A PDF file can’t include any javascript code in it, so it will not be easy for traffic visitors on any particular PDF file to check how many people have seen the file. In this post I will explain how you can track PDF file views without including any javascript or html code in it.


Google Analytic is a free (premium is also available for big companies) tool offered by Google that helps website owners to monitor website traffic, page views, real time visitors, events, etc. This tool also allows you to check traffic location, traffic source, keyword traffic, and social traffic, etc.


Benefits of Including Tracking Visits:

By adding Google Analytic javascript code in your website you can also track PDF file link clicks and PDF file viewers. This will be very helpful to know how many people are interested to view the particular PDF file or which file has more views than other files, how long users are viewing the PDF file, and many more things.


Steps to Track Visits:

There are two ways to track visits on PDF files:

1. Google Analytic Javasript Code.

2. Google Analytic Page Tracking Code.


Step 1 - Google Analytics Javascript Code:

Google Analytic provides a unique code for every website to track visitors. If you don’t have an account then make it, by following this URL: http://www.google.com/analytics/. To track views, Include unique Google Analytic code just above in all pages of your website. To get the code Go to Admin >> Select Account >> Tracking Info. The code will look like the below image:


Tracking Traffic to PDF file:

Add a URL to every link that is pointing to the document on your site.

For example: <a href="http://www.url.com/buy/product.pdf?pdf=Buy-Product" target="_blank">Buy Product</a>

In the above link I have added “?pdf=Buy-Product” in the parameter to the end of the URL link.

In the end, I have added a custom text so that I can tell this link was “Buy Product”. This code will not change anything in display or download by the users.


Check this in Google Analytic:

To check this, open your Google Analytic account, Go to >> Behavior >> Site Content >> All Pages

In the search box, type PDF to see all PDF files on which you have added the above parameter. Your PDF file title will appear there at the end of the URL parameter.

Step 2 - Google Analytic Page Tracking Code:

Google Analytic Page Tracking javascript code allows users to measure page views of a particular page on a website, it could be in the menu, body, sidebar, or even at the footer link.

For example, the code is like this:

<a href="xyz.pdf" onclick="ga('send', 'pageview', '/filepath');">Click to view</a>

Place the code and change the href and filepath to your own to make it working.

Important: To use the above code you must have the Google Analytic code on your website page.

Conclusion: Both the above mentioned processes are to measure page views on a particular file like PDF, video, text, etc. These steps will help you to track PDF file views on your website. If you still need any help, feel free to ask for it in comments.