mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
feat: add valid hostnames to dcosaurus-fathom
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
SITE_ID,
|
||||
SCRIPT_URL,
|
||||
HOSTNAMES,
|
||||
} from '@generated/docusaurus-fathom/default/options'
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'
|
||||
import { ClientModule } from '@docusaurus/types/src/clientModule'
|
||||
@@ -35,6 +36,10 @@ 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) {
|
||||
window.fathom('trackPageview')
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type PluginOptions = {
|
||||
siteId: string
|
||||
scriptUrl: string
|
||||
disabled?: boolean
|
||||
hostnames?: string[]
|
||||
}
|
||||
|
||||
@@ -7,20 +7,21 @@ export default function fathomPlugin(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<undefined> {
|
||||
const { siteId, scriptUrl, disabled = false } = options
|
||||
const { siteId, scriptUrl, hostnames = [] } = options
|
||||
|
||||
const dir = path.join(context.generatedFilesDir, 'docusaurus-fathom/default')
|
||||
fs.ensureDirSync(dir)
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'options.ts'),
|
||||
`export const SITE_ID = "${siteId}"\nexport const SCRIPT_URL = "${scriptUrl}"`,
|
||||
`export const SITE_ID = "${siteId}"\nexport const SCRIPT_URL = "${scriptUrl}"\nexport const HOSTNAMES = ${JSON.stringify(
|
||||
hostnames,
|
||||
)}`,
|
||||
)
|
||||
|
||||
return {
|
||||
name: 'docusaurus-fathom',
|
||||
getClientModules: () =>
|
||||
disabled ? [] : [path.resolve(__dirname, './client/index.js')],
|
||||
getClientModules: () => [path.resolve(__dirname, './client/index.js')],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ const config = {
|
||||
siteId: 'TEST',
|
||||
scriptUrl: 'https://fathom.status.im/tracker.js',
|
||||
disabled: true,
|
||||
hostnames: ['waku.org'],
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user