@@ -8,9 +8,24 @@ function gtag() {
88 window . dataLayer . push ( arguments ) ;
99}
1010
11+ function updateConsent ( cookie ) {
12+ if ( cookie . categories . includes ( 'analytics' ) ) {
13+ gtag ( 'consent' , 'update' , { 'analytics_storage' : 'granted' } ) ;
14+ } else {
15+ gtag ( 'consent' , 'update' , { 'analytics_storage' : 'denied' } ) ;
16+ }
17+
18+ if ( cookie . categories . includes ( 'marketing' ) ) {
19+ gtag ( 'consent' , 'update' , { 'ad_storage' : 'granted' , 'ad_personalization' : 'granted' , 'ad_user_data' : 'granted' } ) ;
20+ } else {
21+ gtag ( 'consent' , 'update' , { 'ad_storage' : 'denied' , 'ad_personalization' : 'denied' , 'ad_user_data' : 'denied' } ) ;
22+ }
23+ }
24+
1125// run plugin with config object
1226CookieConsent . run ( {
1327 disablePageInteraction : true ,
28+ revision : 1 , // Update this whenever cookies need to change
1429 cookie : {
1530 name : 'fitz-cookies' ,
1631 expiresAfterDays : 365 ,
@@ -188,21 +203,11 @@ CookieConsent.run({
188203 }
189204 } ,
190205
191- onConsent : function ( cookie ) {
192- gtag ( 'consent' , 'update' , { 'analytics_storage' : 'granted' , 'ad_storage' : 'granted' , 'ad_personalization' : 'granted' , 'ad_user_data' : 'granted' } ) ;
206+ onConsent : function ( { cookie} ) {
207+ updateConsent ( cookie ) ;
193208 } ,
194209
195- onChange : function ( cookie , changed_preferences ) {
196- if ( cookie . categories . includes ( 'analytics' ) ) {
197- gtag ( 'consent' , 'update' , { 'analytics_storage' : 'granted' } ) ;
198- } else {
199- gtag ( 'consent' , 'update' , { 'analytics_storage' : 'denied' } ) ;
200- }
201-
202- if ( cookie . categories . includes ( 'marketing' ) ) {
203- gtag ( 'consent' , 'update' , { 'ad_storage' : 'granted' , 'ad_personalization' : 'granted' , 'ad_user_data' : 'granted' } ) ;
204- } else {
205- gtag ( 'consent' , 'update' , { 'ad_storage' : 'denied' , 'ad_personalization' : 'denied' , 'ad_user_data' : 'denied' } ) ;
206- }
210+ onChange : function ( { cookie} , changed_preferences ) {
211+ updateConsent ( cookie ) ;
207212 }
208213} ) ;
0 commit comments