Skip to content

Commit 28b2c48

Browse files
wip: optionally load fathom when env vars are set (#281)
1 parent f59d758 commit 28b2c48

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

clients/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@sentry/browser": "^7.101.0",
6161
"@sentry/vite-plugin": "^2.14.0",
6262
"@solid-primitives/map": "^0.4.9",
63+
"@solid-primitives/script-loader": "^2.1.2",
6364
"@solidjs/router": "^0.12.0",
6465
"@tanstack/solid-virtual": "^3.0.4",
6566
"clsx": "^2.1.0",

clients/web/pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/web/src/lib/load-fathom.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createScriptLoader } from "@solid-primitives/script-loader";
2+
3+
export function loadFathom() {
4+
const fathomUrl = import.meta.env.VITE_FATHOM_URL;
5+
const fathomId = import.meta.env.VITE_FATHOM_ID;
6+
if (fathomUrl && fathomId)
7+
createScriptLoader({ src: fathomUrl, "data-site": fathomId, defer: true });
8+
}

clients/web/src/render-client.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import "~/css/global.css";
33
import Entry from "./entry";
44
import * as Sentry from "@sentry/browser";
55
import { DEV } from "solid-js";
6+
import { loadFathom } from "./lib/load-fathom";
67

78
if (!DEV) {
89
Sentry.init({
@@ -11,6 +12,7 @@ if (!DEV) {
1112
integrations: (def) => [...def, Sentry.browserTracingIntegration()],
1213
tracesSampleRate: 0.1,
1314
});
15+
loadFathom();
1416
}
1517

1618
const app = document.getElementById("app");

clients/web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"jsx": "preserve",
2727
"jsxImportSource": "solid-js",
2828

29-
"types": ["vitest/globals"]
29+
"types": ["vitest/globals", "vite/client"]
3030
},
3131
"include": ["src", "tests"]
3232
}

0 commit comments

Comments
 (0)