How to use Google Analytics to track downloads?

2019-05-09 22:14发布

I have a website where I have .tar.gz, .zip and .dmg files. I need to track the number of downloads using google analytics. I heard that I can use onclick="pageTracker._trackPageview('/file_name.file_extension') for the "a" tags on the page. I'm not clear what the file_name.file_extension corresponds to. Also, do I need to use some additional scripts?

2条回答
我想做一个坏孩纸
2楼-- · 2019-05-09 22:30

I'm not clear what the file_name.file_extension corresponds to.

Your example onclick="pageTracker._trackPageview('/file_name.file_extension') logs every click on that link as a page view for file_name.file_extension.

You can edit file_name.file_extension to be whatever you want. It is simply the name of the "page view" that gets passed to Google Analytics and is what will show up in your analytics reports.

Also, do I need to use some additional scripts?

No, adding the above onlick attribute to each link you want tracked will be enough.

See here for reference. Hope that helps.

Edit:

I assumed you knew you needed the general Google Analytics script for this to work (Thanks to Ryan in the comments for clarifying). The script looks like the following, but contains your Google Analytics account number in place of the X's in UA-XXXXXX-X:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-XXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}
</script>

To obtain the script, you'll need a Google Analytics account. Once signed into your account and after adding a new "Website Profile", you'll be given a snippet of Javascript (using your account number) to include in each page you want tracked, along with instructions. That should be enough to get you started, but let me know if I can clarify anything.

Edit 2:

As pointed out in the comments, I erroneously posted the latest, asynchronous version of the Google Analytics script which is actually incompatible with _trackPageview. I've edited my answer to include the "traditional" script that you'll want to use. See here for more info.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-05-09 22:40

For a similar problem on a client site, we're using GA Events (rather than Page view tracking) to track the downloads.

Google's Event Tracking guide has all the details but essentially, instead of

pageTracker._trackPageview("download name");

you can call something like

pageTracker._trackEvent(category, action, opt_label, opt_value)

which ends up as a set of datatables. category defines which table the data goes into, each action is a different row in the table, counted separately.

We have six different downloads that can be delivered in different ways (PDF download, by email, by snailmail etc), so we track the delivery method as the category and the brochure name as the action.

查看更多
登录 后发表回答