谷歌分析
注意
Teek 主题已支持谷歌分析,详情查看 站点统计
账号注册
访问: 点击跳转 (opens new window)没有账号注册一个账号。
根据提示创建 Analytics 账号,添加自己的网站信息,之后会获取一个统计代码:
安装插件
提示
推荐使用 pnpm 安装
,我在子项目的,所以需要切换到子项目的Demo\docs-base
目录下安装
sh
cd Demo\docs-base
pnpm add -D vitepress-plugin-google-analytics
sh
yarn add -D vitepress-plugin-google-analytics
sh
npm install vitepress-plugin-google-analytics
sh
bun add -D vitepress-plugin-google-analytics
配置插件
- 在
Demo\docs-base\.vitepress\theme\index.ts
中进行配置
ts
import googleAnalytics from "vitepress-plugin-google-analytics"; // 引入谷歌统计插件
export default {
extends: Teek,
DefaultTheme,
Layout: defineComponent({
return () =>
h(Teek.Layout, null, {
"layout-top": () => h(notice), // 使用layout-top插槽
googleAnalytics: () =>
h(googleAnalytics, {
id: "G-******", //跟踪ID,在analytics.google.com注册即可
}), // 使用googleAnalytics插槽
"Teek-notice-content": () => h(NoticeContent),
});
},
}),
};