mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
refactor: export onRouteDidUpdate for fathom plugin
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
SCRIPT_URL,
|
||||
} from '@generated/docusaurus-fathom/default/options'
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'
|
||||
import { ClientModule } from '@docusaurus/types/src/clientModule'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -10,8 +11,6 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
let onRouteDidUpdate
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
;(function (f: any, a: any, t: string, h: string) {
|
||||
a[h] =
|
||||
@@ -30,14 +29,13 @@ if (ExecutionEnvironment.canUseDOM) {
|
||||
const { fathom } = window as any
|
||||
fathom('set', 'siteId', SITE_ID)
|
||||
fathom('trackPageview')
|
||||
|
||||
function onRouteDidUpdateFnc({ location, previousLocation }) {
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
fathom('trackPageview')
|
||||
}
|
||||
}
|
||||
|
||||
onRouteDidUpdate = onRouteDidUpdateFnc
|
||||
}
|
||||
|
||||
export { onRouteDidUpdate }
|
||||
export const onRouteDidUpdate: ClientModule['onRouteDidUpdate'] = ({
|
||||
location,
|
||||
previousLocation,
|
||||
}) => {
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
window.fathom('trackPageview')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user