Migrate from analytics.js to gtag.js

We should move this to the internal Hugo template when tested.
This commit is contained in:
Bjørn Erik Pedersen 2018-02-19 09:26:13 +01:00
parent 64a29b6cbc
commit 5571673f08
No known key found for this signature in database
GPG Key ID: 330E6E2BD4859D8F
2 changed files with 11 additions and 1 deletions

View File

@ -34,7 +34,7 @@
{{- template "_internal/twitter_cards.html" . -}} {{- template "_internal/twitter_cards.html" . -}}
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }} {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }}
{{ template "_internal/google_analytics_async.html" . }} {{ partial "gtag" . }}
{{ end }} {{ end }}

View File

@ -0,0 +1,10 @@
{{ with .Site.GoogleAnalytics }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ . }}');
</script>
{{ end }}