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.
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?
You basically have to tag the
Google Analytics provides an easy way
to track clicks on links that lead to
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
pageview to any click on a link – the
pageview is attributed to the filename
For example, to log every click on a
particular link to
http://www.example.com/files/map.pdf as a
pageview for /downloads/map you would
add the following attribute to the
Hope that helps 🙂
I was hoping you would clarify how you’re outputing these links, as per Rarst’s comment..
That said, i’m going to assume you’re using
wp_list_bookmarks to create a list of these links (there aren’t many other functions for the purpose).
wp_list_bookmarks there’s only one hook available and that’s called(ironically)
wp_list_bookmarks, which gives you a string with the output. The following should add the necessary code onto links for you..
A second option would be to use get_bookmarks (see the example on that codex page), just of course bear in mind that
get_bookmarks does little to sanitize the data you’re getting back,
wp_list_bookmarks will deal with sanitization for you..
Hope that helps in some way… 🙂
If you are using a plugin like http://yoast.com/wordpress/google-analytics/ then you can just enable outbound link tracking in the settings. It will append a tracking URL for you so you can segment in analytics.
@Eric: I had this same issue tracking my eBook downloads on my vegan lifestyle website.
The problem is I offer a lot of eBooks and adding the link 1-by-1 just isn’t practical for me. I Googled around and found Entourage.js:
I like it because it has automatic file download tracking. The article has the installation details and download link. But for me, it was as simple as adding the following code snippet before my Google Analytics snippet inside the