Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/landing-site/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const GA_TAG_ID = import.meta.env.VITE_GOOGLE_ANALYTICS
<script is:inline define:vars={{ GA_TAG_ID }}>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', GA_TAG_ID);
</script>
Expand Down
1 change: 1 addition & 0 deletions packages/site/src/layouts/base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const GA_TAG_ID = import.meta.env.VITE_GOOGLE_ANALYTICS
<script is:inline define:vars={{ GA_TAG_ID }}>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', GA_TAG_ID);
</script>
Expand Down
22 changes: 15 additions & 7 deletions packages/system/src/util/analytics-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ export const track = <T extends keyof TrackingCustomEvents>(
event: T,
...data: TrackingCustomEvents[T] extends void ? [] : [TrackingCustomEvents[T]]
): void => {
import.meta.env.MODE === 'production'
? data[0] != null
? gtag('event', event, data[0])
: gtag('event', event)
: data[0] != null
? console.info('track', event, data[0])
: console.info('track', event);
if (import.meta.env.MODE === 'production') {
if (typeof window !== 'undefined' && typeof window.gtag === 'function') {
if (data[0] != null) {
window.gtag('event', event, data[0]);
} else {
window.gtag('event', event);
}
}
} else {
if (data[0] != null) {
console.info('track', event, data[0]);
} else {
console.info('track', event);
}
}
};