uniapp adds Baidu statistical code (h5)

Made a h5 interface for WeChat official account. http//:mp.sscai.club (it can only be opened by wechat browser), in which the statistics code is used, and the record is as follows.

1. New tj.html interface

It can be placed in the root directory of the project, and the file name is named according to your own situation.

2. Paste content

Please copy the following code to the new html above and modify your Baidu statistics code. If you don't know how to get the statistics code, please refer to step 4

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <title>
            <%= htmlWebpackPlugin.options.title %>
        </title>
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
            })
            // Run this script in production
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js? Here is your Baidu statistics code ";
              var s = document.getElementsByTagName("script")[0]; 
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
    </head>
    <body>
        <noscript>
            <strong>Please enable JavaScript to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
    </body>
</html>

3. Configure template code

Enter the pages.json > Source View > H5 (bottom) node, and add:

"template": "tj.html"

4. Statistics code acquisition

New account or existing baidu account login: https://tongji.baidu.com/sc-web>

Add a site to the site list

Then copy the following code.

After graduation, I was confused and created a public official account for my growth. Interested buddy can be concerned about it.

Tags: Programming IE Javascript JSON

Posted on Mon, 04 May 2020 09:48:30 -0400 by trip272