-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gamification-removal
- Loading branch information
Showing
21 changed files
with
237 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./usePostHogIdentity" | ||
export * from "./usePostHogCapture" | ||
export * from "./usePostHogPageViewCapture" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { PostHogEvent } from "#/posthog/events" | ||
import { PostHog, usePostHog } from "posthog-js/react" | ||
import { useCallback } from "react" | ||
|
||
type CaptureArgs = [ | ||
eventName: PostHogEvent, | ||
...rest: Parameters<PostHog["capture"]> extends [unknown, ...infer R] | ||
? R | ||
: never, | ||
] | ||
|
||
export const usePostHogCapture = () => { | ||
const posthog = usePostHog() | ||
|
||
const handleCapture = useCallback( | ||
(...captureArgs: CaptureArgs) => { | ||
posthog.capture(...captureArgs) | ||
}, | ||
[posthog], | ||
) | ||
|
||
const handleCaptureWithCause = useCallback( | ||
(error: unknown, ...captureArgs: CaptureArgs) => { | ||
const [eventName, parameters, ...rest] = captureArgs | ||
|
||
const captureParameters = | ||
error instanceof Error | ||
? { | ||
...parameters, | ||
cause: error.message, | ||
} | ||
: undefined | ||
|
||
handleCapture(eventName, captureParameters, ...rest) | ||
}, | ||
[handleCapture], | ||
) | ||
|
||
return { handleCapture, handleCaptureWithCause } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { PostHog, usePostHog } from "posthog-js/react" | ||
import { useCallback } from "react" | ||
import { sha256, toUtf8Bytes } from "ethers" | ||
|
||
type IdentifyArgs = Parameters<PostHog["identify"]> | ||
|
||
export const usePostHogIdentity = () => { | ||
const posthog = usePostHog() | ||
|
||
const handleIdentification = useCallback( | ||
(...identifyArgs: IdentifyArgs) => { | ||
const [id, ...rest] = identifyArgs | ||
if (!id) return | ||
|
||
const hashedId = sha256(toUtf8Bytes(id.toLowerCase())).slice(2, 12) | ||
|
||
posthog.identify(hashedId, ...rest) | ||
}, | ||
[posthog], | ||
) | ||
|
||
const resetIdentity = useCallback(() => { | ||
posthog.reset() | ||
}, [posthog]) | ||
|
||
return { handleIdentification, resetIdentity } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PostHogEvent } from "#/posthog/events" | ||
import { useEffect } from "react" | ||
import { useLocation } from "react-router-dom" | ||
import { usePostHogCapture } from "./usePostHogCapture" | ||
|
||
export const usePostHogPageViewCapture = () => { | ||
const { handleCapture } = usePostHogCapture() | ||
const location = useLocation() | ||
|
||
useEffect(() => { | ||
handleCapture(PostHogEvent.PageView) | ||
}, [location, handleCapture]) | ||
|
||
return handleCapture | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.