Google Analytics on Blog Posts

Jason Kirby July 17, 2012

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

5 votes
Answer accepted
Amalia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2012

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.

1 vote
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 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.

1 vote
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 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 :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events