-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* posthog added to project * added posthog
- Loading branch information
Showing
8 changed files
with
264 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ yarn-error.log* | |
# Sentry Auth Token | ||
.sentryclirc | ||
|
||
.env*.local |
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 |
---|---|---|
@@ -1,10 +1,55 @@ | ||
import "@514labs/design-system-base/globals.css"; | ||
import RootLayout from "../components/layouts"; | ||
import { useEffect } from 'react' | ||
import { useRouter } from 'next/router' | ||
import Router from 'next/router' | ||
import posthog from 'posthog-js' | ||
import { PostHogProvider } from 'posthog-js/react' | ||
|
||
|
||
export default function App({ Component, pageProps }) { | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
// Wait until Next.js router is ready to ensure query params are populated. | ||
if (!router.isReady) return; | ||
|
||
// Extract cross-site tracking params from Next.js router query. | ||
// These are added by TrackLink as 'ph_distinct_id' and 'ph_session_id'. | ||
const { ph_distinct_id, ph_session_id } = router.query; | ||
let bootstrapData = {}; | ||
|
||
if (ph_distinct_id || ph_session_id) { | ||
bootstrapData = { | ||
...(ph_distinct_id && { distinct_id: ph_distinct_id }), | ||
...(ph_session_id && { session_id: ph_session_id }), | ||
}; | ||
} | ||
|
||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', | ||
ui_host: 'https://us.posthog.com', | ||
bootstrap: bootstrapData, // Bootstrap with IDs from the URL if provided. | ||
// Enable debug mode in development | ||
loaded: (posthogInstance) => { | ||
if (process.env.NODE_ENV === 'development') posthogInstance.debug() | ||
} | ||
}) | ||
|
||
const handleRouteChange = () => posthog?.capture('$pageview') | ||
|
||
Router.events.on('routeChangeComplete', handleRouteChange); | ||
|
||
return () => { | ||
Router.events.off('routeChangeComplete', handleRouteChange); | ||
} | ||
}, [router.isReady]) | ||
|
||
return ( | ||
<RootLayout> | ||
<Component {...pageProps} /> | ||
</RootLayout> | ||
<PostHogProvider client={posthog}> | ||
<RootLayout> | ||
<Component {...pageProps} /> | ||
</RootLayout> | ||
</PostHogProvider> | ||
); | ||
} |
Oops, something went wrong.