PDF Analytics

The holy grail of content tracking: Track visits to your website's PDF files in Google Analytics, Plus a Free Wordpress Plugin.

Carl Hendy

TL;DR – I’ve created a WordPress plugin that tracks PDF views on your website, in Google Analytics. It’s free, and unlike other solutions, captures 100% of traffic (including Direct and Organic Search).

Google Analytics - Realtime Dashboard showing traffic to an example PDF file
Google Analytics – Realtime Dashboard showing traffic to an example PDF file

How do you track Google Analytics data on PDF files?

With 7 out of 10 websites using Google Analytics1, it clearly holds the title of the most popular Analytics platform. But one major downside in how Google Analytics works, is that it can only track visits to the HTML pages on your website2. Unlike previous generations of Web Analytics packages that relied on Log File data, GA cannot see traffic landing directly on your other media files, including the enterprise and public sector favourite, PDF.

The reason for this issue is that Google Analytics uses JavaScript to track visits, which only works on web pages. Images, videos, Microsoft Office documents and PDF files do not execute JavaScript and fall into a black hole. In the past, the recommended solution was to tag internal links to these files, so that Google Analytics could assign a view/touchpoint. This only records a small fraction of views though, and none of the traffic from search engines, email clicks or links from third parties.

Finance, insurance and public sector websites are particularly affected by this problem. Important information, data, forms, product/service details and brochures, all get delivered in PDF format. These institutions do not want to convert their PDFs into webpages, as they cant be easily controlled, versioned, and compliance checked. Even those that do convert, usually link to and promote a PDF version of the information.

Restaurants also favour PDF files for their food and drink menus, but cannot see if anyone downloads or reads them.

I’ve seen this firsthand with several clients, that had PDF documents ranking competitively in Google. None of this traffic was measurable though. The solution was to build “PDF Analytics”, a plugin for WordPress that makes those visits visible in Google Analytics for the first time.

PDF Analytics - Settings Page
PDF Analytics – A simple settings page, with just three fields to complete

PDF Analytics intercepts any request for a .pdf file on your website and collects the visitor’s Google Analytics cookie data (if any), UTM tracking tags in the URL and several other metrics. These are then sent to Google Analytics via their official API. The PDF file is then served as usual, from the same URL and without the visitor knowing any different.

To make it fast and reliable, the PDF tracking script runs independently of WordPress. So your PDF files are still accessible if your WordPress database goes down or has an error, plus isn’t affected by any problem-plugins that might otherwise slow it down. It does not “phone home” to me or any third party other than Google Analytics itself, so will pass corporate compliance and security audits.

If that wasn’t enough, I’m releasing the plugin for free! Just click here to download the ZIP file, then upload it to your WordPress site under “Plugins” > “Add New” > “Upload”. Then “Activate” it and enter your Google Analytics Tracking/Site ID on the settings page.

If you’d like to say thank you, please share a link to this announcement with anyone that you know, who uses WordPress and Google Analytics.

Track visits to your website's PDF files in Google Analytics. Free plugin for WordPress. Click To Tweet

Enjoy!

Frequently Asked Questions

How do I install PDF Analytics?
Download the plugin as a ZIP file here, then upload it to your WordPress site by going to “Plugins” > “Add New” > “Upload Plugin”. Then click “Activate” next to the plugin, from the Plugins page. You will see a success message, linking through to settings page, which can also be found at “Settings” > “PDF Analytics” in the WordPress control panel. You will need to fill and submit three pieces of information (two are filled for you). After saving these settings, PDF Analytics will start sending PDF traffic data to Google Analytics.

How does it work?
All requests for .pdf files on your website are re-routed to PDF Analytics. It reads the user’s Google Analytics cookie, session data and any UTM tracking tags appended to the requested URL. This data is then compiled and sent to the official Google Analytics API. It is then ingested into your Google Analytics account and visible in your dashboard within seconds.

Does your plugin use “log files”?

No log files involved – PDF Analytics uses .htaccess to reroute all PDF file requests to a PHP script, which sends data to the Google Analytics API and then serves the content of the PDF.

PDF flow
PDF Analytics Flow

Are any redirects involved?
No. PDF Analytics uses an “internal rewrite” to direct PDF requests to the tracking script. As long as a PDF file exists at the given URL, it’ll return a 200 (OK) HTTP Status code, and a 404 (Page Not Found) if it doesn’t exist.

How safe is PDF Analytics?
The software is free and open source, so comes without warranty or liability. It has been tested on multiple sites without any issues. The tracking code runs independently of WordPress, so your PDF files remain accessible, even when your WordPress site has a database or plugin issue. The publicly accessible PHP file has no database access and does not write to any files. The plugin settings require admin level access to your WordPress site and cannot be changed without them. The codebase is purposely small and tidy, making code audits fast and simple.

Does the software “phone home” or share the data?
PDF Analytics will only send out visitor data to the official Google Analytics API. I track the number of plugin downloads from the site in Google Analytics, but don’t know who you are exactly. No data is sent to me when activating, using or deactivating the plugin. I will not know which websites use it or see your traffic data. I may start a mailing list to give information about updates, but you can opt-in and opt-out of this at any time.

Do you require access to the Google Analytics account?
No. PDF Analytics only asks for your GA Tracking/Website ID, which is non-sensitive information and visible in the Google Analytics tracking code on your website. This tells Google which GA account to log the data for. Neither the plugin or I will have any access to your Google Analytics account or login details – not even read-only access.

How do I uninstall PDF Analytics?
Just click “Uninstall” next to the plugin on the “Plugins” page. You can also click “Delete” afterwards, to physically remove the files. The PDF Analytics entry in your .htaccess file should be deleted automatically upon Uninstall, but it’s worth double checking. Open your .htaccess file and delete anything between “# BEGIN PDF Analytics” and “# END PDF Analytics”. If you don’t see this in your .htaccess, it means that we deleted this for you.

[1] https://trends.builtwith.com/analytics/Google-Analytics

[2] Google does offer the ability to send data from other sources such as Mobile Apps, but not using the default tracking code that is embedded into your web page.


Carl Hendy
by Carl Hendy on June 19, 2019

My career in SEO spans over 15 years, having previously held leadership roles as the Head of Global Search for the UK’s largest SEO agency, and VP SEO for the largest independent digital agency in Europe. I’ve managed digital marketing efforts for FTSE and NASDAQ-listed clients, including Aviva, John Lewis, O2, Marks & Spencer, Bwin.Party and more. I thrive on delivering results for some of the most competitive keywords in Google’s toughest niches, including gambling, fashion, telecoms, insurance, retail and publishing.