Skip to content

Commit

Permalink
🐞 fix: Google Analytics #64
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Feb 10, 2023
1 parent 82fce3d commit 7f751d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package/hexo-theme-async/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ layout:
sidebar_social: _partial/sidebar/card/social
sidebar_info: _partial/sidebar/card/info
sidebar_email: _partial/sidebar/card/email
# third-party
comment: _third-party/comment/index
analytics: _third-party/web-analytics
# animation
page_loading: _partial/preloader/page-preloader
mode_change: _partial/preloader/change-mode-preloader
Expand Down
2 changes: 1 addition & 1 deletion package/hexo-theme-async/layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
<%- partial('../_third-party/cdn',{ cdntype: 'head' }) %>

<!-- Site Analytics -->
<%- partial('../_third-party/web-analytics') %>
<%- partial(theme.layout.analytics) %>
18 changes: 9 additions & 9 deletions package/hexo-theme-async/layout/_third-party/web-analytics.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
<script defer>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%- theme.webAnalytics.baidu %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%- theme.webAnalytics.baidu %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<% } %>
<% if (theme.webAnalytics.google){ %>
<!-- Google Analytics -->
<script async src='https://www.googletagmanager.com/gtag/js?id=<%- theme.webAnalytics.google %>'></script>
<script defer>
window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) };
ga.l = +new Date;
ga('create', '<%= theme.webAnalytics.google %>', 'auto');
ga('send', 'pageview');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<%= theme.webAnalytics.google %>');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<% } %>
<% if(theme.webAnalytics.tencent && theme.webAnalytics.tencent.sid && theme.webAnalytics.tencent.cid) { %>
Expand Down

0 comments on commit 7f751d9

Please sign in to comment.