quivr/frontend/services/analytics/june/useEventTracking.ts
Stan Girard 5beb5c6829
feat: 🎸 posthog (#1936)
identify init

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2023-12-29 23:45:36 +01:00

33 lines
790 B
TypeScript

"use client";
import { usePostHog } from "posthog-js/react";
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();
const posthog = usePostHog();
const { session } = useSupabase();
const track = async (
event: string,
properties?: Record<string, unknown>
): Promise<void> => {
posthog.capture(event, properties);
if (analytics === undefined) {
console.log("No analytics found");
return;
}
await analytics.identify(session?.user.id, { email: session?.user.email });
await analytics.track(event, properties);
};
return {
track,
};
};