Skip to content

Commit

Permalink
fix(react-tracking): dataLayer null check
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Oct 25, 2024
1 parent 5b7d59b commit 14227c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-hornets-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/react-tracking": patch
---

The window.dataLayer is now null-checked in case of adblockers.
4 changes: 2 additions & 2 deletions packages/react-tracking/utilities/createGtmTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Tracker } from "../components/TrackingProvider";

declare global {
interface Window {
dataLayer: Array<Record<string, unknown>>;
dataLayer?: Array<Record<string, unknown>>;
}
}

export function createGtmTracker({
prefix,
}: { prefix?: string } = {}): Tracker {
return function gtmTracker({ type, ...event }) {
window.dataLayer.push({
window.dataLayer?.push({
event: [prefix, type].filter(Boolean).join("."),
...event,
});
Expand Down

0 comments on commit 14227c8

Please sign in to comment.