send sign_in telemetry event

This commit is contained in:
Alaister Young committed 2023-05-15 21:43:48 +10:00
1 parent 9c4d82c021
commit b49968d977
2 files changed
+20 -2

No files matched your search

+2 -2
View File
@@ -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
+18
View File
@@ -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) {