Mkdocs增加百度统计
获取统计代码
百度统计站点申请参考: 申请百度统计站点帮助 ,获取后的代码类似如下:
1<script>
2var _hmt = _hmt || [];
3(function() {
4 var hm = document.createElement("script");
5 hm.src = "https://hm.baidu.com/hm.js?<站点ID>";
6 var s = document.getElementsByTagName("script")[0];
7 s.parentNode.insertBefore(hm, s);
8})();
9</script>
将该代码保存到mkdocs新建的项目docs/js/baidu-tongji.js文件中。
mkdocs.yaml配置支持
mkdocs.yml添加百度统计配置,内容如下:
1google_analytics:[ UA-xxxxx-xx ,mkdocs.org']
2copyright: Copyright @ 2022-2023
3
4theme:
5 name: material
6 language: 'zh'
7
8extra_javascript:
9 - 'js/baidu-tongji.js'
注意看上面的extra_javascript部分。
验证
配置完成后,就可以通过mkdocs serve
启动站点,并通过分析页面,查看是否有https://hm.baidu.com/hm.js
对应的请求。mkdocs安装百度统计成功后,一般20分钟之后,就可以在百度统计网站看到统计信息了。
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/2023/10/mkdocs-baidutj.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.