feat(cli): support add baiduAnalytics to site

This commit is contained in:
陈嘉涵
2019-12-24 21:09:31 +08:00
parent d89c63ff13
commit 141c0ed2c1
4 changed files with 37 additions and 3 deletions

View File

@@ -9,6 +9,17 @@
<meta http-Equiv="Pragma" Content="no-cache" />
<meta http-Equiv="Expires" Content="0" />
<link href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" rel="stylesheet" />
<% if (htmlWebpackPlugin.options.baiduAnalytics) { %>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%= htmlWebpackPlugin.options.baiduAnalytics.seed %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<% } %>
</head>
<body ontouchstart>
<div id="app"></div>

View File

@@ -8,6 +8,20 @@
<meta http-Equiv="Cache-Control" Content="no-cache" />
<meta http-Equiv="Pragma" Content="no-cache" />
<meta http-Equiv="Expires" Content="0" />
<% if (htmlWebpackPlugin.options.baiduAnalytics) { %>
<script>
// avoid to load analytics in iframe
if (window.top === window) {
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%= htmlWebpackPlugin.options.baiduAnalytics.seed %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
}
</script>
<% } %>
</head>
<body ontouchstart>
<div id="app"></div>