3

Is it possible that I can insert a tracking code of Google analytics in PDF file? I want to know where are users coming from and how users behave in my PDF file.

Please do guide me if you know some process or approach...

I know that PDF accepts some javascript, but I don't know if its capable of google analytics.

Thanks!

Pennf0lio
  • 3,888
  • 8
  • 46
  • 70

3 Answers3

2

You can't, to my knowledge, insert the actual Google Analytics JavaScript snippet into a PDF.

EDIT: My previous answer was incorrect; I said you could embed the __utm.gif that GA fires in the PDF, but @Mark is correct in saying this is not possible.

The correct answer is: It's not possible to embed an external resource in a PDF, at least not with modern PDF readers with basic security settings.

Yahel
  • 37,023
  • 22
  • 103
  • 153
  • next problem would be, how am i gonna insert this in my PDF, I think acrobat dont allow me to do this. – Pennf0lio May 23 '11 at 00:17
  • There are PDF SDKs that let you add externally reference images to PDF files. It is technically possible but most applications default to embedding the image data. Email me or ask another question and I can make some suggestions. – Rowan May 23 '11 at 18:50
  • Embedding an "external image" into a PDF embeds the image into the PDF. That PDF then has an internal copy of that image. No fancy link is going to help you get analytics data when its only used once. – Mark Storer May 25 '11 at 23:26
  • This answer creates a whirlwind of emotions! 1. You can't, 2. My previous answer was incorrect. 3. The correct answer is no. WHY DID YOU DO THIS!? – WPZA Dec 19 '18 at 16:43
1

Personally I place the PDF inside an iframe and then I place my GA and Piwik in the header of the html page that contains the iframe. A bit crooked, but does the job.

1

That simply isn't going to work. PDF's object model is completely different from HTML's DOM. Scripts in one won't work in the other, failing with various null references:

var foo = document.getElementByID("someID");

"Boom: document is undefined", as is "window" and all the other global objects web pages depend on.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80