Integrate google analytics

This commit is contained in:
Kamran Ahmed
2021-09-05 18:40:02 +02:00
parent 0067cfdbc6
commit dd43969dfb
2 changed files with 11 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ declare global {
}
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const firePageView = (url: string) => {
export function firePageView(url: string) {
if (!window.gtag) {
console.warn('Missing GTAG Analytics disabled');
return;
@@ -14,10 +14,10 @@ export const firePageView = (url: string) => {
window.gtag('config', process.env.GA_SECRET, {
page_path: url
});
};
}
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = (props: { action: string; category: string; label: string; value: string; }) => {
export function event(props: { action: string; category: string; label: string; value: string; }) {
const { action, category, label, value } = props;
if (!window.gtag) {
console.warn('Missing GTAG Analytics disabled');
@@ -33,4 +33,4 @@ export const event = (props: { action: string; category: string; label: string;
value: value
}
);
};
}