diff --git a/package-lock.json b/package-lock.json index dd88ff7da..ecf6a2a75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,6 @@ "mdast-util-to-hast": "^13.0.2", "mdast-util-to-string": "^4.0.0", "micromorph": "^0.4.5", - "plausible-tracker": "^0.3.8", "preact": "^10.19.3", "preact-render-to-string": "^6.3.1", "pretty-bytes": "^6.1.1", @@ -4451,14 +4450,6 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/plausible-tracker": { - "version": "0.3.8", - "resolved": "https://registry.npmjs.org/plausible-tracker/-/plausible-tracker-0.3.8.tgz", - "integrity": "sha512-lmOWYQ7s9KOUJ1R+YTOR3HrjdbxIS2Z4de0P/Jx2dQPteznJl2eX3tXxKClpvbfyGP59B5bbhW8ftN59HbbFSg==", - "engines": { - "node": ">=10" - } - }, "node_modules/preact": { "version": "10.19.3", "resolved": "https://registry.npmjs.org/preact/-/preact-10.19.3.tgz", diff --git a/package.json b/package.json index 70df83305..b99471d76 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "mdast-util-to-hast": "^13.0.2", "mdast-util-to-string": "^4.0.0", "micromorph": "^0.4.5", - "plausible-tracker": "^0.3.8", "preact": "^10.19.3", "preact-render-to-string": "^6.3.1", "pretty-bytes": "^6.1.1", diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 8371b5e2b..7f0f206e1 100644 --- a/quartz/cfg.ts +++ b/quartz/cfg.ts @@ -7,6 +7,7 @@ export type Analytics = | null | { provider: "plausible" + host?: string } | { provider: "google" diff --git a/quartz/components/scripts/plausible.inline.ts b/quartz/components/scripts/plausible.inline.ts deleted file mode 100644 index 704f5d5fe..000000000 --- a/quartz/components/scripts/plausible.inline.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Plausible from "plausible-tracker" -const { trackPageview } = Plausible() -document.addEventListener("nav", () => trackPageview()) diff --git a/quartz/plugins/emitters/componentResources.ts b/quartz/plugins/emitters/componentResources.ts index b51d09191..e8a81bc0b 100644 --- a/quartz/plugins/emitters/componentResources.ts +++ b/quartz/plugins/emitters/componentResources.ts @@ -4,8 +4,6 @@ import { QuartzEmitterPlugin } from "../types" // @ts-ignore import spaRouterScript from "../../components/scripts/spa.inline" // @ts-ignore -import plausibleScript from "../../components/scripts/plausible.inline" -// @ts-ignore import popoverScript from "../../components/scripts/popover.inline" import styles from "../../styles/custom.scss" import popoverStyle from "../../components/styles/popover.scss" @@ -103,7 +101,20 @@ function addGlobalPageResources( }); });`) } else if (cfg.analytics?.provider === "plausible") { - componentResources.afterDOMLoaded.push(plausibleScript) + const plausibleHost = cfg.analytics.host ?? "https://plausible.io" + componentResources.afterDOMLoaded.push(` + const plausibleScript = document.createElement("script") + plausibleScript.src = "${plausibleHost}/js/script.manual.js" + plausibleScript.setAttribute("data-domain", location.hostname) + plausibleScript.defer = true + document.head.appendChild(plausibleScript) + + window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) } + + document.addEventListener("nav", () => { + plausible("pageview") + }) + `) } else if (cfg.analytics?.provider === "umami") { componentResources.afterDOMLoaded.push(` const umamiScript = document.createElement("script")