当前位置:网站首页>Nuxt 项目中如何引入百度统计?
Nuxt 项目中如何引入百度统计?
2022-06-09 15:14:00 【子舒】
在部署一个网站之后,我们最关心的事情无异于是访问量,以及对它的分析。国内的百度统计是一个不错的选择,基本的功能都是免费的。
只需要在head中引入一串 javascript 代码即可。
<!-- <script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?xxxxxxxxxxxxxxxxxxx";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script> -->上面是百度提供的统计代码,需要放在 <head></head>中。
但是在nuxt中,没有传统的 <head></head> 。所以要对他进行一些处理。
1. 首先在根目录下 /plugins 新建一个文件 baidu.js
// /plugins/baidu.js
export default ({app: {router}, store}) => {
/* 每次路由变更时进行pv统计 */
router.afterEach((to, from) => {
/* 告诉增加一个PV */
try {
window._hmt = window._hmt || []
window._hmt.push(['_trackPageview', to.fullPath])
} catch (e) {
}
})
}2. 配置 nuxt.config.js 文件
- 在
plugins中:
plugins: [
{
src: '~/plugins/baidu'
}
],- 在
head中:
head: {
// ...
link: [
// ...
],
script: [
{ src: 'https://hm.baidu.com/hm.js?xxxxxxxxxxxxxxxxxxx' }
]
},在script中写入百度统计提供的 url 即可,按照对应的字符。
边栏推荐
- redis实现队列的阻塞、延时、发布和订阅
- 小程序中实现视图懒加载
- 3 tips to crack the flutter productivity you can use immediately!
- 軟件測試職業發展方向,6年老測試帶你走出迷茫...
- 为UEditor for typecho 添加阅读更多按钮
- [IV. demand analysis of several Internet enterprises based on domain name]
- 美原油期货开户,要可靠安全的公司?
- mongoose连接多个数据库简单例子
- Using kubekey to build kubernetes/kubesphere environment“
- 3 个技巧来破解你可以立即使用的 Flutter 生产力!
猜你喜欢

不要假装怀念Kindle

From outsourcing to self research and then to large factories, who knows how I came here in the past five years

关闭StackExchange等平台的privacy收集窗口

Connection between mysql+c ef6

Linux runs shengxunwei online customer service system: implementation method of supporting SQL server and MySQL at the same time

Using kubekey to build kubernetes/kubesphere environment“

Halodoc使用 Apache Hudi 构建 Lakehouse的关键经验

基于tensorflow的猫狗分类

InfoQ geek media's 15th anniversary solicitation of papers | design practice of micro service architecture in the cloud native Era
![[paper] cascade rpn: delving into high quality region proposal network with adaptive revolution](/img/bc/675a4cd11ceb69cdc5be1864003be0.png)
[paper] cascade rpn: delving into high quality region proposal network with adaptive revolution
随机推荐
[paper] cascade r-cnn: delving into high quality object detection
AE script - grid reference line golden section line generation tool guidesup! 2.2 active version
C#/VB.NET 在Word转PDF时生成目录书签
全球骨干网中断 4 小时:谷歌云、AWS、Azure 等均受到影响
JS实现复制内容到剪贴板的方法
Brand renewal, product innovation, marketing innovation, Dongfeng Peugeot's upward road
[v. reverse proxy and related configurations]
JS implements the method of copying contents to the clipboard
cx_ oracle ORA-01036
Blog recommended | bookkeeper - Apache pulsar high availability / strong consistency / low latency storage implementation
基于模板配置的数据可视化平台
Halodoc's key experience in building Lakehouse using Apache Hudi
华为十大发明公布:高效加法网络、多目标博弈智能驾驶获奖
Google搜索为什么不能无限分页?
【二、虚拟主机和域名解析】
Triangular constant strain element (CST) derived from area coordinates
List used by icomponent of unity dots
Due to the suspension of Russian business: IBM Q1 lost 2billion, Cisco 1.3 billion, Adobe 500million, HP 6.7 billion, uipath 100million
tmux(Terminal MultipleXer)命令使用
Mysql+C# EF6间的连接