De Valdez

Icon

an experiment in brain capacity

File Tracking through Google Analytics

Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following article.

To determine which tracking code you are using, please see Which version of the tracking code am I using?

It’s easy to have Google Analytics track clicks on links that lead to file downloads. Since downloads generally do not lead to a pull page that would contain the tracking code, we have to make notifying Analytics of a special event. We do this through _trackPageview(). The following code will assign a pageview to the specified link so Analytics will treat clicks to it as a a view of this pseudo-page.

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

Important: if your pages include a call to _trackPageview, _setAllowLinker _trackTrans(), your Analytics tracking code must be placed in your HTML code above any of these calls. In these cases the tracking code can be placed anywhere between the opening tag and the JavaScript call.

To verify that _trackPageviewis being called correctly, you can check your Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.

Category: JavaScript, Tools

blog comments powered by Disqus