diff --git a/docs-site/.vitepress/config.ts b/docs-site/.vitepress/config.ts index 071c680e..70488069 100644 --- a/docs-site/.vitepress/config.ts +++ b/docs-site/.vitepress/config.ts @@ -1,4 +1,11 @@ const DOCS_HOSTNAME = 'https://docs.subminer.moe'; +const PLAUSIBLE_PROXY_HOSTNAME = 'https://worker.subminer.moe'; +const PLAUSIBLE_SITE_SCRIPT_PATH = '/js/pa-h28Pn9ppgTJRmiSJlyPT6.js'; +const PLAUSIBLE_ENDPOINT = `${PLAUSIBLE_PROXY_HOSTNAME}/api/event`; +const PLAUSIBLE_INIT_SCRIPT = [ + 'window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};', + `plausible.init({ endpoint: '${PLAUSIBLE_ENDPOINT}' });`, +].join('\n'); function pageToCanonicalHref(page: string): string | null { if (page === '404.md') return null; @@ -15,6 +22,15 @@ export default { description: 'SubMiner: an MPV immersion-mining overlay with Yomitan and AnkiConnect integration.', head: [ + ['link', { rel: 'preconnect', href: PLAUSIBLE_PROXY_HOSTNAME }], + [ + 'script', + { + async: '', + src: `${PLAUSIBLE_PROXY_HOSTNAME}${PLAUSIBLE_SITE_SCRIPT_PATH}`, + }, + ], + ['script', {}, PLAUSIBLE_INIT_SCRIPT], ['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }], [ 'link', diff --git a/docs-site/.vitepress/theme/index.ts b/docs-site/.vitepress/theme/index.ts index bfd61856..36eb4ae0 100644 --- a/docs-site/.vitepress/theme/index.ts +++ b/docs-site/.vitepress/theme/index.ts @@ -7,32 +7,7 @@ import './mermaid-modal.css'; import TuiLayout from './TuiLayout.vue'; let mermaidLoader: Promise | null = null; -let plausibleTrackerInitialized = false; const MERMAID_MODAL_ID = 'mermaid-diagram-modal'; -const PLAUSIBLE_DOMAIN = 'subminer.moe'; -const PLAUSIBLE_ENABLED_HOSTNAMES = new Set(['docs.subminer.moe']); -const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture'; - -async function initPlausibleTracker() { - if (typeof window === 'undefined' || plausibleTrackerInitialized) { - return; - } - - if (!PLAUSIBLE_ENABLED_HOSTNAMES.has(window.location.hostname)) { - return; - } - - const { init } = await import('@plausible-analytics/tracker'); - init({ - domain: PLAUSIBLE_DOMAIN, - endpoint: PLAUSIBLE_ENDPOINT, - outboundLinks: true, - fileDownloads: true, - formSubmissions: true, - captureOnLocalhost: false, - }); - plausibleTrackerInitialized = true; -} function closeMermaidModal() { if (typeof document === 'undefined') { @@ -222,9 +197,6 @@ export default { }; onMounted(() => { - initPlausibleTracker().catch((error) => { - console.error('Failed to initialize Plausible tracker:', error); - }); render(); }); watch(() => route.path, render); diff --git a/docs-site/bun.lock b/docs-site/bun.lock index ae6cd304..a3f3356c 100644 --- a/docs-site/bun.lock +++ b/docs-site/bun.lock @@ -8,7 +8,6 @@ "@catppuccin/vitepress": "^0.1.2", "@fontsource/jetbrains-mono": "^5.2.8", "@fontsource/manrope": "^5.2.8", - "@plausible-analytics/tracker": "^0.4.4", "mermaid": "^11.12.3", }, "devDependencies": { @@ -143,8 +142,6 @@ "@mermaid-js/parser": ["@mermaid-js/parser@1.0.0", "", { "dependencies": { "langium": "^4.0.0" } }, "sha512-vvK0Hi/VWndxoh03Mmz6wa1KDriSPjS2XMZL/1l19HFwygiObEEoEwSDxOqyLzzAI6J2PU3261JjTMTO7x+BPw=="], - "@plausible-analytics/tracker": ["@plausible-analytics/tracker@0.4.4", "", {}, "sha512-fz0NOYUEYXtg1TBaPEEvtcBq3FfmLFuTe1VZw4M8sTWX129br5dguu3M15+plOQnc181ShYe67RfwhKgK89VnA=="], - "@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.59.0", "", { "os": "android", "cpu": "arm" }, "sha512-upnNBkA6ZH2VKGcBj9Fyl9IGNPULcjXRlg0LLeaioQWueH30p6IXtJEbKAgvyv+mJaMxSm1l6xwDXYjpEMiLMg=="], "@rollup/rollup-android-arm64": ["@rollup/rollup-android-arm64@4.59.0", "", { "os": "android", "cpu": "arm64" }, "sha512-hZ+Zxj3SySm4A/DylsDKZAeVg0mvi++0PYVceVyX7hemkw7OreKdCvW2oQ3T1FMZvCaQXqOTHb8qmBShoqk69Q=="], diff --git a/docs-site/package.json b/docs-site/package.json index 033aec36..b0a5947c 100644 --- a/docs-site/package.json +++ b/docs-site/package.json @@ -14,7 +14,6 @@ "@catppuccin/vitepress": "^0.1.2", "@fontsource/jetbrains-mono": "^5.2.8", "@fontsource/manrope": "^5.2.8", - "@plausible-analytics/tracker": "^0.4.4", "mermaid": "^11.12.3" }, "devDependencies": { diff --git a/docs-site/plausible.test.ts b/docs-site/plausible.test.ts index c1407588..2d3582da 100644 --- a/docs-site/plausible.test.ts +++ b/docs-site/plausible.test.ts @@ -3,25 +3,34 @@ import { readFileSync } from 'node:fs'; const docsConfigPath = new URL('./.vitepress/config.ts', import.meta.url); const docsThemePath = new URL('./.vitepress/theme/index.ts', import.meta.url); +const docsPackagePath = new URL('./package.json', import.meta.url); const docsConfigContents = readFileSync(docsConfigPath, 'utf8'); const docsThemeContents = readFileSync(docsThemePath, 'utf8'); +const docsPackageContents = readFileSync(docsPackagePath, 'utf8'); -test('docs site keeps docs hostname while sending plausible events to subminer.moe via worker.subminer.moe capture endpoint', () => { +test('docs site loads the docs.subminer.moe Plausible script through the analytics proxy', () => { expect(docsConfigContents).toContain("const DOCS_HOSTNAME = 'https://docs.subminer.moe'"); - expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME'); - expect(docsThemeContents).toContain("const PLAUSIBLE_DOMAIN = 'subminer.moe'"); - expect(docsThemeContents).toContain('const PLAUSIBLE_ENABLED_HOSTNAMES = new Set(['); - expect(docsThemeContents).toContain("'docs.subminer.moe'"); - expect(docsThemeContents).toContain( - "const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture'", + expect(docsConfigContents).toContain( + "const PLAUSIBLE_PROXY_HOSTNAME = 'https://worker.subminer.moe'", ); - expect(docsThemeContents).toContain('@plausible-analytics/tracker'); - expect(docsThemeContents).toContain('const { init } = await import'); - expect(docsThemeContents).toContain('!PLAUSIBLE_ENABLED_HOSTNAMES.has(window.location.hostname)'); - expect(docsThemeContents).toContain('domain: PLAUSIBLE_DOMAIN'); - expect(docsThemeContents).toContain('endpoint: PLAUSIBLE_ENDPOINT'); - expect(docsThemeContents).toContain('outboundLinks: true'); - expect(docsThemeContents).toContain('fileDownloads: true'); - expect(docsThemeContents).toContain('formSubmissions: true'); - expect(docsThemeContents).toContain('captureOnLocalhost: false'); + expect(docsConfigContents).toContain( + "const PLAUSIBLE_SITE_SCRIPT_PATH = '/js/pa-h28Pn9ppgTJRmiSJlyPT6.js'", + ); + expect(docsConfigContents).toContain( + 'const PLAUSIBLE_ENDPOINT = `${PLAUSIBLE_PROXY_HOSTNAME}/api/event`', + ); + expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME'); + expect(docsConfigContents).toContain("rel: 'preconnect'"); + expect(docsConfigContents).toContain('href: PLAUSIBLE_PROXY_HOSTNAME'); + expect(docsConfigContents).toContain("async: ''"); + expect(docsConfigContents).toContain( + 'src: `${PLAUSIBLE_PROXY_HOSTNAME}${PLAUSIBLE_SITE_SCRIPT_PATH}`', + ); + expect(docsConfigContents).toContain('plausible.init({ endpoint:'); + expect(docsConfigContents).toContain('PLAUSIBLE_ENDPOINT'); + expect(docsConfigContents).not.toContain("'data-domain'"); + expect(docsConfigContents).not.toContain("'data-api'"); + expect(docsThemeContents).not.toContain('@plausible-analytics/tracker'); + expect(docsThemeContents).not.toContain('initPlausibleTracker'); + expect(docsPackageContents).not.toContain('@plausible-analytics/tracker'); });