2023-03-29 11:13:06 +02:00
|
|
|
export const trackEvent = (
|
|
|
|
category: string,
|
|
|
|
action: string,
|
|
|
|
label?: string,
|
|
|
|
value?: number,
|
|
|
|
) => {
|
|
|
|
try {
|
2023-06-19 11:18:28 +02:00
|
|
|
// place here categories that you want to track as events
|
|
|
|
// KEEP IN MIND THE PRICING
|
|
|
|
const ALLOWED_CATEGORIES_TO_TRACK = [] as string[];
|
2023-03-29 11:13:06 +02:00
|
|
|
// Uncomment the next line to track locally
|
|
|
|
// console.log("Track Event", { category, action, label, value });
|
|
|
|
|
2023-07-26 22:34:06 +05:30
|
|
|
if (typeof window === "undefined" || process.env.JEST_WORKER_ID) {
|
2023-03-29 11:13:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-19 11:18:28 +02:00
|
|
|
if (!ALLOWED_CATEGORIES_TO_TRACK.includes(category)) {
|
|
|
|
return;
|
2023-03-29 11:13:06 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 19:11:42 +02:00
|
|
|
if (window.sa_event) {
|
|
|
|
window.sa_event(action, {
|
|
|
|
category,
|
|
|
|
label,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}
|
2023-03-29 11:13:06 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error("error during analytics", error);
|
|
|
|
}
|
|
|
|
};
|