mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
Merge pull request #111 from acid-info/fathom
Add disable prop to docusaurus-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'
|
||||
@@ -11,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] ||
|
||||
@@ -31,11 +38,15 @@ if (ExecutionEnvironment.canUseDOM) {
|
||||
fathom('trackPageview')
|
||||
}
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
main()
|
||||
}
|
||||
|
||||
export const onRouteDidUpdate: ClientModule['onRouteDidUpdate'] = ({
|
||||
location,
|
||||
previousLocation,
|
||||
}) => {
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
if (!!window.fathom && location.pathname !== previousLocation?.pathname) {
|
||||
window.fathom('trackPageview')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type PluginOptions = {
|
||||
siteId: string
|
||||
scriptUrl: string
|
||||
hostnames?: string[]
|
||||
}
|
||||
|
||||
@@ -7,13 +7,16 @@ export default function fathomPlugin(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<undefined> {
|
||||
const { siteId, scriptUrl } = 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 {
|
||||
|
||||
@@ -69,6 +69,15 @@ const config = {
|
||||
authorsMapPath: 'authors.yml',
|
||||
}),
|
||||
],
|
||||
[
|
||||
'@acid-info/docusaurus-fathom',
|
||||
{
|
||||
siteId: 'TEST',
|
||||
scriptUrl: 'https://fathom.status.im/tracker.js',
|
||||
disabled: true,
|
||||
hostnames: ['localhost', 'waku.org'],
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
themeConfig:
|
||||
|
||||
Reference in New Issue
Block a user