Skip to content

Commit

Permalink
setup posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanJPNM committed Dec 6, 2023
1 parent 30ef6cc commit e7b27a4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions website/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_POSTHOG_TOKEN=your_posthog_token
3 changes: 3 additions & 0 deletions website/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ const config: UserConfig = {
],
],
vite: {
// the root path is website/docs/, so this will make
// vite look for the env file in website/
envDir: "../",
define: {
"process.env": {},
},
Expand Down
23 changes: 22 additions & 1 deletion website/docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,25 @@
import DefaultTheme from "vitepress/theme";

import "./vars.css";
export default DefaultTheme;
import type { Theme } from "vitepress";
import posthog from "posthog-js";

const theme: Theme = {
extends: DefaultTheme,
enhanceApp({ router }) {
if (import.meta.env.SSR) return;
const token = import.meta.env.VITE_POSTHOG_TOKEN;
if (!token) return;

posthog.init(token, {
api_host: "https://app.posthog.com",
autocapture: false,
});

router.onAfterRouteChanged = () => {
posthog.capture("$pageview");
};
},
};

export default theme;
4 changes: 4 additions & 0 deletions website/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ declare module "*!raw" {
const lib: [string, string][];
export default lib;
}

interface ImportMetaEnv {
VITE_POSTHOG_TOKEN?: string;
}

0 comments on commit e7b27a4

Please sign in to comment.