You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
891 B
TypeScript
41 lines
891 B
TypeScript
1 year ago
|
// place here categories that you want to track. We want to track just a
|
||
|
// small subset of categories at a given time.
|
||
|
const ALLOWED_CATEGORIES_TO_TRACK = ["ai"] as string[];
|
||
|
|
||
2 years ago
|
export const trackEvent = (
|
||
|
category: string,
|
||
|
action: string,
|
||
|
label?: string,
|
||
|
value?: number,
|
||
|
) => {
|
||
|
try {
|
||
1 year ago
|
// prettier-ignore
|
||
|
if (
|
||
|
typeof window === "undefined"
|
||
|
|| import.meta.env.VITE_WORKER_ID
|
||
|
// comment out to debug locally
|
||
|
|| import.meta.env.PROD
|
||
|
) {
|
||
2 years ago
|
return;
|
||
|
}
|
||
|
|
||
2 years ago
|
if (!ALLOWED_CATEGORIES_TO_TRACK.includes(category)) {
|
||
|
return;
|
||
2 years ago
|
}
|
||
|
|
||
1 year ago
|
if (!import.meta.env.PROD) {
|
||
|
console.info("trackEvent", { category, action, label, value });
|
||
|
}
|
||
|
|
||
2 years ago
|
if (window.sa_event) {
|
||
|
window.sa_event(action, {
|
||
|
category,
|
||
|
label,
|
||
|
value,
|
||
|
});
|
||
|
}
|
||
2 years ago
|
} catch (error) {
|
||
|
console.error("error during analytics", error);
|
||
|
}
|
||
|
};
|