@codecademy/tracking 1.0.36-alpha.65be92a8db.0 → 1.0.36-alpha.8939ef2b6b.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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { initializeGTM } from './gtm';
|
|
2
2
|
import { initializeOneTrust } from './onetrust';
|
|
3
|
+
import { initializePartytown } from './partytown';
|
|
3
4
|
/**
|
|
4
5
|
* @see README.md for details and usage.
|
|
5
6
|
*/
|
|
@@ -26,4 +27,9 @@ export const initializeTrackingIntegrations = async _ref => {
|
|
|
26
27
|
optedOutExternalTracking,
|
|
27
28
|
partytown
|
|
28
29
|
});
|
|
30
|
+
|
|
31
|
+
// 4. Load Partytown
|
|
32
|
+
if (partytown) {
|
|
33
|
+
initializePartytown();
|
|
34
|
+
}
|
|
29
35
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initializePartytown: () => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { partytownSnippet } from '@builder.io/partytown/integration';
|
|
2
|
+
const ptConfig = () => ({
|
|
3
|
+
forward: ['dataLayer.push', 'fbq'],
|
|
4
|
+
lib: '/partytown/',
|
|
5
|
+
loadScriptsOnMainThread: [/googleads/, /bing/, /pepperjam/, /facebook/, /snap/, /lightboxcdn/],
|
|
6
|
+
resolveUrl(url) {
|
|
7
|
+
/*
|
|
8
|
+
* When gtm.js tries to create an iframe for sw_iframe, typically this does
|
|
9
|
+
* not worker becuase it's a cross origin request and google does not include
|
|
10
|
+
* a cross origin response header. As a workaround, we can change the url so
|
|
11
|
+
* it points to a proxy that we have setup in next.config.js. This way, it's
|
|
12
|
+
* on the same origin, and no response cors header is needed.
|
|
13
|
+
*/
|
|
14
|
+
const ptGtmProxyBase = `${process.env.NEXT_PUBLIC_BASE_PATH}/partytown-gtm-proxy`;
|
|
15
|
+
if (url.href.includes('sw_iframe')) {
|
|
16
|
+
return new URL(`${ptGtmProxyBase}${url.pathname}`);
|
|
17
|
+
}
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const encapsulate = js => `(() => {${js}})();`;
|
|
22
|
+
export const initializePartytown = () => {
|
|
23
|
+
if (!document.getElementById('partytown-init')) {
|
|
24
|
+
const ptScript = document.createElement('script');
|
|
25
|
+
ptScript.id = 'partytown-init';
|
|
26
|
+
ptScript.innerHTML = encapsulate(partytownSnippet(ptConfig()));
|
|
27
|
+
document.head.appendChild(ptScript);
|
|
28
|
+
}
|
|
29
|
+
};
|
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.8939ef2b6b.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": "a0cdc42894af72d49e7edcd13ecdbed93c6f8805"
|
|
17
17
|
}
|