react 项目添加百度统计

将如下代码添加到 index.html 的 head 标签中

<script>
    var _hmt = _hmt || [];
    (function() {
    
    
      var hm = document.createElement("script");
      <!-- 判断生产环境和测试环境-- >
      hm.src = '%REACT_APP_RUN_ENV%' === 'prod' 
        ? "https://hm.baidu.com/hm.js?8f2623e240dd9012cc4b61155c5b6529" //生产
        : "https://hm.baidu.com/hm.js?674b596cab583fc28239ca2d9024ea3a"; //测试
        console.log(hm.src,"hm.src")
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
</script>

Guess you like

Origin blog.csdn.net/xiamoziqian/article/details/121534794