forked from remix-run/indie-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stephen Chiang
committed
Apr 29, 2022
1 parent
7540097
commit f632678
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
declare global { | ||
interface Window { | ||
gtag: ( | ||
option: string, | ||
gaTrackingId: string, | ||
options: Record<string, unknown> | ||
) => void; | ||
} | ||
} | ||
|
||
/** | ||
* @example | ||
* https://developers.google.com/analytics/devguides/collection/gtagjs/pages | ||
*/ | ||
export const pageview = (url: string, trackingId: string) => { | ||
if (!window.gtag) { | ||
console.warn( | ||
"window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet." | ||
); | ||
return; | ||
} | ||
window.gtag("config", trackingId, { | ||
page_path: url, | ||
}); | ||
}; | ||
|
||
/** | ||
* @example | ||
* https://developers.google.com/analytics/devguides/collection/gtagjs/events | ||
*/ | ||
export const event = ({ | ||
action, | ||
category, | ||
label, | ||
value, | ||
}: Record<string, string>) => { | ||
if (!window.gtag) { | ||
console.warn( | ||
"window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet." | ||
); | ||
return; | ||
} | ||
window.gtag("event", action, { | ||
event_category: category, | ||
event_label: label, | ||
value: value, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as gtag from "./gtags.client"; |