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?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Your example
onclick="pageTracker._trackPageview('/file_name.file_extension')
logs every click on that link as a page view forfile_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.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
: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.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
you can call something like
which ends up as a set of datatables.
category
defines which table the data goes into, eachaction
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 theaction
.