@autobusal/providers 1.44.1 → 1.44.2
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/Setup/analytics.ts +38 -5
- package/package.json +1 -1
package/Setup/analytics.ts
CHANGED
|
@@ -42,13 +42,46 @@ const analytics = (container: string | null | undefined): void => {
|
|
|
42
42
|
window.dataLayer = window.dataLayer || [];
|
|
43
43
|
window.dataLayer.push({ 'gtm.start': Date.now(), event: 'gtm.js' });
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/*
|
|
46
|
+
* LOADED IN THE FIRST QUIET MOMENT, not while the page races for the
|
|
47
|
+
* network.
|
|
48
|
+
*
|
|
49
|
+
* Edited: Claude - Date: 2026-09-16
|
|
50
|
+
*
|
|
51
|
+
* Measured with Lighthouse against production on a throttled phone: the
|
|
52
|
+
* container and the GA tag it pulls are 287 KB of script - more than this
|
|
53
|
+
* app's own entry chunk - fetched in the same window as the bundle, the
|
|
54
|
+
* translations and the images, on a connection modelled at 1.6 Mbps. The
|
|
55
|
+
* page is no more usable for having them early, and every byte they take
|
|
56
|
+
* is one the content is waiting for.
|
|
57
|
+
*
|
|
58
|
+
* The dataLayer is filled FIRST, above, and GTM reads whatever is already
|
|
59
|
+
* in it when it boots - so a page view or a commerce event announced in
|
|
60
|
+
* the meantime still arrives. That is the only thing that could have made
|
|
61
|
+
* deferring this wrong.
|
|
62
|
+
*
|
|
63
|
+
* Safari has no requestIdleCallback, so setTimeout is the fallback rather
|
|
64
|
+
* than a polyfill: "soon, after the load" is the whole requirement.
|
|
65
|
+
*/
|
|
66
|
+
const load = (): void => {
|
|
67
|
+
if (document.getElementById(CONTAINER_ID)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
46
70
|
|
|
47
|
-
|
|
48
|
-
script.async = true;
|
|
49
|
-
script.src = `https://www.googletagmanager.com/gtm.js?id=${ encodeURIComponent(container) }`;
|
|
71
|
+
const script = document.createElement('script');
|
|
50
72
|
|
|
51
|
-
|
|
73
|
+
script.id = CONTAINER_ID;
|
|
74
|
+
script.async = true;
|
|
75
|
+
script.src = `https://www.googletagmanager.com/gtm.js?id=${ encodeURIComponent(container) }`;
|
|
76
|
+
|
|
77
|
+
document.head.appendChild(script);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (typeof window.requestIdleCallback === 'function') {
|
|
81
|
+
window.requestIdleCallback(load, { timeout: 2000 });
|
|
82
|
+
} else {
|
|
83
|
+
window.setTimeout(load, 1200);
|
|
84
|
+
}
|
|
52
85
|
};
|
|
53
86
|
|
|
54
87
|
/**
|