diff options
author | Daniel Atwood <daniel@atwood.io> | 2021-03-03 15:30:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 15:30:06 +0300 |
commit | ba16a14c6e884e309380610331aff78213f84751 (patch) | |
tree | 890cd7654e19c9326e44ba8793c1776f08113249 /tpl/tplimpl | |
parent | 782c79ae61a5ec30746ce3729933d6b4d31e0540 (diff) |
Add support for Google Analytics v4
Diffstat (limited to 'tpl/tplimpl')
-rw-r--r-- | tpl/tplimpl/embedded/templates.autogen.go | 18 | ||||
-rw-r--r-- | tpl/tplimpl/embedded/templates/google_analytics.html | 18 |
2 files changed, 30 insertions, 6 deletions
diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 99adf292f..1391e8956 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -121,8 +121,19 @@ var EmbeddedTemplates = [][2]string{ <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>{{end}} {{- end -}}`}, {`google_analytics.html`, `{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}} -{{- if not $pc.Disable -}} -{{ with .Site.GoogleAnalytics }} +{{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}} +{{ if hasPrefix . "G-"}} +<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script> +<script> +{{ template "__ga_js_set_doNotTrack" $ }} +if (!doNotTrack) { + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '{{ . }}', { 'anonymize_ip': {{- $pc.AnonymizeIP -}} }); +} +</script> +{{ else if hasPrefix . "UA-" }} <script type="application/javascript"> {{ template "__ga_js_set_doNotTrack" $ }} if (!doNotTrack) { @@ -148,8 +159,9 @@ if (!doNotTrack) { ga('send', 'pageview'); } </script> -{{ end }} {{- end -}} +{{- end }}{{ end -}} + {{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}} {{- $pc := .Site.Config.Privacy.GoogleAnalytics -}} {{- if not $pc.RespectDoNotTrack -}} diff --git a/tpl/tplimpl/embedded/templates/google_analytics.html b/tpl/tplimpl/embedded/templates/google_analytics.html index 97588113e..f518b150c 100644 --- a/tpl/tplimpl/embedded/templates/google_analytics.html +++ b/tpl/tplimpl/embedded/templates/google_analytics.html @@ -1,6 +1,17 @@ {{- $pc := .Site.Config.Privacy.GoogleAnalytics -}} -{{- if not $pc.Disable -}} -{{ with .Site.GoogleAnalytics }} +{{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}} +{{ if hasPrefix . "G-"}} +<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script> +<script> +{{ template "__ga_js_set_doNotTrack" $ }} +if (!doNotTrack) { + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '{{ . }}', { 'anonymize_ip': {{- $pc.AnonymizeIP -}} }); +} +</script> +{{ else if hasPrefix . "UA-" }} <script type="application/javascript"> {{ template "__ga_js_set_doNotTrack" $ }} if (!doNotTrack) { @@ -26,8 +37,9 @@ if (!doNotTrack) { ga('send', 'pageview'); } </script> -{{ end }} {{- end -}} +{{- end }}{{ end -}} + {{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}} {{- $pc := .Site.Config.Privacy.GoogleAnalytics -}} {{- if not $pc.RespectDoNotTrack -}} |