Say I have a file in my website: https://example.com/sample.pdf

Is there a way to track how many people clicking on the link, similarly how regular links are tracked? The article Additional kinds of measurement - Analytics Help suggests me to measure clicks as Events. However, if I send the direct link to the viewers, there will be no script to be fired.

  • 1
    Google Analytics isn't the right tool for the job. I don't think you can add your tracking snippet to a PDF document. Do you have access logs you can use instead? Feb 15, 2021 at 17:37
  • 1
    @StephenOstermiller I agree. I wonder if a workaround by putting a link to an html file (with the Analytics code embedded) which then calls the PDF would be sufficient for the OP?
    – davidgo
    Feb 15, 2021 at 19:55
  • @StephenOstermiller yes, but having it included in the Google Analytics report would be convenient. Also, I would like to have different tracking links for different targets. I think the idea of putting it into an HTML file is good. Definitely better than having one redirect to the file
    – Ooker
    Feb 16, 2021 at 13:50
  • @davidgo thanks for you suggestion. It works great
    – Ooker
    Mar 6, 2021 at 10:52

1 Answer 1


I create a blank HTML file, then embed the PDF inside it:

    <embed src="path/to/file" width="100%" height="100%"  type="application/pdf">

For your convenience, here is my template:

<title>CHANGE THIS TEXT</title>
<meta charset="UTF-8">
<meta name="description" content="CHANGE THIS TEXT">
<meta name="keywords" content="CHANGE THIS TEXT">
<meta name="author" content="CHANGE THIS TEXT">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta property="og:title" content="CHANGE THIS TEXT" />
<meta property="og:description" content="CHANGE THIS TEXT" />
<meta property="og:image" content="CHANGE THIS TEXT" />

<!-- INSERT Google Tag Manager script -->
<!-- INSERT Facebook Like script -->    

@media only screen and (max-width: 600px) {
    .phone {
        font-size: large;
        display: none;

@media only screen and (min-width: 601px) {
    .phone {
        display: none;

<div class="phone">
    <a href="https://xkcd.com/1110/"><img src="https://explainxkcd.com/wiki/images/c/c7/click_and_drag.png" width="100%" alt="From the stories, I expected the world to be sad.
    And it was
    And I expected it to be wonderful.
    It was.
    I just didn't expect it to be so big."></a>

<div class="desktop">
    <embed src="CHANGE THIS TEXT" width="100%" height="100%"  type="application/pdf">
<div class="fb-like" data-href="CHANGE THIS TEXT" data-width="" data-layout="standard" data-action="like" data-size="small" data-share="true" ></div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.