iA


Tracking Atlassian Confluence usage with Google Analytics

by David. Average Reading Time: about 2 minutes.

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

A screenshot of the Site Search Setting section

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:

<script type="text/javascript">
  // See: http://davidsimpson.me/2009/03/18/tracking-atlassian-confluence-usage-with-google-analytics/
  // Put this in Confluence Administration | Look and Feel | Custom HTML -- "At end of the HEAD"

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXX-XX']); // Your GA code here
  _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>

Results

This works nicely, particularly as the custom variable 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:

Related Posts (Updated)

40 comments on ‘Tracking Atlassian Confluence usage with Google Analytics’

  1. [...] an excellent post on “Tracking Atlassian Confluence Usage with Google Analytics” [...]

  2. RT @dvdsmpsn Blog post: Tracking Atlassian Confluence usage with Google Analytics http://is.gd/nTE1

  3. samplonius says:

    RT @barconati: RT @dvdsmpsn Blog post: Tracking Atlassian Confluence usage with Google Analytics http://is.gd/nTE1

  4. Steve Kramer says:

    are there any firewall issues as alluded to on this Atlassian page:
    How to audit Confluence – enabling user access logging ?

    thanks, steve

    • David says:

      Steve: If the client browser has free access to the internet, then there should be no problem. It’s the client browser which is loading the ga.js JavaScript directly from Google’s servers.

      If however you’re a closed network, you’re definitely out of luck here. If this applies, you could of course buy a copy of Urchin and host it locally ;-)

  5. Laurel says:

    Any thoughts on how to upgrade when you’ve used this technique to add Analytics to your site? Does the custom html stick around on upgrade?

    • David says:

      Laurel: This should be fine on upgrade as (I believe) the custom HTML section is stored in the database. It’s not part of the themes where it would more likely be susceptible to breakage.

      Having said that, I’ve not upgraded since so can’t be completely certain.

    • Phil Wilson says:

      At Bath we’ve had the GA code in our custom HTML for a few years and never had to re-enter it after any of our many upgrades :)

  6. kk says:

    Any issues with security using this technique ?

    • David says:

      This is the standard Google Analytics footer code. It’s as secure as all the other websites that use it.

      Only use this if Google Analytics is a package you’re happy with.

  7. @SamDim1 this might be of some help for doing web analytics inside #Confluence http://tr.im/su8Q

  8. @inspiredworlds u can use Google Analytics with Confluence – http://tr.im/B9AMhttp://tr.im/B9AK

  9. [...] Setup Google Analytics on your Confluence site [...]

  10. Mauricio says:

    Hi!
    I’d like to find a feature/plugin/extension to Confluence that lists the viewers users of a given page.
    I’ve look at this page, but didn’t find any.
    Do you how to deploy this into Confluence?
    Thank you!

  11. Patricia says:

    Could you tell me exactly which information is transferred from CONFLUENCE to GOOGLE ANALYTICS? Please tell me also if GOOGLE ANALYTICS can see insight the CONFLUENCE server (through remote access) or has write access to our CONFLUENCE server.
    Thanks in advance.

    • David says:

      Patricia: The Google Analytics (GA) Javascript only collects information such as visitor information, referring page, browser, screen resolution and so on i.e. the normal stuff that is shown in Google Analytics reports.

      Google Analytics does not read the content of your Confluence wiki pages or have write access to your Confluence server. The Javascript is executed client-side. So when Confluence is hosted behind a firewall, the client browser has access to the internet (and thus the hosted GA code) and also the Confluence server. But GA and Confluence do not need to have “line of sight” for the tracking Javascript to work.

  12. Kenn North says:

    Do you need the plugin? Can’t you just put the js code in the footer?

    • David says:

      Kenn: There’s absolutely no need to install the analytics plugin if you don’t want to use it. Just drop the GA javascript in the footer. Job done.

      It allows you to show others a subset of Google Analytics reports without giving them access to your GA account. Only use it if you have that requirement.

  13. Jeremy says:

    Can the plugin pull analytic data sitewide or just for the particular space that the page happens to sit in?

    • David says:

      Currently, it displays the data for the space it’s displayed in. If I get a chance sometime, I’d like to add the ability to show site-wide results too.

      Also, I’d like to be able to display Google Analytics data for another site within Confluence, so that you can setup a series of reports for different websites within Confluence.

      If you have any requests or bright ideas for improvement add them here and I’ll try to schedule them for a future release.

      • Jeremy says:

        Thanks. It would be much more useful to display sitewide or for other sites. Great plugin tho. Thanks

        • David says:

          Jeremy: I agree, it would be useful to do that too. I hope to extend the current plugin to do just that at some stage. I’ve added it to JIRA as a new feature request (CGAP-10).

      • Tim says:

        Great Plugin! Site-wide integration would be really helpful. Maybe by adding a parameter to the macro.

        • David says:

          Yes, I agree. It’s on the roadmap — there’s a JIRA (CGAP-10) for that. I want to also allow support for other websites too. There’s likely security implications for that, so that could be an admins only feature.

  14. zac craven says:

    This is great, thanks!

    Is it possible to use this plugin to show Google analytics stats on a Confluence page for accesses to a non confluence site?

    ie. I want to show the google analytics stats of our public website (not confluence) to users of confluence by showing those stats on a confluence page.

    It is easy to do for google webmaster tools using the igoogle widgets, but there seems to be no way to do it for google analytics stats.

    • David says:

      Hi Zac

      This is something I’d like to do as displaying the report should be relatively trivial. I’ve been a little reluctant to do this so far — simply because I don’t know all the use cases for this kind of functionality.

      Currently, space editors can decide who sees their analytics reports by assigning permissions to the page. This makes it very simple for me – no additional permissions model is required in the plugin.

      I’m not clear how this would work for external websites. Some organisations may only want to allow distinct groups permission to add analytics for external sites to a limited number of spaces. It’s likely that for external websites, we’d need the ability to configure users & groups permissions to insert web analytics. It’s possible of course, but I’ve not had the time to work out how to do this in the most simplistic and usable way.

      Your thoughts are welcome. Please submit user stories to JIRA.

  15. Dan says:

    Hey David,

    Thanks for the Information – I just thought I would point out. In you explanation of how to install the code into confluence you say put the code in the “At End of the Head” Section but your helpful screenshot has it in the ‘At End of the Body” Section.

    • David says:

      Good point Dan. I can explain…

      When I wrote this in 2009, the standard practice was to add the Google Analytics Javascript at the end of the page. Since then, Google released their async tracking code where the tracker is now added in the HEAD without a detrimental effect on the page load. I updated the page but forgot to update the screenshot.

      I’ll try to rectify this ASAP :)

  16. How would you use google analytics to track the use of pugins/macros in and enterprise wiki? We are about to upgrade and we need to get some idea of what people are using. The activity macro proved to be too much of a load on our system.

    • David says:

      @Arthur: Using Google Analytics on the client side only, it’s not possible to track plugin or macro usage, because there are no standard hooks from which to track plugin usage.

      It could be possible however to manipulate the page layouts to include an additional macro that parses the page content for patterns that match macro syntax and then add the relevant hooks or indeed the relevant JavaScript for Google Analytics to track this as custom events.

      Another route would be server side Google Analytics tracking that listens for page render events, parses the page content, then sends details of the custom macros to Google Analytics.

      If you’d like some help with this, please contact me at info@appfusions.com

  17. [...] using Google Analytics to track Confluence usage – and if not, why not, David Simpson has an excellent guide on tracking Confluence usage with Google Analytics – you may have noticed that Google Analytics doesn’t track attachment downloads. This [...]

  18. Sean King says:

    I’m having trouble creating a google analytics custom report with the custom variable you created for the spacekey. What would the “dimensions” and “metrics” value(s) be?

Leave a Reply