百度:为vue站添加百度统计

一,登录百度统计获取统计代码:

使用设置->网站列表->新增网站:

填写数据后点确定:

配置单页:

复制代码:

二,添加代码到vue的html页面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width,initial-scale=1.0" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
        <title><%= htmlWebpackPlugin.options.title %></title>
         
        <% if (process.env.NODE_ENV === 'production' ) { %>
        <script>
            var _hmt = _hmt || [];
        </script>
        <% } %>
    </head>
    <body>
        <noscript>
            <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
            
           <% if (process.env.NODE_ENV === 'production' ) { %>
        <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>
        <% } %>
    </body>
</html>

然后打包上传到服务器

liuhongdi@lhdpc:/data/vue/touch$ npm run build

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/08/28/bai-du-wei-vue-zhan-tian-jia-bai-du-tong-ji/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com

三,测试效果:

可以看到代码安装正确无问题

posted @ 2023-08-28 15:23  刘宏缔的架构森林  阅读(720)  评论(0编辑  收藏  举报