Please Note – I will just be covering how to track PDF Downloads here.
Step 1 = Make sure that the Google Analytics Code is correctly placed on your website.
Step 2 = Determine whether you are using the old or the new Analytics code. For example, here is how you can differentiate:
Old Looks like this:
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
New looks like this:
ga('create', 'UA-XXXXXXXX-X', 'MyDomain.com.au');
Steps for the Old Analytics code
<a target="_blank" href="/ReallyLongFileName.pdf">My PDF</a>
//just to describe this for you in short:
The _blank means that the PDF should open in a new tab/window. This actually makes tracking a lot more accurate so leave that as it is.
The rest of the code is quite self-explanatory. ReallyLongFileName.pdf is usually the link to your PDF and > My PDF < is the words that are featured on your website that people can see when they go to click on your PDF.
All you need to do is re-write this code as follows:
<a target="_blank" href="/ReallyLongFileName.pdf" onclick="_gaq.push(['_trackEvent', 'pdf', 'download', 'myPDF']);"> My PDF </a>
This means that upon a click of your PDF – there is a Google Analytic Push of Data which will Track Your Event.
You may want to leave everything as it is except change the wording of “MyPDF” to the name of your actual PDF so that when this information appears in Analytics > Content > Events – it makes a whole lot more sense.
Steps for the New Analytics code
Only 1 change to the above method and that is:
Rather than add this code:
<i>onclick="_gaq.push(['_trackEvent', 'pdf', 'download', 'myPDF']);"</i>
//…which is the old way of doing things – you need to change it to this:
<i>onclick="ga('send', 'event', 'pdf', 'download', 'myPDF')</i>
//…so the final code should look like this:
<i><a target="_blank" href="/ReallyLongFileName.pdf" onclick="ga('send', 'event', 'pdf', 'download', 'myPDF')</i><i>"> My PDF </a></i>
So you can either pass this onto your web developer if you’re feeling quite confident about it or if you’re unsure you could take the following extra steps:
Go back into Google Chrome and do the following:
- Roll over your PDF, right click and choose “Inspect Element”
- Paste your code here
- Test to make sure there are no broken links and that all looks good on your page
- Relax! As only you can see this in your own browser and you’re not actually making changes to the website
- Pass this code onto the web developer.
- Once he has made the change – go and test it yourself.
- You should see Immediate data in Real-Time > Events