Import snowplow as a javascript library

As a modern javascript developer using tools like Create React App, I would like to simply import snowplow into my project. I don’t see that as an option in your guide.

Ideally, I’d like both JS & TS options.

JS
import snowplow from “snowplow”

TS
import * as snowplow from “snowplow”

I would rather not use require as suggested in this NPM package but even that is better than adding a script tag snippet to an index.html

Hi @brandon
Unfortunately at the moment we don’t have a version of our JavaScript tracker that is packaged as a module so that you can import in this way. When working on an application of the type you describe (React, Angular, etc), we often see our sp.js file downloaded from GitHub Releases and bundled into applications so that it loads along with the rest of your JavaScript assets. If this isn’t feasible then the best option currently is to take sp.js and host it on a CDN, such as CloudFront, to be loaded asynchronously through the script tag snippet.

The good news is that this is on our roadmap for 2020, we certainly want to look at how we can better bundle our JavaScript tracker and this will form part of it. You could subscribe to this Github issue to get updates once we begin our work on it. This issue will certainly form part of the work towards this goal: https://github.com/snowplow/snowplow-javascript-tracker/issues/752.

As for the NPM Package you mentioned, this is the shared core between our JavaScript tracker and Node.js tracker. It doesn’t include a number of features that the Tracker libraries contain, such as a variety of helper tracking functions and utilising Local Storage to cache events on page change or poor connectivity. We generally advise to not directly use this, unless you wish to build your own wrapper and tracking functionality around the core Snowplow tracking library.

3 Likes

excellent @PaulBoocock - while we’re evaluating Snowplow today, we don’t actually need to (or more like want to) use it as import until sometime in 2020 - it sounds like it will be straightforward to swap out the script snippet for the import later on - thanks, I’ll follow the updates.

2 Likes