The Snowplow JavaScript Tracker can now be deployed directly into your web and node applications using the analytics
and @analytics/snowplow
NPM packages.
This is particularly useful for modern web applications built with Single Page Application frameworks such as React, Angular or Vue. It’s also a great package if sending events to multiple platforms.
Quick Start
npm install analytics
npm install @analytics/snowplow
Code language: CSS (css)
Initialise the plugin:
import Analytics from 'analytics'
import snowplowPlugin from '@analytics/snowplow'
const analytics = Analytics({
app: 'awesome-app',
plugins: [
// Minimal recommended configuration
snowplowPlugin({
name: 'snowplow',
scriptSrc: 'https://cdn.jsdelivr.net/gh/snowplow/sp-js-assets@2.17.3/sp.js',
collectorUrl: 'collector.mysite.com',
trackerSettings: {
appId: 'myApp',
contexts: {
webPage: true
}
}
})
]
})
Code language: JavaScript (javascript)
Then track a page view event:
analytics.page()
Code language: CSS (css)
Full documentation
Snowplow Plugin documentation (getanalytics.io)
Analytics package documentation (getanalytics.io)