In reply to https://community.atlassian.com/t5/Confluence-questions/Google-Analytics-track-one-space/qaq-p/595032
I get the following error on posting the reply:
Error
Your reply was not accepted. Please check for inappropriate language or spam.
Here's the answer I posted:
Hi @Victor Prasad,
In Google Analytics Admin interface, You'll have to create a custom dimension called "Confluence Space Key".
In Confluence Admin > Look and Feel > Custom HTML > At the END of the HEAD, you should paste this:
<script>
// Standard Google Universal Analytics code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
AJS.toInit(function(){
ga('create', 'UA-XXXX-Y', 'auto');
// Add a page-level custom variable to record the space-key
if (typeof AJS.params.spaceKey === 'string') {
ga('set', 'dimension1', AJS.params.spaceKey); // Set a `spaceKey` dimension at page level
}
ga('send', 'pageview');
});
</script>
The bit that says:
if (typeof AJS.params.spaceKey === 'string') {
ga('set', 'dimension1', AJS.params.spaceKey); // Set a `spaceKey` dimension at page level
}
...is equivalent to this in your comment:
var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);
I hope this helps. Btw: If you need help on adding custom dimensions in Google Analytics, some of the video on this page will be relevant.
@MrVP
Sorry for the delay. I didn't notice that you'd commented here.
I think I missed out creating custom dimensions. I did a little video here about how to create the custom dimensions in Google Analytics.
Having done that, you can easily filter by the new custom dimension Confluence Space Key in the Googhle Analytics user interface.