@codecademy/tracking 1.0.36-alpha.8d366e53b7.0 → 1.0.36-alpha.a87f8f3bb5.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.
|
@@ -3,6 +3,7 @@ export type GTMSettings = {
|
|
|
3
3
|
environment: string;
|
|
4
4
|
scope: TrackingWindow;
|
|
5
5
|
optedOutExternalTracking?: boolean;
|
|
6
|
+
partytown?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare const OPT_OUT_DATALAYER_VAR = "user_opted_out_external_tracking";
|
|
8
|
-
export declare const initializeGTM: ({ scope, environment, optedOutExternalTracking, }: GTMSettings) => void;
|
|
9
|
+
export declare const initializeGTM: ({ scope, environment, optedOutExternalTracking, partytown, }: GTMSettings) => void;
|
package/dist/integrations/gtm.js
CHANGED
|
@@ -2,7 +2,8 @@ export const OPT_OUT_DATALAYER_VAR = 'user_opted_out_external_tracking';
|
|
|
2
2
|
export const initializeGTM = _ref => {
|
|
3
3
|
let scope = _ref.scope,
|
|
4
4
|
environment = _ref.environment,
|
|
5
|
-
optedOutExternalTracking = _ref.optedOutExternalTracking
|
|
5
|
+
optedOutExternalTracking = _ref.optedOutExternalTracking,
|
|
6
|
+
partytown = _ref.partytown;
|
|
6
7
|
scope.dataLayer ??= [];
|
|
7
8
|
scope.dataLayer.push({
|
|
8
9
|
'gtm.start': new Date().getTime(),
|
|
@@ -21,7 +22,13 @@ export const initializeGTM = _ref => {
|
|
|
21
22
|
}
|
|
22
23
|
const gtm = document.createElement('script');
|
|
23
24
|
gtm.src = `https://www.googletagmanager.com/gtm.js?id=GTM-KTLK85W${preview_env}`;
|
|
24
|
-
|
|
25
|
+
if (partytown) {
|
|
26
|
+
gtm.type = 'text/partytown';
|
|
27
|
+
} else {
|
|
28
|
+
gtm.async = true;
|
|
29
|
+
}
|
|
25
30
|
document.getElementsByTagName('head')[0].appendChild(gtm);
|
|
26
|
-
|
|
31
|
+
if (partytown) {
|
|
32
|
+
window.dispatchEvent(new CustomEvent('ptupdate'));
|
|
33
|
+
}
|
|
27
34
|
};
|
|
@@ -16,8 +16,13 @@ export type TrackingIntegrationsSettings = {
|
|
|
16
16
|
* id for the one trust script being used, defaults to the script for `www.codecademy.com`
|
|
17
17
|
*/
|
|
18
18
|
oneTrustScript?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Use partytown to load scripts.
|
|
21
|
+
* next.config.js experimental: { nextScriptWorkers } must be set to true.
|
|
22
|
+
*/
|
|
23
|
+
partytown?: boolean;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* @see README.md for details and usage.
|
|
22
27
|
*/
|
|
23
|
-
export declare const initializeTrackingIntegrations: ({ environment, scope, optedOutExternalTracking, oneTrustScript, }: TrackingIntegrationsSettings) => Promise<void>;
|
|
28
|
+
export declare const initializeTrackingIntegrations: ({ environment, scope, optedOutExternalTracking, oneTrustScript, partytown, }: TrackingIntegrationsSettings) => Promise<void>;
|
|
@@ -7,9 +7,12 @@ export const initializeTrackingIntegrations = async _ref => {
|
|
|
7
7
|
let environment = _ref.environment,
|
|
8
8
|
scope = _ref.scope,
|
|
9
9
|
optedOutExternalTracking = _ref.optedOutExternalTracking,
|
|
10
|
-
oneTrustScript = _ref.oneTrustScript
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
oneTrustScript = _ref.oneTrustScript,
|
|
11
|
+
partytown = _ref.partytown;
|
|
12
|
+
if (!partytown) {
|
|
13
|
+
// 1. Wait 1000ms to allow any other post-hydration logic to run first
|
|
14
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
15
|
+
}
|
|
13
16
|
|
|
14
17
|
// 2. Load in OneTrust's banner and wait for its `OptanonWrapper` callback
|
|
15
18
|
await initializeOneTrust({
|
|
@@ -22,6 +25,7 @@ export const initializeTrackingIntegrations = async _ref => {
|
|
|
22
25
|
initializeGTM({
|
|
23
26
|
scope,
|
|
24
27
|
environment,
|
|
25
|
-
optedOutExternalTracking
|
|
28
|
+
optedOutExternalTracking,
|
|
29
|
+
partytown
|
|
26
30
|
});
|
|
27
31
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/tracking",
|
|
3
3
|
"description": "Tracking library for Codecademy",
|
|
4
|
-
"version": "1.0.36-alpha.
|
|
4
|
+
"version": "1.0.36-alpha.a87f8f3bb5.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist/**"
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"repository": "git@github.com:codecademy-engineering/mono.git",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "52eff623109d9edbe7aa3d6ba4fe0c8b585eb2ad"
|
|
17
17
|
}
|