Skip to content

Commit 6d49d97

Browse files
authored
fix(analytics): streamline posthog script loading and event capturing (#1974)
1 parent c9741d0 commit 6d49d97

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

quartz/plugins/emitters/componentResources.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,10 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
159159
posthog.init('${cfg.analytics.apiKey}', {
160160
api_host: '${cfg.analytics.host ?? "https://app.posthog.com"}',
161161
capture_pageview: false,
162-
})\`
163-
posthogScript.onload = () => {
162+
});
163+
document.addEventListener('nav', () => {
164164
posthog.capture('$pageview', { path: location.pathname });
165-
166-
document.addEventListener('nav', () => {
167-
posthog.capture('$pageview', { path: location.pathname });
168-
});
169-
};
165+
})\`
170166
171167
document.head.appendChild(posthogScript);
172168
`)

0 commit comments

Comments
 (0)