mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 14:06:59 +00:00
23 lines
447 B
TypeScript
23 lines
447 B
TypeScript
// lib/gtm.ts
|
|
type WindowWithDataLayer = Window & {
|
|
dataLayer: Record<string, any>[];
|
|
};
|
|
|
|
declare const window: WindowWithDataLayer;
|
|
|
|
export const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID;
|
|
|
|
export const pageview = (url: string) => {
|
|
if (typeof window.dataLayer !== 'undefined') {
|
|
window.dataLayer.push({
|
|
event: 'pageview',
|
|
page: url
|
|
});
|
|
} else {
|
|
console.debug({
|
|
event: 'pageview',
|
|
page: url
|
|
});
|
|
}
|
|
};
|