Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Javascript Tracker
  6. Modifying snowplow.js

Modifying snowplow.js

It may be necessary for you to make changes to snowplow.js. If you do, then you will also need to minify your updated snowplow.js prior to deploying it. This guide covers how to do this.

To continue with this guide, you will need the following

  • Access to a Unix-like command line
  • Familiarity with and access to [Git][git]
  • Node.js version 10 or above installed
  • npm version 1.4.0 or above installed
  • Some level of technical ability ta2, where ta1 < ta2 < ninja

See this page for guidance help installing node and npm.

Check out the source code

First please download the source code to your development machine:

$ cd ~/development $ git clone git@github.com:snowplow/snowplow-javascript-tracker.git $ cd snowplow-javascript-tracker $ npm install $ grunt $ cd dist $ ls bundle.js snowplow.js sp.js
Code language: PHP (php)

In the listing above, bundle.js is the Browserified JavaScript; snowplow.js is identical to bundle.js but has a banner comment at the top; and sp.js is the minified version.

Update snowplow.js

Making changes to snowplow.js (and testing them) is out of scope of this document. A brief overview of the steps it involves:

  • Make whatever changes you want to inside snowplow-javascript-tracker/src/js
  • Run $ grunt from the snowplow-javascript-tracker directory to rebuild the files in snowplow-javascript-tracker/dist
  • Use the example page snowplow-javascript-tracker/examples/web/async/async-small.html to test your changes locally. You will probably want to edit that file, replacing "//cdn.jsdelivr.net/gh/snowplow/sp-js-assets@2.0.0/sp.js" with "../../dist/snowplow.js", so that it loads your modified copy of snowplow.js.

Upload the minified JavaScript

Use your standard asset pipelining strategy to upload the minified sp.js JavaScript to your servers. Note that to avoid “mixed content” warnings, Snowplow expects the sp.js JavaScript to be available both via HTTP and via HTTPS.

Test your updated JavaScript

As a final step, you will want to just check that your customised sp.js JavaScript is working okay.

To do this, please follow the testing instructions on Testing the Javascript tracker is firing.