Last Updated: February 25, 2016
·
1.616K
· nathansmonk

How to create a download center with file tracking

Whilst working on a WordPress website recently I was asked to create a resource centre that included a downloadable PDF for each resource. The client needed to be able to track how many times the files were downloaded.

We didn't want to use a dedicated plugin for this as it seemed a bit much for what is a relatively simple task. So instead, we chose to use Advanced Custom Fields and Google Analytics.

We created our custom field (for the downloadable file) and then came acros the Yoast Google Analytics, which boasts link tracking. Sweet, right? Wrong. Turns out that it doesn't support links created outside of the content editor - so our custom field based hyperlinks weren't being tracked.

Solution
What we did was track the event using "onclick" and simply used resource and download as the category and action, and just used the URL as the Label. Here's a sample:

<a href="<?php the_field('resource_upload'); ?>" class="button" target="_blank" onclick="_gaq.push(['_trackEvent', 'resources', 'download', '<?php the_field('resource_upload'); ?>']);">Download Resource</a>

That's all there is to it. Now your downloads will appear in your Google Analytics account under Content > Events.

1 Response
Add your response

Thank you for sharing, it was really helpful for a similar project of mine...

over 1 year ago ·