bennyxguo / hexo-theme-obsidian

🎨 A dark Hexo theme, it's responsive, simple but elegant.
https://obsidian.tridiamond.tech/
MIT License
777 stars 110 forks source link

Google Analytics Verification Support #132

Open zhenyuan0502 opened 3 years ago

zhenyuan0502 commented 3 years ago

Hi all, I have reached the Google Analytics Verification for Ownership, which is using gtag.js, but I found out that the document required put it in <head> tag basically to verify.

So I request to move this part at script.ejs https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/layout/_partial/scripts.ejs

<% if (theme.google_analytics) { %>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="//www.googletagmanager.com/gtag/js?id=<%- theme.google_analytics %>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() {
    dataLayer.push(arguments);
  }
  gtag('js', new Date());
  gtag('config', '<%- theme.google_analytics %>');
</script>

and put them in head.ejs https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/layout/_partial/head.ejs

Document: https://developers.google.com/analytics/devguides/collection/gtagjs/

kcn3388 commented 3 years ago

Actually, now all the scripts which mentioned in script.ejs will be add in the footer, and it seems no error now, move to header is not so necessary.

zhenyuan0502 commented 3 years ago

Actually, now all the scripts which mentioned in script.ejs will be add in the footer, and it seems no error now, move to header is not so necessary.

I am not sure if it's detected from Google, if it worked, feel free to close this issue