Skip to content

Commit 19f75eb

Browse files
committed
better logging
1 parent e88960d commit 19f75eb

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/routes/+layout.svelte

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
<script lang="ts">
22
import { browser } from "$app/environment";
3+
import { onMount } from "svelte";
34
45
let { children } = $props();
56
67
let ga4Codes = {
78
"ccported.click": "G-ER9VZ5QL8K",
89
"ccported.github.io": "G-ER9VZ5QL8K",
9-
"localhost": null,
10+
localhost: null,
1011
};
1112
let defaultGA4Code = "G-DJDL65P9Y4";
1213
1314
let idToUse = $state(defaultGA4Code);
1415
let useGA4 = $state(false);
15-
if (browser) {
16-
let hostname = window.location.hostname;
17-
console.log("[R][LAYOUT][BASE] Hostname:", hostname);
18-
if (hostname in ga4Codes) {
19-
const code = ga4Codes[hostname as keyof typeof ga4Codes];
20-
if (code) {
21-
idToUse = code;
22-
useGA4 = true;
16+
17+
onMount(() => {
18+
if (browser) {
19+
let hostname = window.location.hostname;
20+
console.log("[R][LAYOUT][BASE] Hostname:", hostname);
21+
if (hostname in ga4Codes) {
22+
const code = ga4Codes[hostname as keyof typeof ga4Codes];
23+
console.log("[R][LAYOUT][BASE] GA4 Code:", code);
24+
if (code) {
25+
idToUse = code;
26+
useGA4 = true;
27+
} else {
28+
useGA4 = false;
29+
}
2330
} else {
24-
useGA4 = false;
31+
idToUse = defaultGA4Code;
32+
useGA4 = true;
2533
}
26-
} else{
27-
idToUse = defaultGA4Code;
28-
useGA4 = true;
2934
}
30-
}
35+
console.log("[R][LAYOUT][BASE] Using GA4:", useGA4, "with ID:", idToUse);
36+
});
3137
</script>
3238

3339
<svelte:head>
34-
<meta name = "use-ga4" content = {String(useGA4)} />
40+
<meta name="use-ga4" content={String(useGA4)} />
3541
{#if useGA4}
3642
<script
3743
async

0 commit comments

Comments
 (0)