tongji.ts 515 B

123456789101112131415161718192021222324
  1. import { router } from '@/router'
  2. // 用于 router push
  3. window._hmt = window._hmt || []
  4. // HM_ID
  5. const HM_ID = import.meta.env.VITE_APP_BAIDU_CODE
  6. ;(function () {
  7. // 有值的时候,才开启
  8. if (!HM_ID)
  9. return
  10. const hm = document.createElement('script')
  11. hm.src = `https://hm.baidu.com/hm.js?${HM_ID}`
  12. const s = document.getElementsByTagName('script')[0]
  13. s.parentNode.insertBefore(hm, s)
  14. })()
  15. router.afterEach((to) => {
  16. if (!HM_ID)
  17. return
  18. _hmt.push(['_trackPageview', to.fullPath])
  19. })