Host specific Google Analytics

In Domain Booster Configuration specify custom HTML to be added at the end of content page:

Custom HTML
<script type="text/javascript">
if("GOOGLE_ANALYTICS_ACCOUNT_ID" != ("GOOGLE_ANALYTICS_" + "ACCOUNT_ID"))
{
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GOOGLE_ANALYTICS_ACCOUNT_ID']);
_gaq.push(['_trackPageview']);
// Add a page-level custom variable to record the space-key
if (typeof jQuery('meta[name=confluence-space-key]').attr("content") == 'string') {
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1 of 5
'confluence-space-key', // The name acts as a kind of category for the user activity
jQuery('meta[name=confluence-space-key]').attr("content"), // This value of the custom variable
3 // Sets the scope to page-level
]);
}
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>

Use the above snippet as is, keeping GOOGLE_ANALYTICS_ACCOUNT_ID - it's used as a "variable" that will be replaced with host specific GA account ID.

The snippet will initialize Google Analytics only if GOOGLE_ANALYTICS_ACCOUNT_ID has been replaced (in page) with a real account ID. To do this, open site settings in Domain Booster and add a rule to replace GOOGLE_ANALYTICS_ACCOUNT_ID with UA-xxxxxxxx-x (use your account ID and don't specify quotes in the rule).

Note: The above snippet adds Confluence space key as GA custom variable. you may want to remove that part if you're not interested in space access statistics.

comments powered by Disqus