A common use case that we have been asked about is how to track PDF downloads. From white papers to restaurant menus, to other lead magnets, PDF files are used by everyone, and in many cases, count as an important conversion on the website.
There are a few ways in which you can track PDF downloads which we will cover using our plugin WP Google Analytics Events.
You can use both the free and the Pro versions of the plugin to track the downloads so let’s get started.
Oh, by the way, you can use these same methods for tracking any other file type download (zip, audio, video, etc.).
Tracking PDF Downloads
Usually, a link to a PDF file will look something like this:
<a href=”https://wpflow.com/files/event-tracking-whitepaper.pdf”>Download our Event Tracking Whitepaper</a>
I’m going to show you two ways to track this PDF link – One using the id or class attributes of the link, and the other, more general, but more powerful.
When the link has an id or class attributes
If you already have or can set an id or class attributes to the link in HTML, tracking the PDF link is rather trivial using our plugin.
Suppose that your download link looks like this:
<a id=”whitepaper” href=”https://wpflow.com/files/event-tracking-whitepaper.pdf”>Download our Event Tracking Whitepaper</a>
You can use the id, in this case, whitepaper, to create a simple click event that will cover this individual file.
Head over to the plugin’s Click Tracking tab, and add an event with the element name “whitepaper” and set the type to id.
Set the category, action, and label fields to whatever makes sense for this link. This is the information that we will send to Google Analytics, and will show up on their dashboard.
Here is a simple example –
This method works very well, but it is not as scalable if you have many PDF links spread across your website, which leads us to the next option.
When you want to track all the PDF download links on the website
Let’s say that you do have many PDF files and want to use a more generic way to track all of them without manually adding each one as an event in the plugin.
What you can do, is tell the plugin to track every link that leads to a URL, or in this case, a file, that ends with .pdf.
To do that, you will first have to enable the plugin’s Advanced Mode, by going to the General Settings page and check the right box.
Then, head over to the Click Tracking tab and add an event that has the following element name:
Set the type to advanced and then fill in the rest of the fields like in the previous example.
Pro tip (as in pro version)
Placeholders are great for these types of events. You can use the $$ATTR_HREF$$ placeholder in any of the fields to get the actual PDF link. The $$PAGENAME$$ placeholder will tell you on which page the visitor clicked the link.
$$ELEMENT_TEXT$$ will give you the actual link text – for example “Download our Event Tracking Whitepaper”.
If you want to get more specific and create a different event for each file, you can add the whole file name to the element name instead of just the .pdf file extension:
This is useful in cases where you don’t have a class or an id in the link’s attributes.
What we can and can’t do
One thing to keep in mind after reading this post is that we can only track downloads that originated by a user clicking a link on your website. If the link to the PDF came directly from another site, Facebook, an email or any other medium, we could not track it.