Skip to content

Commit

Permalink
feat(react-tracking): prepare dataLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Oct 25, 2024
1 parent cac82bb commit ec06ed9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tender-rats-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/react-tracking": patch
---

The dataLayer is now prepared in case the script is not yet loaded.
4 changes: 3 additions & 1 deletion packages/react-tracking/utilities/createGtmTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function createGtmTracker({
prefix,
}: { prefix?: string } = {}): Tracker {
return function gtmTracker({ type, ...event }) {
window.dataLayer?.push({
window.dataLayer = window.dataLayer || [];

window.dataLayer.push({
event: [prefix, type].filter(Boolean).join("."),
...event,
});
Expand Down

0 comments on commit ec06ed9

Please sign in to comment.