Updated 2020-03-03: Tracking Atlassian Confluence Cloud usage with Google Analytics

Updated 2014-08-14: Added Universal Analytics tracking code

Updated 2011-06-30: Changed to asynchronous Google Analytics tracking

You've chosen Confluence as your Enterprise wiki and got it installed. People are using it. But how many people?

You could have a look at the Global Activity page on Confluence, but this might confuse matters.

You'll get to see graphs, but what do they really mean? The Global Activity statistics are at best very basic.

Better still, install Google Analytics and you'll have a much more accurate idea of what's going on. Best of all, it's really easy to install.

How to install Google Analytics on Confluence

I'm assuming (for my sake) that you already know your way around Google Analytics.

In Google Analytics

Login to Google Analytics and add a new website profile

The settings will roughly mirror those in the screenshot below

Make sure that you check "Do Track Site Search" against Site Search. Add queryString as the Query Parameter. This will allow you to monitor who is searching for what.

Update (2009-11-12)
Edit the Search Settings configuration like in the image to see search terms grouped by spaceKey in the internal search categories reports. Further details why can be seen here

Settings - Site Search

The top search terms will suggest either content that's missing from the site, or something that is not easily found in the current information architecture. Either way, tracking this and acting on the findings should improve the user experience.

In Confluence

Login to Confluence as an administrator and add the GA tracking javascript code to the end of the page body...

Navigate to:

Dashboard | Administration | Look and Feel | Custom HTML

Click on the "Edit" button and add the javascript sample (with your tracker code) to the "At end of the HEAD" section:

Update 2014-08-14: Universal Analytics tracking code

With the changes for Universal Analytics, custom variables have been replaced by custom dimensions. Currently there is not way to migrate data stored in custom variable into custom dimensions, so you'll just have to bite the bullet and hope for the best.

Additionally, unlike custom variables (which you could create on the fly with JavaScript) you now have to do some work in Google Analytics to set up a custom dimension.

In Google Analytics

Browse to Google Analytics Administration.

  • Select an Account and then a Property within that account
  • Expand Custom Definitions below a selected Property
  • Select Custom Dimensions
  • Click on the Custom Dimension Name button
  • In the Add Custom Dimension screen
    • Type Confluence Space Key in the Name field
    • Select Hit from the Scope dropdown menu
    • Check the Active checkbox
    • Click the Create button

You now have a Custom Dimension named Confluence Space Key which is available for use within the Google Analytics interface. Next, you’ll need to populate this custom dimension with some data.

In Confluence

Browse to Confluence Administration | Look and Feel | Custom HTML and paste this in At the END of the HEAD:


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

Results

This works nicely, particularly as the custom variable custom dimension allows us to easily track all space related content separately, and thus facilitate the use of the (Google) Analytics reporting plugin for Confluence.

Screenshot of Content by Title report:

Screenshot of Site Search Terms report:

Additional Notes

Note for users of Zen Foundation

Zen Foundation overrides the At the end of the HEAD field, so adding the tracking code there will fail for Zen Foundation users. Instead, pop it at the end of the BODY.

Note for users of Google Analytics plugins that track user's names

If you're using a plugin that tracks users names by sending the name to Google, you will be in violation of the Google Analytics Terms of Service. Find out more by reading Identifying your users in Google Analytics while complying with section 7 of the terms of service.

If you are unsure of the plugin's compliance with the Google Analytics Terms of Service, ask the plugin vendor for more details of how they comply with comply with section 7 of the Google Analytics terms of service.

To prevent you from falling foul of this, I recommend AppFusions' Google Analytics for Confluence add-on which is fully compliant with section 7 of the terms of service.

Tracking Atlassian Confluence Cloud usage with Google Analytics

This method is not possible for Confluence Cloud because Atlassian do not allow you to add JavaScript code into their cloud products

Instead, the best option is to install an app which provides the same solution

Further reading