Skip to content

config/privacy: Change GoogleAnalytics.RespectDoNotTrack default to true #13664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions config/privacy/privacyConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions tpl/tplimpl/tplimpl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>`,
`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>`,
`var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);`,
`if ( false )`,
)
}

Expand Down
Loading