Skip to content

Commit c2c58d4

Browse files
authored
Issue #853: Fix gtag dataLayer push to use arguments instead of array (#885)
##### Description of Change The gtag.js library expects `Arguments` objects in the `dataLayer`, not arrays. Our implementation used rest params (`...args`) which pushed arrays — gtag loaded but never sent data to Google. Fix: switch to the canonical `function() { dataLayer.push(arguments); }` pattern that Google's own snippet uses. **Before:** gtag.js loaded (200 OK), zero `/g/collect` requests sent **After:** gtag.js loaded, collection requests sent to Google Analytics ##### Related Issues Follow-up fix for the GA4 instrumentation in #875 ##### Type of Change - [x] Bug fix (non-breaking change which fixes an issue) ##### Project Area(s) Affected - [x] frontends/ ##### Testing - [x] Manual testing performed (Playwright verified `/g/collect` requests) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 9b5ef69 + f6de40f commit c2c58d4

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

frontends/lif_advisor_app/src/utils/analytics.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ function loadGtag(): void {
1616
document.head.appendChild(script);
1717

1818
window.dataLayer = window.dataLayer || [];
19-
window.gtag = function gtag(...args: unknown[]) {
20-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21-
(window.dataLayer as any[]).push(args);
19+
// gtag.js expects the `arguments` object to be pushed into dataLayer (not a rest-parameter array)
20+
// eslint-disable-next-line prefer-rest-params
21+
window.gtag = function () {
22+
window.dataLayer.push(arguments);
2223
};
2324
window.gtag('js', new Date());
2425
window.gtag('config', MEASUREMENT_ID, { anonymize_ip: true });

frontends/mdr-frontend/src/utils/analytics.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ function loadGtag(): void {
1616
document.head.appendChild(script);
1717

1818
window.dataLayer = window.dataLayer || [];
19-
window.gtag = function gtag(...args: unknown[]) {
20-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21-
(window.dataLayer as any[]).push(args);
22-
};
19+
// Must use `arguments` (not rest params) — gtag.js checks for Arguments objects in dataLayer
20+
// eslint-disable-next-line prefer-rest-params
21+
window.gtag = function () { window.dataLayer.push(arguments); };
2322
window.gtag('js', new Date());
2423
window.gtag('config', MEASUREMENT_ID, { anonymize_ip: true });
2524
}

0 commit comments

Comments
 (0)