diff --git a/packages/docusaurus-fathom/src/client/index.ts b/packages/docusaurus-fathom/src/client/index.ts index d5ca5c2..24e3f16 100644 --- a/packages/docusaurus-fathom/src/client/index.ts +++ b/packages/docusaurus-fathom/src/client/index.ts @@ -12,7 +12,13 @@ declare global { } } -if (ExecutionEnvironment.canUseDOM) { +const main = () => { + if ( + HOSTNAMES.length > 0 + ? !HOSTNAMES.includes(window.location.hostname) + : window.location.hostname === 'localhost' + ) + return ;(function (f: any, a: any, t: string, h: string) { a[h] = a[h] || @@ -32,15 +38,15 @@ if (ExecutionEnvironment.canUseDOM) { fathom('trackPageview') } +if (ExecutionEnvironment.canUseDOM) { + main() +} + export const onRouteDidUpdate: ClientModule['onRouteDidUpdate'] = ({ location, previousLocation, }) => { - if (HOSTNAMES.length > 0 && !HOSTNAMES.includes(window.location.hostname)) - return - if (window.location.hostname === 'localhost') return - - if (location.pathname !== previousLocation?.pathname) { + if (!!window.fathom && location.pathname !== previousLocation?.pathname) { window.fathom('trackPageview') } } diff --git a/packages/docusaurus-playground/docusaurus.config.js b/packages/docusaurus-playground/docusaurus.config.js index e90b187..d92de82 100644 --- a/packages/docusaurus-playground/docusaurus.config.js +++ b/packages/docusaurus-playground/docusaurus.config.js @@ -75,7 +75,7 @@ const config = { siteId: 'TEST', scriptUrl: 'https://fathom.status.im/tracker.js', disabled: true, - hostnames: ['waku.org'], + hostnames: ['localhost', 'waku.org'], }, ], ],