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:
<script>
AJS.toInit(function() {
AJS.$("a[href*='/download/attachments/']").click(function() {
_gaq.push(['_trackPageview', AJS.$(this).attr('href')])
});
});
</script>
4. Click Save
After 24-48 hours you should then see your attachments being tracked in Google Analytics under Content -> Site Content -> Pages:

Happy Tracking
Related Links
- Google Analytics
- Tracking Confluence Usage with Google Analytics – blog post by David Simpson
- How do I track files (such as PDF, AVI, or WMV) that are downloaded from my site? – Google Analytics support page
Got a Confluence tip? Tweet it now then see it in the Confluence docs.

