Skip to content

Commit 939e8a0

Browse files
committed
Final attempted fix
1 parent c9fec3d commit 939e8a0

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"ntfy",
4545
"obtainium",
4646
"posthog",
47+
"prefs",
4748
"reconsent",
4849
"SIEM",
4950
"SPDY",

src/lib/stores/posthog.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
1111
* @module src/lib/stores
1212
*/
1313

14-
import { afterNavigate } from "$app/navigation";
1514
import {
1615
shouldRemindUserToReconsent,
1716
shouldTrackUser,
@@ -76,12 +75,6 @@ export async function initPostHog() {
7675
});
7776

7877
ph.capture("$pageview");
79-
80-
afterNavigate(() => {
81-
if (ph !== null && get(trackingEnabled)) {
82-
ph.capture("$pageview");
83-
}
84-
});
8578
}
8679

8780
/**

src/lib/stores/trackingStatus.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
1414

1515
import { writable } from "svelte/store";
1616

17-
export const trackingStatus = writable("unknown");
17+
/**
18+
* Writable tracking status store.
19+
* Initialized with fallback value and updated in browser context.
20+
* @type {import("svelte/store").Writable<string>}
21+
*/
22+
export const trackingStatus = writable("⏳ Checking tracking preferences...");
23+
24+
// Dynamically import browser-only logic after mount
25+
if (typeof window !== "undefined") {
26+
import("$lib/utils/trackingStatus.js").then(({ getTrackingPreferences }) => {
27+
const prefs = getTrackingPreferences();
28+
trackingStatus.set(prefs.status);
29+
});
30+
}

src/routes/+layout.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,3 @@ export function load({ url }) {
4242
meta: currentMeta, // Return the meta data (either from the route or the fallback)
4343
};
4444
}
45-
46-
// cspell:ignore posthog

src/routes/+layout.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This file is part of Network Pro.
1010
export let data;
1111
1212
import { onMount } from "svelte";
13-
import { initPostHog, showReminder } from "$lib/stores/posthog";
13+
import { afterNavigate } from "$app/navigation";
14+
import { initPostHog, showReminder, capture } from "$lib/stores/posthog";
1415
import { registerServiceWorker } from "$lib/registerServiceWorker.js";
1516
import { browser } from "$app/environment";
1617
import { shouldTrackUser } from "$lib/utils/privacy.js";
@@ -37,6 +38,11 @@ This file is part of Network Pro.
3738
registerServiceWorker();
3839
initPostHog();
3940
41+
// Register navigation tracking only on client
42+
afterNavigate(() => {
43+
capture("$pageview");
44+
});
45+
4046
if (browser) {
4147
const isDev = import.meta.env.MODE === "development";
4248

0 commit comments

Comments
 (0)