Skip to content

Commit f7ca0ad

Browse files
Use Posthog directly (#830)
1 parent 85631e1 commit f7ca0ad

File tree

5 files changed

+543
-823
lines changed

5 files changed

+543
-823
lines changed

docs/.vuepress/client.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {onMounted} from "vue";
44
import type {RouteLocationNormalized, Router} from "vue-router";
55
import CloudBanner from "./components/CloudBanner.vue";
66
import KapaWidget from './components/KapaWidget.vue';
7+
import {usePostHog} from "./lib/usePosthog";
78
import UserFeedback from './components/TocWithFeedback';
89

910
declare const __VERSIONS__: { latest: string, selected: string, all: string[] }
@@ -49,20 +50,15 @@ const reload = () => {
4950
}
5051

5152
const leave = (to: RouteLocationNormalized, from: RouteLocationNormalized) => {
52-
if (from.path !== to.path && typeof window !== "undefined" && window.analytics !== undefined) {
53-
// const sessionId = (typeof window.posthog !== "undefined") ? window.posthog.getSessionId() : null;
54-
window.analytics.track({
55-
event: "$pageleave",
56-
properties: {
57-
$host: window.location.hostname,
58-
// $session_id: sessionId
59-
}
60-
});
53+
if (from.path !== to.path && typeof window !== "undefined") {
54+
posthog.capture('$pageleave');
6155
}
6256
}
6357

58+
const { posthog } = usePostHog();
59+
6460
export default defineClientConfig({
65-
enhance({app, router, siteData}) {
61+
enhance({app, router, _}) {
6662
app.component("CloudBanner", CloudBanner);
6763
app.component("KapaWidget", KapaWidget);
6864
app.component("UserFeedback", UserFeedback);
@@ -118,18 +114,20 @@ export default defineClientConfig({
118114
router.afterEach((to, from) => {
119115
if (typeof window === "undefined" || to.path === from.path || removeHtml(to.path) === removeHtml(from.path)) return;
120116
const esData = findEsMeta(to);
117+
posthog.capture('$pageview', {
118+
site: "docs",
119+
version: esData?.version,
120+
category: esData?.category,
121+
});
121122
const a = window.analytics;
122123
if (a) {
123-
const sessionId = (typeof window.posthog !== "undefined") ? window.posthog.getSessionId() : null;
124124
setTimeout(() => {
125125
a.page({
126126
site: "docs",
127127
url: window.location.origin + to.fullPath,
128128
title: to.meta.t,
129129
version: esData?.version,
130130
category: esData?.category,
131-
$host: window.location.hostname,
132-
$session_id: sessionId
133131
});
134132
}, 1000);
135133
}

docs/.vuepress/lib/usePosthog.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import posthog from 'posthog-js';
2+
3+
export function usePostHog() {
4+
try {
5+
posthog.init('phc_DeHBgHGersY4LmDlADnPrsCPOAmMO7QFOH8f4DVEVmD', {
6+
api_host: 'https://phog.kurrent.io'
7+
});
8+
} catch (e) {
9+
}
10+
11+
return {
12+
posthog
13+
}
14+
}

docs/.vuepress/public/js/snippet.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,4 @@
8383
analytics._writeKey = "REDACTED";
8484
analytics.SNIPPET_VERSION = "5.2.1";
8585
analytics.load("REDACTED");
86-
87-
analytics.ready(() => {
88-
window.posthog.init("phc_DeHBgHGersY4LmDlADnPrsCPOAmMO7QFOH8f4DVEVmD", {
89-
api_host: 'https://phog.kurrent.io',
90-
segment: analytics,
91-
capture_pageview: false,
92-
loaded: (posthog) => {
93-
analytics.page({
94-
site: "docs",
95-
title: "Home",
96-
$host: window.location.hostname,
97-
// $session_id: posthog.getSessionId(),
98-
})
99-
}
100-
});
101-
})
10286
})();

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@mdit/plugin-dl": "^0.13.0",
1313
"@types/fs-extra": "^11.0.4",
1414
"@types/markdown-it": "^14.1.1",
15-
"@vuepress/plugin-watermark": "2.0.0-rc.27",
1615
"degit": "2.8.4",
1716
"del": "5.1.0",
1817
"dotenv": "10.0.0",
@@ -22,7 +21,7 @@
2221
"fs-extra": "^11.2.0",
2322
"markdown-it": "^14.1.0",
2423
"prettier": "2.3.2",
25-
"sass": "^1.84.0",
24+
"sass": "^1.86.0",
2625
"shx": "0.3.3",
2726
"stylus": "^0.56.0",
2827
"ts-pattern": "^5.4.0",
@@ -36,24 +35,25 @@
3635
"@segment/analytics-next": "^1.74.0",
3736
"@vuepress/bundler-vite": "2.0.0-rc.20",
3837
"@vuepress/helper": "^2.0.0-rc.80",
39-
"@vuepress/plugin-docsearch": "^2.0.0-rc.76",
40-
"@vuepress/plugin-google-analytics": "^2.0.0-rc.66",
41-
"@vuepress/plugin-notice": "^2.0.0-rc.74",
42-
"@vuepress/plugin-seo": "^2.0.0-rc.74",
43-
"@vuepress/plugin-sitemap": "^2.0.0-rc.74",
38+
"@vuepress/plugin-docsearch": "^2.0.0-rc.86",
39+
"@vuepress/plugin-notice": "^2.0.0-rc.86",
40+
"@vuepress/plugin-seo": "^2.0.0-rc.86",
41+
"@vuepress/plugin-sitemap": "^2.0.0-rc.86",
42+
"@vuepress/plugin-watermark": "^2.0.0-rc.86",
4443
"@vueuse/core": "^12.8.2",
4544
"bowser": "^2.11.0",
4645
"dashjs": "^4.7.4",
4746
"hls.js": "^1.5.14",
4847
"iconify-icon": "^2.1.0",
4948
"mermaid": "^11.4.0",
50-
"sass-loader": "^15.0.0",
49+
"posthog-js": "^1.232.7",
50+
"sass-loader": "^16.0.5",
5151
"uglify-js": "^3.19.3",
52-
"vue": "^3.4.30",
52+
"vue": "^3.5.13",
5353
"vue-router": "^4.4.0",
5454
"vuepress": "2.0.0-rc.20",
55-
"vuepress-plugin-md-enhance": "^2.0.0-rc.71",
56-
"vuepress-theme-hope": "^2.0.0-rc.74"
55+
"vuepress-plugin-md-enhance": "^2.0.0-rc.75",
56+
"vuepress-theme-hope": "^2.0.0-rc.75"
5757
},
5858
"scripts": {
5959
"preinstall": "npx only-allow pnpm",

0 commit comments

Comments
 (0)