Skip to content

Commit ac48a99

Browse files
committed
config/privacy: Change GoogleAnalytics.RespectDoNotTrack default to true
Closes #13307
1 parent 26f31ff commit ac48a99

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

config/privacy/privacyConfig.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,8 @@ type X struct {
112112

113113
// DecodeConfig creates a privacy Config from a given Hugo configuration.
114114
func DecodeConfig(cfg config.Provider) (pc Config, err error) {
115-
if !cfg.IsSet(privacyConfigKey) {
116-
return
117-
}
118-
115+
pc.GoogleAnalytics.RespectDoNotTrack = true
119116
m := cfg.GetStringMap(privacyConfigKey)
120-
121117
err = mapstructure.WeakDecode(m, &pc)
122118

123119
return

tpl/tplimpl/tplimpl_integration_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,35 @@ func TestGoogleAnalyticsTemplate(t *testing.T) {
195195
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
196196
[privacy.googleAnalytics]
197197
disable = false
198-
respectDoNotTrack = true
198+
DNT
199199
[services.googleAnalytics]
200200
id = 'G-0123456789'
201-
-- layouts/index.html --
202-
{{ template "_internal/google_analytics.html" . }}
201+
-- layouts/home.html --
202+
{{ partial "google_analytics.html" . }}
203203
`
204204

205-
b := hugolib.Test(t, files)
205+
// default respectDoNotTrack value
206+
f := strings.ReplaceAll(files, "DNT", "")
207+
b := hugolib.Test(t, f)
208+
b.AssertFileContent("public/index.html",
209+
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
210+
`if ( true )`,
211+
)
212+
213+
// respectDoNotTrack = true
214+
f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = true")
215+
b = hugolib.Test(t, f)
216+
b.AssertFileContent("public/index.html",
217+
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
218+
`if ( true )`,
219+
)
206220

221+
// respectDoNotTrack = false
222+
f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = false")
223+
b = hugolib.Test(t, f)
207224
b.AssertFileContent("public/index.html",
208225
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
209-
`var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);`,
226+
`if ( false )`,
210227
)
211228
}
212229

0 commit comments

Comments
 (0)