mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-01 18:00:26 +00:00
32 lines
674 B
TypeScript
32 lines
674 B
TypeScript
export const GOOGLE_ANALYTICS_KEY =
|
|
process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_KEY;
|
|
|
|
export const pageview = (url: any) => {
|
|
// @ts-ignore
|
|
window.gtag('config', GOOGLE_ANALYTICS_KEY, {
|
|
page_path: url,
|
|
});
|
|
};
|
|
|
|
export const event = ({ action, category, label, value }: any) => {
|
|
// @ts-ignore
|
|
window.gtag('event', action, {
|
|
event_category: category,
|
|
event_label: label,
|
|
value: value,
|
|
});
|
|
};
|
|
|
|
export const initAnalytics = () => `
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag() {
|
|
dataLayer.push(arguments);
|
|
}
|
|
|
|
gtag('js', new Date());
|
|
gtag('config', ${GOOGLE_ANALYTICS_KEY}, {
|
|
page_path: window.location.pathname,
|
|
});
|
|
`;
|