Skip to content

Commit

Permalink
fix(PostHogProvider): use alias to merge anonymous and identified u…
Browse files Browse the repository at this point in the history
…sers
  • Loading branch information
BrickheadJohnny committed Feb 23, 2025
1 parent f6f8499 commit a9d45ba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/v2/components/Providers/PostHogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ export function CustomPostHogProvider({ children }: { children: ReactNode }) {

const identifyUser = useCallback(
(userData: User) => {
posthog.identify(userData.id.toString(), {
const anonymousId = posthog.get_distinct_id()

const userIdAsString = userData.id.toString()

posthog.identify(userIdAsString, {
primaryAddress: userData.addresses.find((a) => a.isPrimary)?.address,
currentAddress: address,
walletType,
wallet: connectorName,
})

if (anonymousId !== userIdAsString) {
posthog.alias(userIdAsString, anonymousId)
}
},
[address, connectorName, walletType]
)
Expand Down

0 comments on commit a9d45ba

Please sign in to comment.