diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-05-25 14:52:06 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-05-25 15:56:10 +0200 |
commit | a51945ea4b99d17501d73cf3367926683e4a4dfd (patch) | |
tree | 730552e112274a2cdc3c3e0f1b1ff2f365107d81 /tpl | |
parent | 7b9dbef41acfc619754d5a2a342a00e37f6f96e0 (diff) |
Add no-cookie variants of the Google Analytics templates
The current full set of options for GA is now:
```toml
[privacy]
[privacy.googleAnalytics]
disable = false
respectDoNotTrack = true
anonymizeIP = true
useSessionStorage = true
```
Fixes #4775
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/embedded/templates.autogen.go | 26 | ||||
-rwxr-xr-x | tpl/tplimpl/embedded/templates/google_analytics.html | 13 | ||||
-rwxr-xr-x | tpl/tplimpl/embedded/templates/google_analytics_async.html | 13 |
3 files changed, 52 insertions, 0 deletions
diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index df44102ea..db35f789a 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -109,7 +109,20 @@ if (!doNotTrack) { (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + {{- if $pc.UseSessionStorage }} + if (window.sessionStorage) { + var GA_SESSION_STORAGE_KEY = 'ga:clientId'; + ga('create', '{{ . }}', { + 'storage': 'none', + 'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY) + }); + ga(function(tracker) { + sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId')); + }); + } + {{ else }} ga('create', '{{ . }}', 'auto'); + {{ end -}} ga('send', 'pageview'); {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } @@ -132,7 +145,20 @@ var doNotTrack = (dnt == "1" || dnt == "yes"); {{ template "__ga_js_set_doNotTrack" $ }} if (!doNotTrack) { window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; + {{- if $pc.UseSessionStorage }} + if (window.sessionStorage) { + var GA_SESSION_STORAGE_KEY = 'ga:clientId'; + ga('create', '{{ . }}', { + 'storage': 'none', + 'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY) + }); + ga(function(tracker) { + sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId')); + }); + } + {{ else }} ga('create', '{{ . }}', 'auto'); + {{ end -}} ga('send', 'pageview'); {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } diff --git a/tpl/tplimpl/embedded/templates/google_analytics.html b/tpl/tplimpl/embedded/templates/google_analytics.html index 611c1c726..429672a7e 100755 --- a/tpl/tplimpl/embedded/templates/google_analytics.html +++ b/tpl/tplimpl/embedded/templates/google_analytics.html @@ -8,7 +8,20 @@ if (!doNotTrack) { (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + {{- if $pc.UseSessionStorage }} + if (window.sessionStorage) { + var GA_SESSION_STORAGE_KEY = 'ga:clientId'; + ga('create', '{{ . }}', { + 'storage': 'none', + 'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY) + }); + ga(function(tracker) { + sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId')); + }); + } + {{ else }} ga('create', '{{ . }}', 'auto'); + {{ end -}} ga('send', 'pageview'); {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } diff --git a/tpl/tplimpl/embedded/templates/google_analytics_async.html b/tpl/tplimpl/embedded/templates/google_analytics_async.html index 18e18a168..8fb746e0b 100755 --- a/tpl/tplimpl/embedded/templates/google_analytics_async.html +++ b/tpl/tplimpl/embedded/templates/google_analytics_async.html @@ -5,7 +5,20 @@ {{ template "__ga_js_set_doNotTrack" $ }} if (!doNotTrack) { window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; + {{- if $pc.UseSessionStorage }} + if (window.sessionStorage) { + var GA_SESSION_STORAGE_KEY = 'ga:clientId'; + ga('create', '{{ . }}', { + 'storage': 'none', + 'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY) + }); + ga(function(tracker) { + sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId')); + }); + } + {{ else }} ga('create', '{{ . }}', 'auto'); + {{ end -}} ga('send', 'pageview'); {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } |