-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: enable posthog analytics (#519)
- Loading branch information
1 parent
74e34db
commit 22c1dd0
Showing
11 changed files
with
236 additions
and
108 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,4 @@ | ||
VITE_PUBLIC_POSTHOG_KEY=phc_wqyze0qQlWutAwL5RL1Bv83D8bdySCkhcFw9MkTVuI8 | ||
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com | ||
VITE_ENV=development | ||
VITE_ENABLE_POSTHOG=false |
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,4 @@ | ||
VITE_PUBLIC_POSTHOG_KEY=phc_wqyze0qQlWutAwL5RL1Bv83D8bdySCkhcFw9MkTVuI8 | ||
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com | ||
VITE_ENV=production | ||
VITE_ENABLE_POSTHOG=true |
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,118 @@ | ||
import type { ReactNode, JSX } from 'react' | ||
|
||
import { createTheme, MantineProvider, AppShell } from '@mantine/core' | ||
|
||
import type { CSSVariablesResolver } from '@mantine/core' | ||
import { useDisclosure } from '@mantine/hooks' | ||
|
||
import PageWithTOC from '@/components/PageWithTOC' | ||
import Navbar from '@/components/Navbar' | ||
import Sidebar from '@/components/Sidebar' | ||
import MdxProvider from '@/components/MdxProvider' | ||
|
||
import '@mantine/core/styles.css' | ||
import '@mantine/code-highlight/styles.css' | ||
import Footer from '@/components/Footer' | ||
|
||
interface RootRouteProps { | ||
children: ReactNode | ||
} | ||
|
||
const theme = createTheme({ | ||
primaryColor: 'violet', | ||
primaryShade: { light: 6, dark: 9 }, | ||
fontFamily: 'Inter', | ||
fontFamilyMonospace: 'Menlo', | ||
respectReducedMotion: true, | ||
radius: { | ||
xs: '4px', | ||
sm: '4px', | ||
lg: '8px', | ||
xl: '8px', | ||
md: '8px', | ||
}, | ||
fontSizes: { | ||
// 'xs' | 'sm' | 'md' | 'lg' | 'xl' | ||
xs: '14px', | ||
sm: '14px', | ||
}, | ||
colors: { | ||
dark: [ | ||
'#d5d7e0', | ||
'#acaebf', | ||
'#8c8fa3', | ||
'#666980', | ||
'#4d4f66', | ||
'#34354a', | ||
'#2b2c3d', | ||
'#1d1e30', | ||
'#0c0d21', | ||
'#01010a', | ||
], | ||
}, | ||
headings: { | ||
sizes: { | ||
h1: { | ||
fontSize: '48px', | ||
}, | ||
}, | ||
}, | ||
other: { | ||
sidebarGrayLight: '#495057', | ||
sidebarGrayDark: '#adb5bd', | ||
sidebarTextHoverLight: '#212529', | ||
sidebarTextHoverDark: '#f8f9fa', | ||
}, | ||
}) | ||
|
||
const resolver: CSSVariablesResolver = (th) => { | ||
const { | ||
sidebarGrayLight, | ||
sidebarTextHoverLight, | ||
sidebarGrayDark, | ||
sidebarTextHoverDark, | ||
} = th.other as Record<string, string> | ||
|
||
return { | ||
variables: {}, | ||
light: { | ||
'--mantine-color-footer-bg': th.colors.gray[1], | ||
'--mantine-color-sidebar-gray': sidebarGrayLight, | ||
'--mantine-color-sidebar-text-hover': sidebarTextHoverLight, | ||
'--mantine-color-quote-border': th.colors.violet[1], | ||
}, | ||
dark: { | ||
'--mantine-color-footer-bg': th.colors.dark[6], | ||
'--mantine-color-sidebar-gray': sidebarGrayDark, | ||
'--mantine-color-sidebar-text-hover': sidebarTextHoverDark, | ||
'--mantine-color-quote-border': th.colors.violet[9], | ||
}, | ||
} | ||
} | ||
|
||
export default function App({ children }: RootRouteProps): JSX.Element { | ||
const [opened, { toggle }] = useDisclosure() | ||
|
||
return ( | ||
<MantineProvider theme={theme} cssVariablesResolver={resolver}> | ||
<AppShell | ||
layout="alt" | ||
header={{ height: 60 }} | ||
navbar={{ | ||
width: 300, | ||
breakpoint: 'sm', | ||
collapsed: { mobile: !opened }, | ||
}} | ||
> | ||
<Navbar toggle={toggle} /> | ||
<Sidebar close={toggle} /> | ||
<AppShell.Main pt={0} px="auto"> | ||
<MdxProvider> | ||
<PageWithTOC>{children}</PageWithTOC> | ||
</MdxProvider> | ||
</AppShell.Main> | ||
<Footer /> | ||
</AppShell> | ||
</MantineProvider> | ||
) | ||
} |
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 @@ | ||
import App from './App' | ||
|
||
export default App |
20 changes: 20 additions & 0 deletions
20
apps/documentation/src/components/PostHog/PostHogPageView.tsx
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,20 @@ | ||
import { useEffect } from 'react' | ||
import { usePostHog } from 'posthog-js/react' | ||
import { useRouter } from 'tuono' | ||
|
||
export default function PostHogPageView(): null { | ||
const { pathname } = useRouter() | ||
const posthog = usePostHog() | ||
|
||
// Track pageviews | ||
useEffect(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (pathname && posthog) { | ||
const url = window.origin + pathname | ||
|
||
posthog.capture('$pageview', { $current_url: url }) | ||
} | ||
}, [pathname, posthog]) | ||
|
||
return null | ||
} |
31 changes: 31 additions & 0 deletions
31
apps/documentation/src/components/PostHog/PostHogProvider.tsx
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,31 @@ | ||
import type { JSX, ReactNode } from 'react' | ||
import { useEffect } from 'react' | ||
import { PostHogProvider as PostHogLibraryProvider } from 'posthog-js/react' | ||
import posthogJs from 'posthog-js' | ||
|
||
interface PostHogProviderProps { | ||
children: ReactNode | ||
} | ||
|
||
export default function PostHogProvider({ | ||
children, | ||
}: PostHogProviderProps): JSX.Element { | ||
useEffect(() => { | ||
if (import.meta.env.VITE_ENABLE_POSTHOG === 'true') { | ||
posthogJs.init(import.meta.env.VITE_PUBLIC_POSTHOG_KEY, { | ||
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST, | ||
persistence: 'memory', // Cookieless tracking | ||
disable_persistence: true, // Disable persistence | ||
loaded: (ph) => { | ||
if (import.meta.env.VITE_ENV === 'development') ph.debug() | ||
}, | ||
}) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<PostHogLibraryProvider client={posthogJs}> | ||
{children} | ||
</PostHogLibraryProvider> | ||
) | ||
} |
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,4 @@ | ||
import PostHogProvider from './PostHogProvider' | ||
import PostHogPageView from './PostHogPageView' | ||
|
||
export { PostHogProvider, PostHogPageView } |
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,10 @@ | ||
interface ImportMetaEnv { | ||
readonly VITE_PUBLIC_POSTHOG_KEY: string | ||
readonly VITE_PUBLIC_POSTHOG_HOST: string | ||
readonly VITE_ENV: 'production' | 'development' | ||
readonly VITE_ENABLE_POSTHOG: 'true' | 'false' | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv | ||
} |
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.