UNPKG

2.85 kBMarkdownView Raw
1# Snowplow JavaScript Tracker
2
3[![npm version][npm-image]][npm-url]
4[![License][license-image]](LICENSE)
5
6Add Snowplow Tracking to your website via a tag solution.
7
8## Maintainer quick start
9
10Part of the Snowplow JavaScript Tracker monorepo.
11Build with [Node](https://nodejs.org/en/) (10+) and [Rush](https://rushjs.io/).
12
13### Setup repository
14
15```bash
16$ npm install -g @microsoft/rush
17$ git clone https://github.com/snowplow/snowplow-javascript-tracker.git
18$ rush update
19```
20
21## Select your version
22
23This repository creates two versions of the tracker.
24
25The fully featured `sp.js` contains the majority of the plugins included within this repository for a complete tracking experience. This is our recommended version.
26
27However, if you'd like a lightweight version of the tracker you can opt for `sp.lite.js`.
28This version only includes Page Views, Page Activity, Structured and Self Describing events as well as global contexts and anonymous tracking.
29
30## Installation
31
32Add the tag to your website or Tag Management solution:
33
34```html
35<script type="text/javascript" async=1>
36;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","{{URL to sp.js}}","snowplow"));
37</script>
38
39<script>
40window.snowplow('newTracker', 'sp', collector_endpoint, {
41 appId: 'my-app',
42 eventMethod: 'post',
43 contexts: {
44 performanceTiming: true,
45 },
46});
47</script>
48```
49
50We advise you host `sp.js` or `sp.lite.js` yourself, and rename it. However if you'd like use a CDN, you'll find the tracker on jsDelivr, unpkg and cdnjs.
51
52## Usage
53
54```js
55window.snowplow('enableLinkClickTracking');
56
57window.snowplow('trackPageView', {
58 title: 'My Title',
59 context: [
60 // Set page title; add page context
61 {
62 schema: 'iglu:org.schema/WebPage/jsonschema/1-0-0',
63 data: {
64 keywords: ['tester'],
65 },
66 },
67 ],
68});
69
70window.snowplow('trackSelfDescribingEvent', {
71 event: {
72 schema: 'iglu:com.acme/my_event/jsonschema/1-0-0',
73 data: {
74 myId: '12345-abc',
75 },
76 }
77});
78```
79
80## Copyright and license
81
82Licensed and distributed under the [BSD 3-Clause License](LICENSE) ([An OSI Approved License][osi]).
83
84Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang.
85
86All rights reserved.
87
88[npm-url]: https://www.npmjs.com/package/@snowplow/browser-tracker
89[npm-image]: https://img.shields.io/npm/v/@snowplow/browser-tracker
90[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/
91[osi]: https://opensource.org/licenses/BSD-3-Clause
92[license-image]: https://img.shields.io/npm/l/@snowplow/javascript-tracker