diff --git a/config/privacy/privacyConfig.go b/config/privacy/privacyConfig.go
index 900f73540b6..c73467089d5 100644
--- a/config/privacy/privacyConfig.go
+++ b/config/privacy/privacyConfig.go
@@ -112,12 +112,8 @@ type X struct {
// DecodeConfig creates a privacy Config from a given Hugo configuration.
func DecodeConfig(cfg config.Provider) (pc Config, err error) {
- if !cfg.IsSet(privacyConfigKey) {
- return
- }
-
+ pc.GoogleAnalytics.RespectDoNotTrack = true
m := cfg.GetStringMap(privacyConfigKey)
-
err = mapstructure.WeakDecode(m, &pc)
return
diff --git a/tpl/tplimpl/tplimpl_integration_test.go b/tpl/tplimpl/tplimpl_integration_test.go
index b628989237a..3fb917a70e3 100644
--- a/tpl/tplimpl/tplimpl_integration_test.go
+++ b/tpl/tplimpl/tplimpl_integration_test.go
@@ -195,18 +195,35 @@ func TestGoogleAnalyticsTemplate(t *testing.T) {
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
[privacy.googleAnalytics]
disable = false
-respectDoNotTrack = true
+DNT
[services.googleAnalytics]
id = 'G-0123456789'
--- layouts/index.html --
-{{ template "_internal/google_analytics.html" . }}
+-- layouts/home.html --
+{{ partial "google_analytics.html" . }}
`
- b := hugolib.Test(t, files)
+ // default respectDoNotTrack value
+ f := strings.ReplaceAll(files, "DNT", "")
+ b := hugolib.Test(t, f)
+ b.AssertFileContent("public/index.html",
+ ``,
+ `if ( true )`,
+ )
+
+ // respectDoNotTrack = true
+ f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = true")
+ b = hugolib.Test(t, f)
+ b.AssertFileContent("public/index.html",
+ ``,
+ `if ( true )`,
+ )
+ // respectDoNotTrack = false
+ f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = false")
+ b = hugolib.Test(t, f)
b.AssertFileContent("public/index.html",
``,
- `var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);`,
+ `if ( false )`,
)
}