-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d65e321
commit 14f96dc
Showing
15 changed files
with
1,099 additions
and
511 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_POSTHOG_KEY="" | ||
NEXT_PUBLIC_POSTHOG_HOST="" |
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,46 @@ | ||
'use client' | ||
|
||
import { Player } from '@lottiefiles/react-lottie-player' | ||
|
||
export default function Content() { | ||
return ( | ||
<> | ||
<Player | ||
src="https://lottie.host/7401522f-2d8b-4049-ad18-eb0edb6af224/CE9lFrNlEH.json" | ||
// className="ph-no-capture" | ||
background="Transparent" | ||
speed={3} | ||
style={{ width: 300, height: 300 }} | ||
direction={1} | ||
// mode="normal" | ||
loop | ||
// controls | ||
autoplay | ||
/> | ||
<Player | ||
src="https://lottie.host/fb187981-8846-4ae9-98db-b95fc6347955/vO2S1YTZMn.json" | ||
// className="ph-no-capture" | ||
background="Transparent" | ||
speed={3} | ||
style={{ width: 300, height: 300 }} | ||
direction={1} | ||
// mode="normal" | ||
loop | ||
// controls | ||
autoplay | ||
/> | ||
<Player | ||
src="https://lottie.host/3239c7de-e4de-4148-830d-e95b7f747f91/vftYOWDcUO.json" | ||
// className="ph-no-capture" | ||
background="Transparent" | ||
speed={3} | ||
style={{ width: 300, height: 300 }} | ||
direction={1} | ||
// mode="normal" | ||
loop | ||
// controls | ||
autoplay | ||
/> | ||
</> | ||
) | ||
} |
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,70 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
import { useEffect, useState } from 'react' | ||
import { useFeatureFlagEnabled, usePostHog } from 'posthog-js/react' | ||
|
||
export default function Content({ flags }: { flags: Record<string, string | boolean> }) { | ||
const posthog = usePostHog() | ||
const result = useFeatureFlagEnabled('test') | ||
|
||
const [time, setTime] = useState('') | ||
|
||
useEffect(() => { | ||
const t = setInterval(() => { | ||
setTime(new Date().toISOString().split('T')[1].split('.')[0]) | ||
}, 1000) | ||
|
||
return () => { | ||
clearInterval(t) | ||
} | ||
}, []) | ||
|
||
const randomID = () => Math.round(Math.random() * 10000) | ||
|
||
return ( | ||
<> | ||
<main> | ||
<h1>PostHog React</h1> | ||
|
||
<p>The current time is {time}</p> | ||
|
||
<div className="buttons"> | ||
<button onClick={() => posthog.capture('Clicked button')}>Capture event</button> | ||
<button data-attr="autocapture-button">Autocapture buttons</button> | ||
<a data-attr="autocapture-button" href="#"> | ||
<span>Autocapture a > span</span> | ||
</a> | ||
|
||
<button className="ph-no-capture">Ignore certain elements</button> | ||
|
||
<button onClick={() => posthog?.identify('user-' + randomID())}>Identify</button> | ||
|
||
<button | ||
onClick={() => | ||
posthog?.setPersonProperties({ | ||
email: `user-${randomID()}@posthog.com`, | ||
}) | ||
} | ||
> | ||
Set user properties | ||
</button> | ||
</div> | ||
|
||
<div className="buttons"> | ||
<Link href="/animations">Animations</Link> | ||
<Link href="/iframe">Iframe</Link> | ||
<Link href="/media">Media</Link> | ||
<Link href="/long">Long</Link> | ||
</div> | ||
|
||
<p> | ||
Feature flag response: <code>{JSON.stringify(result)}</code> | ||
</p> | ||
<p> | ||
SSR feature flags: <code>{JSON.stringify(flags)}</code> | ||
</p> | ||
</main> | ||
</> | ||
) | ||
} |
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,37 @@ | ||
'use client' | ||
|
||
import { usePostHog } from 'posthog-js/react' | ||
import { useEffect, useState } from 'react' | ||
|
||
export default function Page() { | ||
const posthog = usePostHog() | ||
|
||
const [otherHost, setOtherHost] = useState('') | ||
|
||
useEffect(() => { | ||
setOtherHost(window.location.origin.includes('other-localhost') ? 'localhost' : 'other-localhost') | ||
}) | ||
|
||
return ( | ||
<> | ||
<main> | ||
<h1>Iframes</h1> | ||
|
||
<h2>Cross origin iframe</h2> | ||
<p> | ||
This loads the same page but from <b>other-localhost</b> which you need to add to your hosts file. | ||
</p> | ||
|
||
{otherHost && ( | ||
<iframe | ||
src={`http://${otherHost}:3000/`} | ||
style={{ width: '100%', height: '500px' }} | ||
onLoad={() => { | ||
posthog.capture('iframe loaded') | ||
}} | ||
/> | ||
)} | ||
</main> | ||
</> | ||
) | ||
} |
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,39 +1,17 @@ | ||
import '@/styles/globals.css' | ||
import { ReactNode, Suspense } from 'react' | ||
import { PostHogPageview, Providers } from './providers' | ||
|
||
import React, { useEffect } from 'react' | ||
import type { AppProps } from 'next/app' | ||
import { useRouter } from 'next/router' | ||
|
||
import posthog from 'posthog-js' | ||
import { PostHogProvider } from 'posthog-js/react' | ||
|
||
if (typeof window !== 'undefined') { | ||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || '', { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com', | ||
session_recording: { | ||
recordCrossOriginIframes: true, | ||
}, | ||
debug: true, | ||
}) | ||
;(window as any).posthog = posthog | ||
} | ||
|
||
export default function App({ Component, pageProps }: AppProps) { | ||
const router = useRouter() | ||
|
||
useEffect(() => { | ||
// Track page views | ||
const handleRouteChange = () => posthog.capture('$pageview') | ||
router.events.on('routeChangeComplete', handleRouteChange) | ||
|
||
return () => { | ||
router.events.off('routeChangeComplete', handleRouteChange) | ||
} | ||
}, []) | ||
|
||
export default function RootLayout({ children }: { children: ReactNode }) { | ||
return ( | ||
<PostHogProvider client={posthog}> | ||
<Component {...pageProps} /> | ||
</PostHogProvider> | ||
<html lang="en"> | ||
<Suspense> | ||
<PostHogPageview /> | ||
</Suspense> | ||
|
||
<Providers> | ||
<body>{children}</body> | ||
</Providers> | ||
</html> | ||
) | ||
} |
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.