Tracking PDF downloads as pageviews

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 first version?

 UPDATE: Google Tag Manager will soon be available in version 2 only, so follow 5 easy steps for setting up PDF download tracking in Google Analytics using Google Tag Manager v2.0.!

Did you actually know 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 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 don’t say 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, Rule and Macro). However, if you are not sure how to do it, please refer to Google Tag Manager Documentation.)

Recently, Google Tag Manager announced a really cool feature: The Event Listener tag. It is a Tag Manager “code” that you use for listening to what is going on on your web page(s). There are few different types of event listeners available, and you can learn more about them at Google Tag Manager help. Today, we will be using only one of them: the link click listener. It fires every time a user clicks to an anchor link, giving us further information about that click that we can use for our Google Analytics reports. Since PDF documents are mostly downloaded by clicking to a certain website link, this particular listener would be an appropriate actor for this example.

Step 1: Link Click Listener tag

How do we set it up? Firstly, we should create one new Tag for that event listener. Let’s call it “Link Click Listener”. In your Tag Manager, select New – Tag and name it “Link click Listener”. Under “Tag Type” select “Event Listener” and then choose “Link Click Listener”. Be sure to enable it to trigger on every page by adding “All Pages” rule to that tag. If you have PDF documents on few pages only, you can set up a new rule that will trigger this tag only on those pages, but let’s stick here to “All Pages” since this listener might be useful for other purposes too. Save your tag and we are ready to move further!

Figure 1

Step 2: One simple rule

If we want to include clicks to PDF files only, we should set up some rules. In order to do that, let’s click to “New – Rule” which we will name “PDF links only”. You should know that link click listener we have set up before actually triggers an reserved event called gtm.linkClick once we click on any webpage anchor. That is why we will first add event that equals (or contains) “linkClick”, followed by one Regular Expression rule that says “In case this link URL contains PDF only”. That should look like this:

Figure 2

Now save your tag and take one step forward.

 Step 3: Virtual Pageview

Remember how we said at the beginning we will use virtual Pageviews for PDF downloads and not events? OK, let’s configure new Tag that will send some virtual Pageview information to Google Analytics, but only when we click to PDF document everywhere within your website.

First create new tag and name it “PDF Virtual Pageview”. Select it’s type to be “Universal Analytics” and type the appropriate Google Analytics ID (or let the macro populate that value, the way I am using Tag Manager for a while).

Figure 3

Now select “Pageview” under type and expand “Basic Configuration”. Here under “Document Path” we should put the PDF document file name and it will be shown together with all other Pageviews in your Google Analytics reports. The easiest way is to put here the value of “element URL” macro this way:

Figure 4

Don’t forget to fire this tag on PDF links only! Under “Tag Rules” select that rule we created before: “PDF links only”, save your tag and voilà! We have a Pageview tag that will send it’s information to Google Analytics only when a user clicks on 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 PDF document on it, just to be sure you are tracking all PDF downloads! Plus, once you edit all website code, someone will probably add another PDF in a day or two without telling you that, and you will have incomplete data! Using these few simple steps you saved yourself a lot of time and effort!

 Step 4: Publish!

Now, you can create 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 “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 doesn’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 recently knows how to fix that and help us, so let’s make it work.

We should start by creating one macro that returns only the portion of the URL after the domain name. Let’s name it “element path”, because it is very similar to existing “element” macros (and I hope Google will soon make it a part of standard macros package that appears once you create new Tag Manager container). Its type should be “Auto-event Variable” with Variable Type of “Element URL” and (very important!) a Component Type “Path”. Save that macro.

Figure 6

Step 5b: Virtual Pageview revision

Now go back to the “PDF virtual Pageviews” tag we created earlier and take a look at its Basic configuration. We should replace the existing “Document Path” value with the macro we just created: “element 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 is getting that text via macro called “element text”, so that’s the actual macro value you should put under “Document Title”. Therefore your tag Basic Configuration should at the end look like the example below:

Figure 5

Save the tag, create and publish 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?

Figure 7

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 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!

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

42 Comments

1

Igor

Reply
Fast, simple and easy. I will agree with you that a PDF "download" is in most cases a PageView, except if you are using an old browser or reading it on mobile where some platforms are still downloading it and using an alternative app to read the pdf.Thank you for sharing ;)
2

Robert Petković

Reply
Igor, thanks for this reply! But nevermind the platform, I'd still rather look at PDFs as Pageview than as events. Events are something that happens while clicking to user interface. That way you can have an event that says "Someone has clicked to PDF link (and also to e-mail link or logo)" AND a similar Pageview. :)
3

Pepe

Reply
Great Article! I do have a question that is somewhat related and i haven't seen the answer anywhere. Is there anyway to track how many people are clicking on a pdf directly from a search engine? (Google, yahoo, bing, etc) I can easily see traffic to the pdf from my website but I want to see Total traffic to PDF from all other websites. Can you advise if you know any way to get those numbers?Thank you
4

Caitlin

Reply
Could this be updated to reflect how to do it on V2 of GTM?
5

rohith

Reply
You are Awesome Man :-) Thanks a lot
6

Robert Petković

Reply
Thank Rohith, hope you will use these suggestions sometimes! :)
7

VegeJuice

Reply
Pure gold. So good to be able to track link actions as a PageView - more logical. Thanks for the post.
8

Robert Petković

Reply
Thank you very much! I am glad I could help, hope you will use these suggestions very soon.
9

Rohit

Reply
Awesome post Robertplease suggest even when we will enable pdf tracking through the method you have suggested in the post, would it impact the overall website bounce rate? For example if our home page has few pdf's and 3 out of 10 people click on the pdf and exit the website (since we are not tracking the pdfs) causing 30% of bounce rate, after we implement the solution you have mentioned above the bounce rate will remain 0?
10

Robert Petković

Reply
Hi Rohit, thanks for the question! Yes, these actions directly impact the bounce rate, since these clicks are not counted as bounces. I've seen many times situtations like yours: people put PDF links on the home page, visitors are "leaving" the website and the bounce rate grows. Well, in my opinion, if you are putting some extra product info in the PDF, then that should not be treated as bounce pr "a visitor leaving the website". On the other hand, if your website has links to PDFs that actually doesn't have much in common with your website content, then those clicks might be treated as bounces and you shouldn't implement the PDF tracking method I mentioned here. But let's be serious, why would you put some PDFs on your website that doesn't make any sense? In general - yes, the method I suggested impacts the overall bounce rate in a very positive way. :)
11

Petra

Reply
Robert, any chance you can also track imbedded links within the pdf (pointing to another pdf or site) using this method? What if the link to the pdf came from your email auto system vs. website? Thanks, Petra
12

Robert Petković

Reply
Hi Petra! Unfortunately, this method doesn't cover the PDFs themselves, since it is not possible to embed Google Tag Manager within PDF file. But let me answer step by step. You can track embedded links within PDF file, as long as they are pointing to your website, or the website you have a Google Analytics access to. Please check-out my blog post 5 Cool Examples of UTM tracking for more detailed explanations. But if your links are pointing to another PDF or site, it is not possible to track those links this way. The same goes if the link to PDF came via email, since even if you have previously utm-tracked that link, it will not be registered using GTM. Try to make your e-mail links point to the landing page that has a link to PDF instead.Technically, it would be possible to track these situations in Google Analytics using server-side actions and Measurement Protocol, but that's a whole new blog topic :)
13

mohit nagar

Reply
I follow the same procedure but I am unable to track my pdf downloading information, Please let me know, In {{element url}} [regEx] \.pdf, What is PDF ? means it's path or folder information. My all PDF are not open on windows, by default those are directly downloads on system. So I want to know about how much users download it.Please help me for tracking pdf downloads.
14

Robert Petković

Reply
Hi Mohit, thank you for reading this post and wanting to know more! If I understood your question correctly, your links doesn't point directly to PDF files but to some server-side script? IF that's the case, then it shouldn't be a problem to track those clicks using similar method too. "\.pdf" in that RegEx means "activate only when some link has .pdf in its a href". If your links have ".pdf" in their URLs, then this method will work. But if you have some server-side script (like "download-pdf.php?itemid=356") then this RegEx should be changed to "{{element url}} contains 'download-pdf'" or something similar. Change this "PDF links only" rule to match your case, and that should work. Please let me know if this helps, regards!
15

Elizabeth

Reply
I followed your instructions step by step, but when I go back to my Google Analytics page my PDF files still cannot be found when I search in Pageviews. Forgive me, I am a novice at all of this. I am wondering if it has something to do with the website code. Do i need to adjust the data layer in my website code? Or are there any other ideas as to why my PDF clicks still aren't being tracked? Thanks, Elizabeth
16

Robert Petković

Reply
Hi Elizabeth! I am sorry my instructrions weren't that helpful. As far as I can see on your website, you've used link click listener, but did you create rule and virtual pageview? Can you re-check your configuration again and make sure you have a listener, rule and a pageview? Please let me know the results. Good luck!
17

Bobby

Reply
Wow, this is awesome! I just set this up for a client and it's working. I have a secondary question to this. So for this particular client, in addition to a page with the 'Download PDF' they also have 'View Catalog' which essentially opens a non pdf version of the catalog. It opens the catalog in a media viewer where the url looks like.. examplesite.com/catalog_files/11South2/index.html etc. (replace the name after 'catalog_files' each time with different catalog names.)This catalog viewer doesn't have Analytics. Is there a simple way to use GTM to setup tracking or at least clicks to all of these catalogs? I've done some testing similar to the way you described with the pdf but I can't seem to get it to work?Thanks!
18

Robert Petković

Reply
Hi Bobby, I am glad these tips were helpful. In this particular case you mentioned you might use another rule that fires on links containing "catalog_files" and create pageview or event tag named "View Catalog" for that purpose. On the other hand, you can simply put Google Tag Manager on all those catalog index.html pages and you'll track their pageviews instantly :)
19

Skeptical

Reply
This is fine for publishers who's documents are linked from their other html content. However I am in the situation where my pdf content is an entry page. I do not want to embed javascript into the PDF documents, because it causes a warning in Adobe reader. Others seem to work around this issue by embedding their PDFs into a html document. Just wondering if you have a solution for this?Thanks.
20

Robert Petković

Reply
Well, first of all, I would never suggest to use PDF as an entry page (homepage). It's better to make some basic homepage with a PDF link than to open a PDF directly. On the other hand, sometimes people are landing to our PDF files from search engines directly and in that case this solution won't work. You might try to embed a 1x1 GIF into your PDF document with a Measurement Protocol URL, but I am not sure whether it would be able to track the visit source other than (direct/none). If you ever try that solution, please let me know your results.
21

Juanne

Reply
Thank you for sharing this. I couldn't get my head around setting up PDF tracking without involving the developers every time! This sorted me out!
22

Robert Petković

Reply
Juanne, I am glad you fidn this article helpful :)
23

Chris McCreery

Reply
Hi Robert, was wondering if you have any scripts to share for tracking pdf downloads where the user doesn't visit your website first. For instance, if a user finds your pdf in Google search results and loads the pdf directly. I would love to track this. After reviewing my WMT account I can see that over 30000 pdf downloads occur directly from Google search results, yet on our site we can only see 3000 pdf downloads using a similar method as you've outlined above. Any help would be great.Thank you, Chris
24

Robert Petković

Reply
Hi Chris! This is the question that pops up every now and then, and I still don't have the right answer for it. The possible solution would involve a lot of server-side scripting, so here's acceptable one. You might try to use Google Analytics Measurement Protocol in which case you should embed one 1x1 pixel image that has Measurement Protocol URL as an img src. The thing with this method is that you can't read the Google Analytics ClientID, which you should use in Measurement Protocol to connect that data with some previous or ongoing session. In this case you should make up some random ClientID which will always be your "visitor" for all PDF views. This "Measurement Protocol Method" might be acceptable, depending on what you want to measure. Remember, this Tag Manager method I described in my blog post only tracks clicks to PDF's. It doesn't show how many times someone has actually opened this PDF, but on the other hand it shows that click's source, medium, campaign, etc. Measurement Protocol might show you the amount of "pageviews" to your PDF, regardless the source. If you don't need the PDF load visit source information, than Measurement Protocol might be good for you. Will you use events, pageviews or custom dimensions in MP URL, it's up to you. Chris, please try the Measurement Protocol option and tell us if it works. I'll be glad to mention your successful solution in my future posts :) Good luck!
25

Chris McCreery

Reply
Thanks Robert, I think ultimately I'm going to have to use a server side script to redirect pdf requests as I have thousands of pdfs I would need to edit to add a tracking pixel. I can't find many references to example scripts that work properly. I've even messaged various Google Analytics social profiles but never get a response. Was hoping someone might have a solution as I'm sure there are many websites that are losing out on credit being associated with their efforts when the pdfs they create are directly accessed from search results.
26

Sam

Reply
Hi Robert, Great instructions, thanks. Very detailed. One thing I'm wondering about is .xls and .doc files. We have a lot of these on our website. I thought that this process would work for them, and appears to have partly done - I can see the .xls views in the 'real time' section on GA, but not when I go to 'Site Content > All Pages'. I know it's perhaps not correct to track them as page views, as they're rarely opened in a browser, but nonetheless, would you expect this to work?
27

Robert Petković

Reply
Hi Sam! Yes, I would expect that to work, although I rather track .xls, .doc and .zip files as Google Analytics events. Many people also track PDFs as events, and that's not wrong either. I only suggest to track PDFs as Pageviews because PDF files are usually presented that way - to show something more about the website. XLS files you use to do something besides the website itself. Real Time analytics and "regular" analytics are not using the same Analytics engine, but still they should show these hits as pageviews. Real Time is sometimes not that strict in terms of errors and it shows more data than regular reports, but that is really just sometimes. Also, you should see the data in regular reports after a couple of minutes (or even hours) and not just immediately. It's been a couple of days since you wrote this, so I sincerely hope you are able to see your data in Google Analytics now.
28

Anthony

Reply
Hello Robert... great article. I am seeing PDF click tracking after just a few minutes of implementing GTM and Analytics. My question now is, within Analytics, I can see the PDF file path, but was wondering if there is a way to also show which page URL the PDF was clicked on? We have multiple pages that point to the same resource and want to know what page that visitor clicked the link on ... possible?
29

Robert Petković

Reply
Hi Anthony, this is a very good question, thank you! The answer is rather easy, just find that particular Pageview under Behavior - Site content - All Pages, click on that PDF Pageview and then select tab "Navigation Summary". You should see URLs where that PDF has been clicked to under "Previous Page Path". Hope that's what you were looking for ;)
30

Anthony

Reply
Perfect. Thank you.
31

Craig

Reply
Hi Robert. Thanks for this. I have set up Tag Manager and followed your instructions but cannot see PDFs in my Pageviews. Do I need to move my Analytics into Tag Manager for this to work?
32

Robert Petković

Reply
Hi Craig, thanks for the visit! I'm afraid I don't get your question. Do you have a Tag Manager code on your website or the Universal Analytics code? You should have the appropriate Tag Manager code in order for this to work. Your Google Analytics Property ID should be typed into "Tracking ID" field of every Tag you create here, regardless if it's a PDF Virtual Pageview or a regular pageview that should fire on every page. Could you be more specific? Thanks.
33

Craig

Reply
Thanks for the reply Robert! Sorry, I'll try to be more clear.> Do you have a Tag Manager code on your website or the Universal Analytics code?I have both the Tag Manager and Universal Analytics code included on my website. My question is in regards to moving Analytics into Tag Manager as mentioned on this website: https://www.distilled.net/blog/getting-started-with-google-tag-manager/ (the "Moving Google Analytics to Google Tag Manager" section). Currently I'm not doing this. Do I need to do this for the PDF tracking to work?
34

Paul

Reply
Hi Robert, a very informative article. Thank you. Just to clarify, if we share a PDF on a URL ending with .PDF which is hosted on our site and the user clicks on the social media generated short URL which opens up our PDF URL, will your 'click listener tag' methodology work? Many thanks.
35

Robert Petković

Reply
Hi Paul! No, this method won't work in that case, sorry. But looking from a marketeer's side, I would always recommend to navigate users to some landing page where you can put a link to your PDF, as well as a brief explanation of the document.
36

Jeremy

Reply
Interesting ideas around using Google Analytics to track PDF downloads as page views. We actually we looking for this awhile back with a bunch of external research PDF's that we share with our clients and we stumbled across Orangedox. It's quite a bit easier to setup then using GA, give us view times as well as the average time spent on each page and it also let's us brand the documents as our own (since we didn't create the original PDF). Worth checking out!
37

Robert Petković

Reply
Thanks Jeremy, I will check-out Orangedox, but as far as I can see it only works with files that are inside your Dropbox account, right?
38

Mike

Reply
Is it possible to apply this method to external PDFs? I am sending a link to a PDF in an email blast and the PDF is hosted on our Wordpress site, but the link does not actually appear anywhere on our website.I'd like to track through Google Analytics who is clicking the link within the email.Thank you! Mike
39

Robert Petković

Reply
Hi Mike, thanks for the visit! Unfortunately, as I stated here many times, it is not possible to track direct email links to PDF files this way. But I always suggest to navigate users to some landing page with a link to PDF and a brief explanation of the document.

Share your thoughts

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