-
Notifications
You must be signed in to change notification settings - Fork 71
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 #260 from availproject/staging
fix: posthog config + new banner
- Loading branch information
Showing
5 changed files
with
132 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// app/providers.js | ||
'use client' | ||
import posthog from 'posthog-js' | ||
import { PostHogProvider } from 'posthog-js/react' | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
if (typeof window !== 'undefined') { | ||
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) { | ||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, | ||
capture_pageview: false // Disable automatic pageview capture, as we capture manually | ||
}) | ||
} | ||
} | ||
|
||
export function PostHogPageview() { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
// Track pageviews | ||
useEffect(() => { | ||
if (pathname) { | ||
let url = window.origin + pathname | ||
if (searchParams.toString()) { | ||
url = url + `?${searchParams.toString()}` | ||
} | ||
posthog.capture( | ||
'$pageview', | ||
{ | ||
'$current_url': url, | ||
} | ||
) | ||
} | ||
}, [pathname, searchParams]) | ||
|
||
return (<></>) | ||
} | ||
|
||
export function PHProvider({ children }: { | ||
children: React.ReactNode | ||
}) { | ||
return <PostHogProvider client={posthog}>{children}</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
|
||
import { Suspense } from 'react'; | ||
import '../styles/globals.css'; | ||
import Head from 'next/head'; | ||
import { PHProvider, PostHogPageview } from '@/components/providers'; | ||
|
||
|
||
export default function App({ Component, pageProps }) { | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<meta charSet="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Avail Developer Docs</title> | ||
</Head> | ||
<Suspense> | ||
<PostHogPageview /> | ||
</Suspense> | ||
<PHProvider> | ||
<Component {...pageProps} /> | ||
</PHProvider> | ||
</> | ||
); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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