From 628e939537a1b5069dfefa532285457b9635fcc4 Mon Sep 17 00:00:00 2001 From: Marc Rutkowski Date: Mon, 6 Jan 2025 15:52:00 +0100 Subject: [PATCH] =?UTF-8?q?Met=20=C3=A0=20jour=20l'identifiant=20de=20trac?= =?UTF-8?q?king?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core-logic/api/auth/AuthProvider.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app.territoiresentransitions.react/src/core-logic/api/auth/AuthProvider.tsx b/app.territoiresentransitions.react/src/core-logic/api/auth/AuthProvider.tsx index 250c5dfb1c..1869c9ef4c 100644 --- a/app.territoiresentransitions.react/src/core-logic/api/auth/AuthProvider.tsx +++ b/app.territoiresentransitions.react/src/core-logic/api/auth/AuthProvider.tsx @@ -14,6 +14,7 @@ import { SignInWithPasswordCredentials, User, } from '@supabase/supabase-js'; +import { usePostHog } from 'posthog-js/react'; import { createContext, ReactNode, @@ -109,6 +110,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { const { data: userData = null } = useUserData(session); + const posthog = usePostHog(); + useEffect(() => { // écoute les changements d'état (connecté, déconnecté, etc.) const { @@ -139,12 +142,22 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { if (window.location.href.includes('localhost')) environment = 'development'; + if (posthog) { + posthog.identify(userData.id, { + email: userData.email, + user_id: userData.id, + }); + } + if (environment === 'production' || environment === 'test') { // @ts-expect-error - StonlyWidget is not defined window.StonlyWidget('identify', userData.user_id); } } else { clearCrispUserData(); + if (posthog) { + posthog.reset(); + } } }, [userData]);