Skip to content

hueper/PDF-Analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 Commits

Repository files navigation

PDF-Analytics

Tracking user interaction within a PDF

We are using PDF.js a JavaScript library to parse PDF files using the HTML5 Canvas. The browser output is HTML, not a PDF. That makes tracking easy as cake.

Requirements

Interactions

pagechange (user scrolls to another page)
click
  • download
  • print
  • zoomIn
  • zoomOut
  • presentationMode
  • viewFind (user searches)

How to track

  1. Get Git:
    https://git-scm.com/downloads

  2. Get the JavaScript tracking snippet:
    https://developers.google.com/analytics/devguides/collection/analyticsjs/

  3. Get PDF.js:

 $ git clone git://github.com/mozilla/pdf.js.git $ cd pdf.js # following pdf.js install instructions https://github.com/mozilla/pdf.js#getting-the-code: $ npm install -g gulp-cli $ npm install $ gulp server # open http://localhost:8888/web/viewer.html
  1. Add pdf-analytics.js:
  • add pdf-analytics.js to pdf.js/web
  • add your JavaScript tracking snippet to pdf.js/viewer.html (right before the closing body tag):
<scriptsrc="pdf-analytics.js"></script><script>vartrackInteraction=function(cat,url){ga('send','event',cat,'scroll',url,{'transport': 'beacon'});}</script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*newDate();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','YOUR-TRACKING-ID','auto');ga('send','pageview');</script></body>

Done

Contributions

Are very welcome

License

MIT

About

Tracking user interaction within a PDF

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published