@codecademy/tracking 1.0.3-alpha.8d0a0395a.0 → 1.0.3-alpha.c00898968.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/README.md +100 -0
- package/dist/index.cjs +711 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +595 -3
- package/dist/package.json +21 -0
- package/package.json +2 -2
- package/dist/events/index.d.ts +0 -3
- package/dist/events/index.js +0 -3
- package/dist/events/track.d.ts +0 -12
- package/dist/events/track.js +0 -115
- package/dist/events/types.d.ts +0 -251
- package/dist/events/types.js +0 -1
- package/dist/events/user.d.ts +0 -2
- package/dist/events/user.js +0 -41
- package/dist/integrations/conditionallyLoadAnalytics.d.ts +0 -9
- package/dist/integrations/conditionallyLoadAnalytics.js +0 -27
- package/dist/integrations/consent.d.ts +0 -9
- package/dist/integrations/consent.js +0 -11
- package/dist/integrations/device.d.ts +0 -13
- package/dist/integrations/device.js +0 -25
- package/dist/integrations/fetchDestinationsForWriteKey.d.ts +0 -6
- package/dist/integrations/fetchDestinationsForWriteKey.js +0 -88
- package/dist/integrations/getConsentDecision.d.ts +0 -8
- package/dist/integrations/getConsentDecision.js +0 -32
- package/dist/integrations/index.d.ts +0 -31
- package/dist/integrations/index.js +0 -90
- package/dist/integrations/mapDestinations.d.ts +0 -13
- package/dist/integrations/mapDestinations.js +0 -55
- package/dist/integrations/onetrust.d.ts +0 -6
- package/dist/integrations/onetrust.js +0 -53
- package/dist/integrations/runSegmentSnippet.d.ts +0 -7
- package/dist/integrations/runSegmentSnippet.js +0 -64
- package/dist/integrations/types.d.ts +0 -24
- package/dist/integrations/types.js +0 -1
package/dist/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# `@codecademy/tracking`
|
|
2
|
+
|
|
3
|
+
This package contains our user "telemetry" (tracking metrics such as `click` and `visit`) integrations that are shared across multiple web properties.
|
|
4
|
+
|
|
5
|
+
We've consolidated them here for a few reasons:
|
|
6
|
+
|
|
7
|
+
- To standardize APIs around events like tracking user clicks
|
|
8
|
+
- To make sure any third party integrations are CCPA & GDPR compliant
|
|
9
|
+
- Because this repository already has a sweet CI setup for previewing and auto-publishing new versions 😎
|
|
10
|
+
|
|
11
|
+
There are two kinds of tracking we package in this library:
|
|
12
|
+
|
|
13
|
+
- **Internal** tracking ([`createTracker`](#createTracker)): sent directly to our `/analytics/` endpoint
|
|
14
|
+
- **External** tracking ([`useTrackingIntegrations`](#useTrackingIntegrations)): scripts loaded via Google Tag Manager
|
|
15
|
+
|
|
16
|
+
## `createTracker`
|
|
17
|
+
|
|
18
|
+
Creates a "tracker" object that includes methods for user telemetry such as `click` and `visit`.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { createTracker } from '@codecademy/tracking';
|
|
22
|
+
|
|
23
|
+
const tracker = createTracker('apiBaseUrl', 'authToken');
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Event Usage
|
|
27
|
+
|
|
28
|
+
#### `click`
|
|
29
|
+
|
|
30
|
+
Tracks that a user has clicked an element on the page.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
tracker.click({
|
|
34
|
+
page_name: 'my_page',
|
|
35
|
+
target: 'my_button',
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Calls to _`event`_ internally.
|
|
40
|
+
|
|
41
|
+
#### `visit`
|
|
42
|
+
|
|
43
|
+
Tracks that a user has visited a page or sub-page.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
tracker.visit({
|
|
47
|
+
page_name: 'my_page',
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Calls to _`event`_ internally.
|
|
52
|
+
|
|
53
|
+
#### `event`
|
|
54
|
+
|
|
55
|
+
Generic event for any other event.
|
|
56
|
+
Events that are allowed to be used here are strongly typed in the `types.d.ts` file included in the package.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
tracker.event('calendar', 'reminder', data);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Miscellaneous Usage
|
|
63
|
+
|
|
64
|
+
#### `pushDataLayerEvent`
|
|
65
|
+
|
|
66
|
+
Adds a [GTM `dataLayer` event](https://developers.google.com/tag-manager/devguide) to the global `dataLayer` array.
|
|
67
|
+
If `dataLayer` does not exist, it will be created.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
tracker.pushDataLayerEvent('user_sign_up');
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## `initializeTrackingIntegrations`
|
|
74
|
+
|
|
75
|
+
> See [GDPR Compliance on Notion](https://www.notion.so/codecademy/GDPR-Compliance-141ebcc7ffa542daa0da56e35f482b41) for full docs on external tracking.
|
|
76
|
+
|
|
77
|
+
Starts the initialization process for our third-party integrations.
|
|
78
|
+
|
|
79
|
+
Integrations are loaded in an intentionally layered manner for CCPA/GDPR compliance:
|
|
80
|
+
|
|
81
|
+
1. Wait 1000ms to allow any other post-hydration logic to run first
|
|
82
|
+
2. Load in OneTrust's banner and wait for its `OptanonWrapper` callback
|
|
83
|
+
3. [Segment's copy-and-paste snippet](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet) is run to load the Segment global library
|
|
84
|
+
4. Destination integrations for Segment are fetched
|
|
85
|
+
5. Those integrations are compared against the user's consent decisions into a list of allowed destinations
|
|
86
|
+
6. We load only those allowed destinations using Segment's `analytics.load`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { initializeTrackingIntegrations } from '@codecademy/tracking';
|
|
90
|
+
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
initializeTrackingIntegrations({
|
|
93
|
+
onError: logger.error,
|
|
94
|
+
production: true,
|
|
95
|
+
scope: window,
|
|
96
|
+
user: { email: 'my@email.com', id: 'my-user-id' },
|
|
97
|
+
writeKey: 'my-segment-write-key',
|
|
98
|
+
});
|
|
99
|
+
}, 1000);
|
|
100
|
+
```
|