Tracking PDF downloads as pageviews using Google Tag Manager V2

Robert Petković

Google Analytics Specialist

Have you ever had the task to measure how many people actually read those lovely PDF files that were too heavy to convert into HTML while developing your website’s first version?

Did you actually know that Google Analytics is able to track PDF downloads as well? If you are a Google Analytics geek as I am, you are probably tracking those already. But are you sure you are tracking them the proper, easy way? Also, did you know that some latest Google Tag Manager updates enable you to track all PDF files within your website by using a rather simple procedure? Let’s find out how!

There are many blog posts out there covering this issue for a long time, but most of them suggest that: “You should track your PDF documents as Google Analytics Events”. I’m not saying that’s wrong, I just think PDF documents might be treated as (virtual) Pageviews, since PDF documents are usually opened within the browser itself. In most cases they are read on the screen, unlike spreadsheets which we open for further calculations in another application, or some files we use for application installation. That’s exactly the reason why I’ll write about creating Virtual Pageviews while clicking to PDF documents, but you are free to track them as Events too, if you would like.

I suppose you have your Google Tag Manager installation ready. If you don’t, feel free to check all about it on Google Tag Manager website. Let’s say you have previously implemented basic Pageview tag, too (and you know the purpose of Tag, Trigger and Variable). However, if you are not sure how to do it, please refer to Google Tag Manager Documentation.

Google Tag Manager will soon be available in version 2 only, so it’s a perfect time to revise these steps and to show you how easy it is to track PDF files as pageviews in Google Tag Manager v2.0.

The main difference between GTM version 1 and 2 is that in version 2 you don’t need to activate Link Click Listeners any more (Step 1), since they are now a part of basic “Variables” (used to be called “Macros”), but we still need to activate them.

But, let’s go from the start:

Step 1: Built-in variable for click URL

How do we set it up? First, we go to “Variables” section and just check “Click URL” under the “Clicks” section. This way we enabled the pre-built variable that captures our visitors’ clicks URL. It looks like this:

Step 2: One simple trigger

If we want to include clicks to PDF files only, we should set up some rules, which are now called “Triggers”. In order to do that, let’s click to “Triggers – New” which we will name “PDF links only”.
Here we’ll choose a type of event – “Click”, because we want this trigger to activate upon somebody clicking onto some webpage element.
Then we configure the trigger type – “Link Click”, because we don’t want to capture all clicks but just clicks on links. If you wish, you can also select “Wait for Tags” and “Check Validation”, although that is not necessary with this trigger. If you select either of those options, you should also tell this trigger which pages should it be active on, by putting “Page URL matches RegEx .*” under “Enable When” section.
Now we should tell this trigger to activate when the link URL contains “PDF” only. Under “Fire On” select “Some Clicks” and add the following condition: “Click URL matches RegEx (ignore case) \.pdf”. “Click URL” is what we have activated in the previous step, while Regular Expression “\.pdf” means “Activate In case this URL contains PDF”. That should look like this:

Now save your trigger and go to the next step.

Step 3: Virtual pageview

Remember how we said at the beginning that we will use virtual Pageviews for PDF downloads and not events? OK, let’s configure a new Tag that will send some virtual Pageview information to Google Analytics, but only when we click to PDF document anywhere within your website.
First, create a new tag and name it “PDF Virtual Pageview”. Select its type to be “Google Analytics” and “Universal Analytics” and type the appropriate Google Analytics ID (or let the macro populate that value, the way I’ve been using Tag Manager for a while). Select its Track Type to be “Pageview”:

Now expand “More Settings” and “Fields to Set”. Here we should put the PDF document file name to be shown together with all other Pageviews in your Google Analytics reports. The easiest way is to put an additional field called “page” (just start typing “pa” and it will show in the menu list) and the value of “{{Click URL}}” variable this way:

Don’t forget to fire this tag on PDF links only! Under “Fire On” choose “Click” and in the popup window put a checkmark by the rule we created before: “PDF links only”. Now your tag information should look like this:

Create your tag and voilà! We have a Pageview tag that will send its information to Google Analytics only when a user clicks on a PDF document anywhere on our website! Isn’t that great? In the past you had to edit the website code (or use CMS to edit the HTML) on every web page with a PDF document on it, just to be sure that you are tracking all PDF downloads! Plus, once you edit all website codes, someone will probably add another PDF in a day or two without telling you that, and you will have incomplete data! By using these few simple steps you saved yourself a lot of time and effort!

Step 4: Publish!

You can now create a new Tag Manager container version, publish it and your website will immediately start sending the proper PDF download information to Google Analytics. You will be able to see the full URL of that document under the “Behaviour”‘ section, among other Pageviews.

Step 5: One extra tip with one extra macro

But – wait! There is something wrong here, especially if you are a nit-picker! I can hear you asking: “But wait, other Pageviews’ URLs don’t start with ‘http://’ but with a slash only! Those other pages also have titles in reports, while PDFs don’t! Can we somehow fix that?”.
Well, today is your lucky day and you can get extra tips for the regular price! Google Tag Manager knows how to fix that and help us, so let’s make it work.
We should start by creating one variable that returns only the portion of the URL after the domain name. Let’s name it “Click URL Path”, because it is very similar to the existing “Click URL” variable. Its type should be “Auto-event Variable” with Variable Type of “Element URL” and (very important!) a Component Type “Path”. Save that variable.

Step 5b: Virtual pageview revision

Now go back to the “PDF Virtual Pageview” tag we created earlier and take a look at its “Fields to Set”. We should replace the existing “page” value with the variable we just created: “{{Click URL Path}}” and that’s it! Our Pageviews will no longer contain domain names and will be consistent with other website Pageviews!
But what about the Document Title? Well, if you know SEO or know basic principles of good web writing, your PDF document link will probably look like this: “Please take a moment and download our Product catalogue as a 5 MB PDF file”, with “Product catalogue” being an actual link to a PDF. Google Tag Manager will get that text via built-in variable called “Click Text” that we first need to enable under “Variables – Clicks” section.
So, under “Fields to Set” we should add a new pre-defined field name “title” that will contain a value returned by this fresh variable {{Click Text}}. Therefore, your tag configuration should at the end look like the example below:

Save the tag, create and publish the new container version and now you have PDF documents with URL and title in your Google Analytics reports! As easy as one-two-three, right?

Just one more thing before we finish! If you are a lousy copywriter and your links to PDF documents usually look like “You can download our PDF price list here.” then you will not fully benefit from this post, nor should we be blamed for the fact that all your PDF documents in Google Analytics reports are titled “here”. But we sincerely hope you will soon figure out how to solve this problem using your own CMS. ;)

Feel free to comment on this solution or to send even better examples, I would be glad to analyze or comment them. And if you find this solution useful, let me know that too, so that I can prepare more posts like this!

For all of you who made it to the end of this post, I have an even better solution! A free download of JSON object containing the configuration I just described here!

After you download and extract the “GTM-Virtual-PDF.zip” file below, all you need is to go to the Admin section of your Tag Manager container and choose “Import Container”. Select “GTM-Virtual-PDF.json” file to import and choose to “Merge” these tags, triggers and variables with your existing setup. Soon after the confirmation, you should see this new tag called “PDF Virtual Pageview” in your new GTM Container. You’re welcome ;)


First name

Last name

Email address

Company

Job title

Phone number

Author

Robert Petković

Google Analytics Specialist

Currently the oldest but hardly the most serious member of the team. Likes to play with gadgets, numbers and applications and loves music, travelling and spending time with his family.

All stories by Robert

SIGN UP FOR OUR MONTHLY NEWSLETTER

Get more digital stories directly in your inbox.
Your email is saved
Join the discussion

12 Comments

1

Dave P.

Reply
Great write up and step by step instructions! It was easy to follow, thank you! Just wondering were exactly in Google Analytics I will see the PDF download stats. Thanks again!
2

braymond

Reply
Thanks for the information. I set it up as suggested and I see the PDFs in Google Analytics when I click a PDF link from the page.I'm using QR codes on printed items. When users scan the code, they are taken to a PDF version of the poster. These hits don't show up in GA or when I just paste the PDF URL into the browser -- this is for a PDF that doesn't have any parameters on it -- is that normal behavior? So in that case it would only track PDF hits coming in from the QR code if it had parameters on it?Thanks, braymond
3

Marin Zenić

Reply
Hi Braymond,Yes, this is normal behavior. We have defined a trigger that will send its information to Google Analytics only when a user clicks on a PDF document anywhere on our website. So if your user don't click on some link on your site to get to your PDF, your tag will not fire because there is no trigger (firing rule). And besides, .pdf doesn't have GMT tag in it's source code. :(Since you use QR code, check this link, it can be useful to you: http://www.degordian.com/education/blog/5-cool-examples-of-utm-tracking/
4

Chad

Reply
Thanks for the great tutorial, I have followed your steps and am now in Google Analytics trying to see where the page views load. Is there a specific area that the PDF tracking will be located at within Google Analytics? Thanks again and I will be watching for your reply. :)
5

Marin Zenić

Reply
Hi Chad,You can check virtual pageviews in Behavior > Site Content > All Pages report.
6

Andrew Gouty

Reply
Very nice walkthrough. I like the concept of PDFs as page views. I feel this also makes it easier to judge PDF formatted content as contributing to other lead funnels. Well done!
7

Emily

Reply
Hi,Thanks for sharing this. I was fine until Step 5B when it said "Unknown variable 'Click Text' found in a tag. Edit the tag and remove the reference to the unknown variable." when I tried to publish it but my screen looks the same as your screen grab in that section. Not sure what to do now!
8

Marin Zenić

Reply
Hi Emily,You have to enable GTM's built in variable "Click Text" variable on the Variables tab. That should work just fine then.Let me know if it helps!
9

Robert Lu

Reply
Thank you for the instructions. My question is, how to check of this pdf pageviews from GA. I can't see it. Thank you.
10

Michael W.

Reply
This was a wonderful walkthrough on setting up PDF tracking. Thank you, Robert!
11

Brad

Reply
Great, super-helpful article! Thanks for taking the time to put this together. Please correct me if I'm wrong, put you could follow this process to create tracking views for other file types (.ppt, .xls, etc...). Is that correct?Thanks again for the solid article!Brad
12

Sergio

Reply
Thank you for this so detailed explanation about how to get tracking of the pdf's files. It was pretty useful for me. Thanks again.

Share your thoughts

Let's work together  →
Go to top
css.php