How can I enable Google Analytics on a file download link?

I’m using WordPress to present some software for download. The download links are provided via Custom Link entries in a side menu. I would like to enable Google Analytics tracking for these file downloads but I can’t see how I can add the required javascript triggers as per the example here: http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55529.

Can anyone offer a way of achieving this?

Edit: By “Custom Link”, I mean that the file links are created in a custom menu as custom links in the Appearance->Menus area of WP3. I’m using the Atahualpa theme, if that makes any difference.

Further Edit: I’m trying the plug-in route, which will hopefully automate the process, but another possibility I’ve found is to use the “Text” widget and simply paste the menu code in there and edit in the javascript trigger on the links. This is obviously more of a pain to maintain. I would add this as a possible answer, but I can’t answer my own question, apparently.

Outcome: Thanks for the responses. I’ve ended up going with the Text widget and just hand-coding the menu for now.

I’m not sure why the answer simply pasting the info from the link I gave in the question is being up-voted as it doesn’t address how to do this in WordPress. A plugin that allows adding onclick handlers to the custom links or similar would be best, but I can’t find one and “if you had a unicorn” isn’t an answer either. I may come back to the coding suggestions but the creation of useful GA identifiers seems difficult to do automatically, which seems to lead back to effectively writing my own plugin… and surely that’s an answer to almost anything?

4 s
4

You basically have to tag the <a> link

Google Analytics provides an easy way
to track clicks on links that lead to
file downloads.

Because these links do
not lead to a page on your site
containing the tracking code, you’ll
need to tag the link itself with the
_trackPageview() JavaScript if you would like to track these downloads.
This piece of JavaScript assigns a
pageview to any click on a link – the
pageview is attributed to the filename
you specify.

For example, to log every click on a
particular link to
www.example.com/files/map.pdf as a
pageview for /downloads/map you would
add the following attribute to the
link’s tag:

<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('/downloads/map'); ">

http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55529

Hope that helps 🙂

Leave a Comment