Skip to content

添加 Google Analytics 统计代码

本处默认你已注册 Google Analytics账号。

注册网址:https://analytics.google.com/

添加 script

.vitepress/config.mts 中添加

ts
export default defineConfig({
  head: [
    //Google Analytics
    [
      'script',
      { async: '', src: 'https://www.googletagmanager.com/gtag/js?id=YOURID' } 
    ],
    [
      'script',
      {},
      `window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'YOURID');` 
    ],
  ],
})

其中:需要置换成你的个人信息的是 YOURID

Powered by VitePress