From b49968d977d4e3047b20fc28e231a367d458442e Mon Sep 17 00:00:00 2001 From: Alaister Young Date: Mon, 15 May 2023 21:43:48 +1000 Subject: [PATCH] send sign_in telemetry event --- studio/hooks/misc/useProfile.tsx | 4 ++-- studio/lib/auth.tsx | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/studio/hooks/misc/useProfile.tsx b/studio/hooks/misc/useProfile.tsx index 08f4dbaca4c..93901e82cd3 100644 --- a/studio/hooks/misc/useProfile.tsx +++ b/studio/hooks/misc/useProfile.tsx @@ -3,7 +3,7 @@ import { useRouter } from 'next/router' import { useTelemetryProps } from 'common' import { useProfileCreateMutation } from 'data/profile/profile-create-mutation' import { useProfileQuery } from 'data/profile/profile-query' -import telemetry from 'lib/telemetry' +import Telemetry from 'lib/telemetry' /** * Fetches the user's profile, creating one if it does not exist @@ -14,7 +14,7 @@ function useProfile() { const { mutate: createProfile, isLoading: isCreating } = useProfileCreateMutation({ onSuccess() { - telemetry.sendEvent( + Telemetry.sendEvent( { category: 'conversion', action: 'sign_up', label: '' }, telemetryProps, router diff --git a/studio/lib/auth.tsx b/studio/lib/auth.tsx index 973530e3afd..815387f5c08 100644 --- a/studio/lib/auth.tsx +++ b/studio/lib/auth.tsx @@ -1,4 +1,5 @@ import { useQueryClient } from '@tanstack/react-query' +import { useRouter } from 'next/router' import { PropsWithChildren, useCallback, useEffect } from 'react' import { @@ -17,6 +18,7 @@ export const AuthContext = AuthContextInternal export const AuthProvider = ({ children }: PropsWithChildren<{}>) => { const { ui, app } = useStore() + const router = useRouter() const telemetryProps = useTelemetryProps() // Check for unverified GitHub users after a GitHub sign in @@ -36,6 +38,22 @@ export const AuthProvider = ({ children }: PropsWithChildren<{}>) => { handleEmailVerificationError() }, []) + useEffect(() => { + const { + data: { subscription }, + } = gotrueClient.onAuthStateChange((event) => { + if (event === 'SIGNED_IN') { + Telemetry.sendEvent( + { category: 'conversion', action: 'sign_in', label: '' }, + telemetryProps, + router + ) + } + }) + + return subscription.unsubscribe + }, []) + // Track telemetry for the current user useProfileQuery({ onSuccess(profile) {