Skip to content

Commit 18961e7

Browse files
authored
engine: captures 404 page events (#859)
1 parent 533c5aa commit 18961e7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docs/.vuepress/client.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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";
87
import UserFeedback from './components/TocWithFeedback';
8+
import {usePostHog} from "./lib/usePosthog";
99

1010
declare const __VERSIONS__: { latest: string, selected: string, all: string[] }
1111

@@ -132,15 +132,34 @@ export default defineClientConfig({
132132
});
133133
}, 1000);
134134
}
135+
136+
// Check for 404 page after navigation completes
137+
setTimeout(() => {
138+
// Check for the specific elements with classes error-code and error-hint
139+
const errorCodeElement = document.querySelector('p.error-code');
140+
const errorHintElement = document.querySelector('p.error-hint');
141+
142+
// If both elements exist, we're on a 404 page
143+
if (errorCodeElement && errorHintElement) {
144+
// Capture the 404 event in PostHog
145+
if (window && window.posthog) {
146+
window.posthog.capture("page_not_found", {
147+
url: window.location.href,
148+
referrer: document.referrer,
149+
path: to.path,
150+
attemptedPath: to.path.replace('.html', '')
151+
});
152+
}
153+
}
154+
}, 50);
135155
});
136156
router.beforeEach((to, from) => leave(to, from));
137157
},
138158
setup() {
139159
onMounted(() => {
140160
const route = useRoute();
141-
if (route.path !== "/") return;
142-
// console.log(route.meta._pageChunk.data.frontmatter.head);
161+
if (route.path !== "/");
143162
});
144163

145164
},
146-
} satisfies ClientConfig);
165+
} satisfies ClientConfig);

0 commit comments

Comments
 (0)