mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
config/privacy: Change GoogleAnalytics.RespectDoNotTrack default to true
Closes #13307
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
438f113f83
commit
565a10cbf0
@@ -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
|
||||
|
||||
@@ -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",
|
||||
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
|
||||
`var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);`,
|
||||
`if ( true )`,
|
||||
)
|
||||
|
||||
// respectDoNotTrack = true
|
||||
f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = true")
|
||||
b = hugolib.Test(t, f)
|
||||
b.AssertFileContent("public/index.html",
|
||||
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
|
||||
`if ( true )`,
|
||||
)
|
||||
|
||||
// respectDoNotTrack = false
|
||||
f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = false")
|
||||
b = hugolib.Test(t, f)
|
||||
b.AssertFileContent("public/index.html",
|
||||
`<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`,
|
||||
`if ( false )`,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user