@@ -195,18 +195,35 @@ func TestGoogleAnalyticsTemplate(t *testing.T) {
195195disableKinds = ['page','section','rss','sitemap','taxonomy','term']
196196[privacy.googleAnalytics]
197197disable = false
198- respectDoNotTrack = true
198+ DNT
199199[services.googleAnalytics]
200200id = '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