-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from berachain/posthog-setup
Posthog Analytics
- Loading branch information
Showing
20 changed files
with
356 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import { usePostHog } from "posthog-js/react"; | ||
|
||
export default function PostHogPageView(): null { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const posthog = usePostHog(); | ||
useEffect(() => { | ||
// Track pageviews | ||
if (pathname && posthog) { | ||
let url = window.origin + pathname; | ||
if (searchParams.toString()) { | ||
url = `${url}?${searchParams.toString()}`; | ||
} | ||
posthog.capture("$pageview", { | ||
$current_url: url, | ||
}); | ||
} | ||
}, [pathname, searchParams, posthog]); | ||
|
||
return null; | ||
} |
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 |
---|---|---|
@@ -1,24 +1,40 @@ | ||
"use client"; | ||
import React, { type PropsWithChildren } from "react"; | ||
|
||
import React, { useEffect, type PropsWithChildren } from "react"; | ||
import { BeraJsProvider, BlockTimeProvider } from "@bera/berajs"; | ||
import { BeraWagmi } from "@bera/wagmi"; | ||
import posthog from "posthog-js"; | ||
import { PostHogProvider } from "posthog-js/react"; | ||
|
||
import { ThemeProvider } from "~/components/theme-provider"; | ||
import { BeraJsProvider, BlockTimeProvider } from "@bera/berajs"; | ||
|
||
export default function Providers({ children }: PropsWithChildren<any>) { | ||
useEffect(() => { | ||
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) { | ||
return; | ||
} | ||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, | ||
person_profiles: "identified_only", | ||
capture_pageview: false, // Disable automatic pageview capture, as we capture manually | ||
}); | ||
}, []); | ||
return ( | ||
<BeraWagmi> | ||
<BeraJsProvider configOverride={undefined}> | ||
<BlockTimeProvider> | ||
<ThemeProvider | ||
attribute="class" | ||
defaultTheme="dark" | ||
forcedTheme="dark" | ||
themes={["dark"]} | ||
> | ||
{children} | ||
</ThemeProvider> | ||
</BlockTimeProvider> | ||
</BeraJsProvider> | ||
</BeraWagmi> | ||
<PostHogProvider client={posthog}> | ||
<BeraWagmi> | ||
<BeraJsProvider configOverride={undefined}> | ||
<BlockTimeProvider> | ||
<ThemeProvider | ||
attribute="class" | ||
defaultTheme="dark" | ||
forcedTheme="dark" | ||
themes={["dark"]} | ||
> | ||
{children} | ||
</ThemeProvider> | ||
</BlockTimeProvider> | ||
</BeraJsProvider> | ||
</BeraWagmi> | ||
</PostHogProvider> | ||
); | ||
} |
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
Oops, something went wrong.