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!
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.
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
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.
It looks like you're new here. Sign in or register to get started.