Snowplow JavaScript Tracker 2.2.0 released
We are happy to announce the release of version 2.2.0 of the Snowplow JavaScript Tracker. This release improves the Tracker’s callback support, making it possible to use access previously internal variables such as the tracker-generated user fingerprint and user ID. It also adds the option to disable the Tracker’s use of localStorage
and first-party cookies.
The rest of this blog post will cover the following topics:
- More powerful callbacks
- Disabling localStorage and cookies
- Non-integer offsets
- Upgrading
- Getting help
1. More powerful callbacks
Version 2.1.1 added support for custom callbacks to be executed when sp.js loads:
This release extends that support by calling the callback function as a method on an internal trackerDictionary
object. This sets the value of this
in the callback to the trackerDictionary
, allowing you to call methods which return results on individual tracker instances.
An example which extracts all the available fields:
Note that getDomainUserInfo()
returns an array containing 6 elements:
- A string set to
'1'
if this is the user’s first session and'0'
otherwise - The domain user ID
- The timestamp at which the cookie was created
- The number of times the user has visited the site
- The timestamp for the current visit
- The timestamp of the last visit
This change is backward-compatible unless you were relying on your callback function being executed in the global context (meaning that this
is set to window
).
We would like to thank Snowplow community member Rob Murphy (@murphybob) for his help developing this feature!
2. Disabling localStorage and cookies
The Snowplow JavaScript Tracker maintains a queue of events that have failed to send. This means that if a visitor loses and later regains connectivity, no data will be lost. By default the tracker will use localStorage
to store this queue so the events are recoverable even after the user leaves the site.
You can now disable this use of localStorage
by setting a flag in the argmap used to create a new tracker instance. You can also disable the use of first-party cookies:
Disabling first-party cookies can be useful if you are deploying the JavaScript Tracker in an environment where first-party cookies are forbidden (for example, in ad tags running on Google domains).
3. Non-integer offsets
Snowplow page ping events include the maximum and minimum scroll distances since the last pa
ge ping. We found that it is possible for the scroll values reported by the browser to not be whole numbers, causing the event to fail enrichment (which requires these fields to be integers). We have fixed this bug by rounding the relevant values to the nearest integer.
4. Upgrading
The new minified and gzipped JavaScript is available at
http(s)://d1fc8wv8zag5ca.cloudfront.net/2.2.0/sp.js
5. Getting help
Check out the documentation for more help and examples.
If you have any suggestions for new features or need help getting set up, please get in touch. And raise an issue if you spot a bug!