refactor: export onRouteDidUpdate for fathom plugin

This commit is contained in:
jinhojang6
2023-06-28 09:38:20 +09:00
parent 02b3cad4fd
commit 86039478d1
+9 -11
View File
@@ -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')
}
}