Skip to content

Commit d0c7dbf

Browse files
feat(analytics): add posthog
1 parent 5aeb508 commit d0c7dbf

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"globals": "^16.0.0",
4444
"mode-watcher": "^0.5.1",
4545
"octokit": "^4.1.2",
46+
"posthog-js": "^1.235.4",
4647
"prettier": "^3.5.3",
4748
"prettier-plugin-svelte": "^3.3.3",
4849
"prettier-plugin-tailwindcss": "^0.6.11",
@@ -67,6 +68,7 @@
6768
"pnpm": {
6869
"onlyBuiltDependencies": [
6970
"@vercel/speed-insights",
71+
"core-js",
7072
"esbuild"
7173
]
7274
},

pnpm-lock.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks.client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import posthog from "posthog-js";
2+
3+
export function handleError({ error, status }) {
4+
if (status === 404) return;
5+
posthog.captureException(error);
6+
}

src/routes/+layout.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { browser } from "$app/environment";
2+
import posthog from "posthog-js";
13
import { injectSpeedInsights } from "@vercel/speed-insights/sveltekit";
24
import type { MetaTagsProps } from "svelte-meta-tags";
35

@@ -6,6 +8,14 @@ injectSpeedInsights();
68
const siteName = "Svelte Changelog";
79

810
export function load({ url, data }) {
11+
if (browser) {
12+
posthog.init("phc_mikNRIemcxWqXq0a4Pj9WPIWpbl815sf8VoMLJlFNYT", {
13+
api_host: `${url.origin}/ingest`,
14+
ui_host: "https://eu.posthog.com",
15+
person_profiles: "always"
16+
});
17+
}
18+
919
return {
1020
...data,
1121
siteName,

svelte.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const config = {
66
preprocess: [vitePreprocess({})],
77

88
kit: {
9-
adapter: adapter()
9+
adapter: adapter(),
10+
paths: {
11+
relative: false
12+
}
1013
}
1114
};
1215

vercel.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"rewrites": [
3+
{
4+
"source": "/ingest/static/:path(.*)",
5+
"destination": "https://eu-assets.i.posthog.com/static/:path*"
6+
},
7+
{
8+
"source": "/ingest/:path(.*)",
9+
"destination": "https://eu.i.posthog.com/:path*"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)