fix(analytics): streamline posthog script loading and event capturing

This commit is contained in:
Aswanth 2025-05-11 18:14:43 +05:30
parent e98d97a271
commit b0c8829b52

View File

@ -159,14 +159,10 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
posthog.init('${cfg.analytics.apiKey}', {
api_host: '${cfg.analytics.host ?? "https://app.posthog.com"}',
capture_pageview: false,
})\`
posthogScript.onload = () => {
});
document.addEventListener('nav', () => {
posthog.capture('$pageview', { path: location.pathname });
document.addEventListener('nav', () => {
posthog.capture('$pageview', { path: location.pathname });
});
};
})\`
document.head.appendChild(posthogScript);
`)