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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.