2023-06-26 12:36:15 +03:00
|
|
|
"use client";
|
|
|
|
|
2023-12-30 01:45:36 +03:00
|
|
|
import { usePostHog } from "posthog-js/react";
|
2023-12-28 13:03:05 +03:00
|
|
|
|
2023-06-26 12:36:15 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
|
|
|
|
|
|
|
import { useJune } from "./useJune";
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
export const useEventTracking = () => {
|
|
|
|
const analytics = useJune();
|
2023-12-28 13:03:05 +03:00
|
|
|
const posthog = usePostHog();
|
2023-06-26 12:36:15 +03:00
|
|
|
const { session } = useSupabase();
|
|
|
|
|
2023-08-29 13:26:08 +03:00
|
|
|
const track = async (
|
|
|
|
event: string,
|
|
|
|
properties?: Record<string, unknown>
|
|
|
|
): Promise<void> => {
|
2023-12-28 13:03:05 +03:00
|
|
|
posthog.capture(event, properties);
|
2023-08-25 11:33:14 +03:00
|
|
|
if (analytics === undefined) {
|
|
|
|
console.log("No analytics found");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await analytics.identify(session?.user.id, { email: session?.user.email });
|
2023-08-29 13:26:08 +03:00
|
|
|
await analytics.track(event, properties);
|
2023-06-26 12:36:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
track,
|
|
|
|
};
|
|
|
|
};
|