add google analytics

This commit is contained in:
MeiK
2020-12-16 14:18:42 +08:00
parent b8138d659e
commit 4dcb9d2204
2 changed files with 16 additions and 1 deletions

View File

@@ -8,7 +8,6 @@
## TODO
- Google Analytics
- 评论
- 自定义菜单
- 更多链接平台支持

View File

@@ -39,3 +39,19 @@
{{ with .OutputFormats.Get "json" }}
<link href="{{ .RelPermalink }}" rel="alternate" type="application/json" title="{{ $.Site.Title }}" />
{{ end }}
<!-- Google Analytics -->
{{ if eq (getenv "HUGO_ENV") "production"}}
{{ with .Site.GoogleAnalytics }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
if (navigator.doNotTrack !== '1') {
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '{{ . }}');
}
</script>
{{ end }}
{{ end }}