diff options
-rw-r--r-- | config/privacy/privacyConfig.go | 3 | ||||
-rw-r--r-- | config/privacy/privacyConfig_test.go | 2 | ||||
-rw-r--r-- | hugolib/embedded_templates_test.go | 5 | ||||
-rw-r--r-- | hugolib/testhelpers_test.go | 17 | ||||
-rw-r--r-- | tpl/tplimpl/embedded/templates.autogen.go | 2 | ||||
-rwxr-xr-x | tpl/tplimpl/embedded/templates/google_analytics.html | 1 | ||||
-rwxr-xr-x | tpl/tplimpl/embedded/templates/google_analytics_async.html | 1 |
7 files changed, 30 insertions, 1 deletions
diff --git a/config/privacy/privacyConfig.go b/config/privacy/privacyConfig.go index 9c2a8df66..33e98754c 100644 --- a/config/privacy/privacyConfig.go +++ b/config/privacy/privacyConfig.go @@ -48,6 +48,9 @@ type GoogleAnalytics struct { // Enabling this will make the GA templates respect the // "Do Not Track" HTTP header. See https://www.paulfurley.com/google-analytics-dnt/. RespectDoNotTrack bool + + // Enabling this will make it so the users' IP addresses are anonymized within Google Analytics. + AnonymizeIP bool } // Instagram holds the privacy configuration settings related to the Instagram shortcode. diff --git a/config/privacy/privacyConfig_test.go b/config/privacy/privacyConfig_test.go index 6b07ef7e6..112e45988 100644 --- a/config/privacy/privacyConfig_test.go +++ b/config/privacy/privacyConfig_test.go @@ -34,6 +34,7 @@ disable = true [privacy.googleAnalytics] disable = true respectDoNotTrack = true +anonymizeIP = true [privacy.instagram] disable = true simple = true @@ -59,6 +60,7 @@ simple = true assert.True(pc.Disqus.Disable) assert.True(pc.GoogleAnalytics.Disable) assert.True(pc.GoogleAnalytics.RespectDoNotTrack) + assert.True(pc.GoogleAnalytics.AnonymizeIP) assert.True(pc.Instagram.Disable) assert.True(pc.Instagram.Simple) assert.True(pc.SpeakerDeck.Disable) diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go index fd620bd15..e04a37f63 100644 --- a/hugolib/embedded_templates_test.go +++ b/hugolib/embedded_templates_test.go @@ -47,7 +47,10 @@ Disqus: b.Build(BuildCfg{}) // Gheck GA regular and async - b.AssertFileContent("public/index.html", "'script','https://www.google-analytics.com/analytics.js','ga');\n\tga('create', 'ga_id', 'auto')", "<script async src='//www.google-analytics.com/analytics.js'>") + b.AssertFileContent("public/index.html", + "'anonymizeIp', true", + "'script','https://www.google-analytics.com/analytics.js','ga');\n\tga('create', 'ga_id', 'auto')", + "<script async src='//www.google-analytics.com/analytics.js'>") // Disqus b.AssertFileContent("public/index.html", "\"disqus_shortname\" + '.disqus.com/embed.js';") diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 7a93fcd9a..28dd8c125 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -143,6 +143,23 @@ shortname = "disqus_shortname" [services.googleAnalytics] id = "ga_id" +[privacy] +[privacy.disqus] +disable = false +[privacy.googleAnalytics] +respectDoNotTrack = true +anonymizeIP = true +[privacy.instagram] +simple = true +[privacy.speakerDeck] +[privacy.twitter] +enableDNT = true +[privacy.vimeo] +disable = false +[privacy.youtube] +disable = false +privacyEnhanced = true + ` func (s *sitesBuilder) WithSimpleConfigFile() *sitesBuilder { diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 9b4db35d6..9637deb10 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -111,6 +111,7 @@ if (!doNotTrack) { })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', '{{ . }}', 'auto'); ga('send', 'pageview'); + {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } </script> {{ end }} @@ -133,6 +134,7 @@ if (!doNotTrack) { window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; ga('create', '{{ . }}', 'auto'); ga('send', 'pageview'); + {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } </script> <script async src='//www.google-analytics.com/analytics.js'></script> diff --git a/tpl/tplimpl/embedded/templates/google_analytics.html b/tpl/tplimpl/embedded/templates/google_analytics.html index ae4898c7a..611c1c726 100755 --- a/tpl/tplimpl/embedded/templates/google_analytics.html +++ b/tpl/tplimpl/embedded/templates/google_analytics.html @@ -10,6 +10,7 @@ if (!doNotTrack) { })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', '{{ . }}', 'auto'); ga('send', 'pageview'); + {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } </script> {{ end }} diff --git a/tpl/tplimpl/embedded/templates/google_analytics_async.html b/tpl/tplimpl/embedded/templates/google_analytics_async.html index b81ade025..18e18a168 100755 --- a/tpl/tplimpl/embedded/templates/google_analytics_async.html +++ b/tpl/tplimpl/embedded/templates/google_analytics_async.html @@ -7,6 +7,7 @@ if (!doNotTrack) { window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; ga('create', '{{ . }}', 'auto'); ga('send', 'pageview'); + {{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}} } </script> <script async src='//www.google-analytics.com/analytics.js'></script> |