Giter Site home page Giter Site logo

pdf-analytics's Introduction

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):
  <script src="pdf-analytics.js"></script>
    <script>
      var trackInteraction = 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*new Date();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

pdf-analytics's People

Contributors

hueper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.