It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Attachment download tracking with Google Analytics?

Richard Richard Mar 21, 2012

We have Google analytics set up on our confluence isntance, but out of hte box, GA only tracks page views. Since attachments aren't actually page views, we don't get any metrics on downloaded attachments. We can parse the httpd request and access logs to track requests, and while it's useful, it's limited and one dimensional. We'd like to get this data in GA.

google has a support page that tells what JS to add to links to turn on this sort of link tracking. I'd like to do this for all attachments in all spaces, and in the interest of avoiding a day of code-spelunking, I wonder if anyone knows where I should look to modify generated link html?

Thanks,

Richard S.

2 answers

1 accepted

4 votes
Answer accepted
David Simpson Community Leader May 04, 2013

AppFusions' Google Analytics for Confluence plugin now tracks attachment downloads n a similar way to Andrew's approach. It also assigns the download against the space.

The Mixpanel Engagement Analytics plugin also fully tracks all Confluence events including attachment create, update, view/download and delete events. This is also tracked against username, so you can really get an idea of who is doing what n your Confluence instance.

1 vote
Andrew Frayling Mar 21, 2012

Hi Richard,

I'd be tempted to do this using jQuery to add the click handler to the URL rather than digging around trying to alter link generation in the code.

Login as an admin and select Browse -> Confluence Admin -> Look and Feel -> Custom HTML and enter the following in the End of HEAD section:

<script>
AJS.toInit(function() {
   AJS.$("a[href*='/download/attachments/']").click(function() {
     _gaq.push(['_trackPageview', '/downloads/map']);
   });
});
</script>

All of the attachment links in Confluence should have a standard format of "/download/attachments/" in the URL so the above selector should only alter attachment links and leave all the other links alone.

I'm not a huge fan of jQuery manipulations all over the place, but this might be easier than the alternatives.

Hope that helps?

Andrew.

Richard Richard Mar 21, 2012

Thanks Andrew. That's clever and practical. I agree on the point about js manipulations, but this wouldn't be our first either. Fortunately we do a good job of keeping track of the few tweaks we do make.

Andrew Frayling Mar 21, 2012

Haven't had chance to test it properly as it takes 24-48 hours for Analytics to pick up the virtual page view, but if you go the jQuery route and this works could you mark the answer as correct please?

Cheers,

Andrew.

Richard Richard Mar 21, 2012

Yep. I haven't had a chance to test it yet, but if it works, I'll definitely mark it as answered.

Richard Richard Mar 21, 2012

I did this yesterday, and it looks like this works as advertized. Thanks.

Andrew Frayling Mar 21, 2012

Cool, glad it worked. Thanks for marking as correct.

Andrew Frayling Mar 29, 2012

Noticed a problem with my previous JS snippet, this version is better:

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

mang temi Oct 22, 2012

Thanks for this script but what metric should i use to see this?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

2,050 views 11 27
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you