diff --git a/.changeset/brown-foxes-hide.md b/.changeset/brown-foxes-hide.md new file mode 100644 index 00000000..7312848b --- /dev/null +++ b/.changeset/brown-foxes-hide.md @@ -0,0 +1,9 @@ +--- +"@ima/plugin-analytic-google": patch +--- + +Correct GTM params + +- **What?** Push correct data format to Google Tag Manager `dataLayer`. +- **Why?** Otherwise the GA4 events are not hit. GTM needs the params in the `Arguments` array-like object - not object, not array. +- **How?** Nothing. diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts index d880a737..a9678c90 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts @@ -171,8 +171,9 @@ export class GoogleAnalytics4 extends AbstractAnalytic { _createGlobalDefinition(window: globalThis.Window) { window.dataLayer = window.dataLayer || []; - this._ga4Script = function (...rest: unknown[]) { - window.dataLayer.push(...rest); + this._ga4Script = function () { + // We are passing a set of arguments to the gtag function of GTM. This MUST be an `arguments` object, not an array. + window.dataLayer.push(arguments); // eslint-disable-line prefer-rest-params }; this._configuration();