Google Analytics on Blog Posts

Is there a way to add Google Analytics to blog posts? I have a space that the administrator creates blog posts on and those become part of an RSS feed where the user can click a link to see the post. I want to be able to track whenever a user goes to these blog posts.

Much thanks!

3 answers

1 accepted

This widget could not be displayed.

You can add Google Analytics JavaScript to Blog Post Layout in Confluence Admin > Layouts.

Alternatively, you can add it in Main Layout and insert the following code:

#if ($sitemeshPage.getProperty("page.bodyClass") == 'view-blog-post')
    <insert Google Analytics JS here>
#end

The JS in the above code will only be shown when a blog post is viewed.

This widget could not be displayed.
David Simpson Community Champion Aug 21, 2012

A more correct way of doing this would be to track Google Analytics site-wide but have the RSS feed automatically add the Google Analytics campaign tracking parameter utm_medium=rss (or similar) so that the reporting would appear on the correct screen in Google Analytics :)

This widget could not be displayed.
David Simpson Community Champion Aug 21, 2012

Another approach would be to use Confluence Admin | Look and Feel | Custom HTML | At the end of the HEAD and paste:

<script>
AJS.toInit(function(){
	if (AJS.$('body').hasClass('view-blog-post')){
		// Add Google Analytics code here
	}
});
</script>

This has the advantage of being usable on any theme and won't hinder upgrade to the next version.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

406 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you