将统计插件修改为 hexo g
生成静态文件时生效,避免 hexo s
影响统计数据。
layout\plugin\google-analytics.ejs
1 2 3 4 5 6 7 8 9 10
| <% if (head && get_config_from_obj(plugin, 'tracking_id') && env.cmd.indexOf('g') === 0) { %> <script async src="https://www.googletagmanager.com/gtag/js?id=<%= get_config_from_obj(plugin, 'tracking_id') %>"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date());
gtag('config', '<%= get_config_from_obj(plugin, 'tracking_id') %>'); </script> <% } %>
|
layout\plugin\baidu-analytics.ejs
1 2 3 4 5 6 7 8 9 10 11
| <% if (head && get_config_from_obj(plugin, 'tracking_id') && env.cmd.indexOf('g') === 0) { %> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?<%= get_config_from_obj(plugin, 'tracking_id') %>"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <% } %>
|