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

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 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 :)

1 vote
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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

380 views 21 10
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