Skip to content

Commit c1453c5

Browse files
authored
feat: track anonymous user (#238)
1 parent 84b4a97 commit c1453c5

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/util/AmplitudeProvider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { useEffectOnce } from '@/util/hooks/useEffectOnce'
55
const AmplitudeProvider = () => {
66
const user = useUserData()
77
useEffectOnce(() => {
8-
if (!user) return
9-
initAmplitude(user.id, () => setInitialUserProperties(user))
8+
initAmplitude(user?.id, () => {
9+
if (user) setInitialUserProperties(user)
10+
})
1011
})
1112

1213
return null

src/util/analytics/amplitude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { identify, Identify, init, setUserId } from '@amplitude/analytics-browse
22

33
import { UserInfo } from '@/providers/UserProvider'
44

5-
export const initAmplitude = async (userId: string, callback?: () => void) => {
5+
export const initAmplitude = async (userId?: string, callback?: () => void) => {
66
init(import.meta.env.VITE_API_AMPLITUDE_API_KEY, {
77
userId,
88
defaultTracking: true,

0 commit comments

Comments
 (0)