Google analytics track pdf downloads

2019-01-26 19:22发布

问题:

I was wondering if anyone has gotten file download and external link tracking with google analytics working.

I read here how its done http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55529.

But I tried implementing it on my links and its been a couple weeks since I did it and I can't see where it has shown up. (I know i've clicked it a couple of times)

Here is the code I have used.

For an external link

<a onclick="javascript: _gaq.push(['_trackPageview', '/external-link/www.somesite.com']);" href="http://www.somesite.com/" title="External link">www.somesite.com</a>

For the pdf file

<a onclick="javascript: _gaq.push(['_trackPageview', '/pdfs/test.pdf']);" href="http://www.site.com/pdfs/test.pdf">Downland and complete a Transfer your super into Cbus form</a>

I have analytics on the page but it doesn't seem to be tracking.

Has anyone gotten this working? Any help would be appreciated.

Thanks

回答1:

Have you tried looking at your page either in Chrome with the developer tools or Firefox & Firebug and check the console for javascript errors?

Also, you may want to use event tracking instead of pageviews, like at http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html

In that case, your code would look something like

<a onclick="_gaq.push(['_trackEvent', 'File', 'Download', '/pdfs/test.pdf']);" href="http://www.site.com/pdfs/test.pdf">Downland and complete a Transfer your super into Cbus form</a>

Something to be aware of is that Google Analytics works by requesting a tracking pixel. If you leave the current page before the tracking pixel request has completed, you won't see the analytics data. I've had good results with variations of the following:

<script type="text/javascript">
function trackLink(link) {
    _gaq.push(['_trackEvent', 'Link', 'Click', link.href])
    if ("_blank" == link.target) return true;
    setTimeout('document.location = "' + link.href + '"', 150);
    return false;        
}
</script>
<a onclick="return trackLink(this);" href="http://www.somesite.com/" title="External link">www.somesite.com</a>

In brief, unless the link opens in a new window (`_blank" == link.target), handle going to the new URL ourselves after waiting 150 ms.



回答2:

This works for me. I'm able to find tracked file downloads in Google Analytics under the Content section. Have you tried going into Google Analytics and filtering under the Content menu section? Content -> Site Content -> Pages. Use the filter option and try searching with /pdfs/. Does that return any results for you?