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):
This commit is contained in:
Stan Girard 2023-12-29 23:45:36 +01:00 committed by GitHub
parent c95e0ec00c
commit 5beb5c6829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 17 deletions

View File

@ -1,8 +1,8 @@
"use client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { posthog } from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';
import { posthog } from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { PropsWithChildren, useEffect } from "react";
import { Menu } from "@/lib/components/Menu/Menu";
@ -17,17 +17,16 @@ import { usePageTracking } from "@/services/analytics/june/usePageTracking";
import "../lib/config/LocaleConfig/i18n";
if (process.env.NEXT_PUBLIC_POSTHOG_KEY != null && process.env.NEXT_PUBLIC_POSTHOG_HOST != null) {
posthog.init(
process.env.NEXT_PUBLIC_POSTHOG_KEY,
{
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
opt_in_site_apps: true
},
);
if (
process.env.NEXT_PUBLIC_POSTHOG_KEY != null &&
process.env.NEXT_PUBLIC_POSTHOG_HOST != null
) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
opt_in_site_apps: true,
});
}
// This wrapper is used to make effect calls at a high level in app rendering.
const App = ({ children }: PropsWithChildren): JSX.Element => {
const { fetchAllBrains, fetchDefaultBrain, fetchPublicPrompts } =
@ -42,6 +41,7 @@ const App = ({ children }: PropsWithChildren): JSX.Element => {
void fetchAllBrains();
void fetchDefaultBrain();
void fetchPublicPrompts();
posthog.identify(session.user.id, { email: session.user.email });
}
}, [session]);

View File

@ -1,14 +1,11 @@
"use client";
import { usePostHog } from 'posthog-js/react';
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();
@ -19,9 +16,7 @@ export const useEventTracking = () => {
event: string,
properties?: Record<string, unknown>
): Promise<void> => {
posthog.capture(event, properties);
posthog.identify(session?.user.id, { email: session?.user.email });
if (analytics === undefined) {
console.log("No analytics found");