Tracking Confluence Attachment Downloads with Google Analytics

If you’re 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 is because downloads such as PDFs, Word Docs, Powerpoint Presentations, etc. are not web pages and therefore do not include the Google Analytics tracking code. Fortunately there is a solution based on this support document from Google:

1. Login to Confluence as a Confluence Administrator
2. Select Browse -> Confluence Admin
3. Select Look and Feel -> Custom HTML and enter the following JS snippet in the “At end of HEAD” section in addition to your Google Analytics tracking code:

AJS.toInit(function() {
  AJS.$("a[href*='/download/attachments/']").click(function() {
    _gaq.push(['_trackPageview', AJS.$(this).attr('href')])

4. Click Save

After 24-48 hours you should then see your attachments being tracked in Google Analytics under Content -> Site Content -> Pages:

Google Analytics Page View

Happy Tracking :-)

Related Links

Tips via Twitter for Confluence enterprise wiki

Got a Confluence tip? Tweet it now then see it in the Confluence docs.


Leave a Reply