Skip to content

Commit

Permalink
Merge pull request #163 from seznam/ga4-hit-fix
Browse files Browse the repository at this point in the history
Push correct data format to GTM data layer
  • Loading branch information
corvidism committed Apr 18, 2024
2 parents 3988e41 + 7830f4b commit ad68dc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .changeset/brown-foxes-hide.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions packages/plugin-analytic-google/src/GoogleAnalytics4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ad68dc6

Please sign in to comment.