Skip to content

Commit

Permalink
Implement identity id hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
kpyszkowski committed Nov 28, 2024
1 parent bb14994 commit b3b99a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dapp/src/hooks/posthog/usePostHogIdentity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PostHog, usePostHog } from "posthog-js/react"
import { useCallback } from "react"
import { sha256, toUtf8Bytes } from "ethers"

type IdentifyArgs = Parameters<PostHog["identify"]>

Expand All @@ -8,7 +9,12 @@ export const usePostHogIdentity = () => {

const handleIdentification = useCallback(
(...identifyArgs: IdentifyArgs) => {
posthog.identify(...identifyArgs)
const [id, ...rest] = identifyArgs
if (!id) return

const hashedId = sha256(toUtf8Bytes(id.toLowerCase())).slice(2, 12)

posthog.identify(hashedId, ...rest)
},
[posthog],
)
Expand Down

0 comments on commit b3b99a0

Please sign in to comment.