You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 analytics 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 analytics script has not loaded on the page yet.",
);
return;
}
window.gtag("event", action, {
event_category: category,
event_label: label,
value: value,
});
};
Reproduction
Root
gtag util
System Info
Used Package Manager
npm
Expected Behavior
That I got no hydration err
Actual Behavior
Google analatiycs works but not google tag manager. I got hydration error when I use this code:
The text was updated successfully, but these errors were encountered: