ga-download-tracker.js
This script helps you track file downloads in Google Analytics using virtual pageviews and events.
Simply include a reference to the script anywhere on your page:
<script src="/scripts/ga-download-tracker.js"></script>
The script automatically inserts tracking to all <a> tags on the page that link to files.
This script requires the standard Google Analytics script to also be included on the page.
These filetypes are tracked by default. Change this list by editing variable filetypes:
- zip
- od*
- doc*
- xls*
- ppt*
- exe
- dmg
- mp2, mp3, mp4
- mov
- avi
- gif
- png
- wav
- jpg
- jpeg
- ogg
Let us say you have a link to this file on your website: http://mysite.com/content/files/document.docx
The pageview uses the actual path to the file, so you will find the statistics for the example file in Google Analytics' dashboard here:
Behaviour → Site Content → Content Drilldown → /content/ → /files/
The event for the example file has these properties:
- Event Category: Downloaded file
- Event Action: document.docx
- Event Label: /content/files/document.docx
- You will get hits for files that are not on your own domain.
A big thanks to TechOctave, their project entourage.js was a big influence.