@@ -117,6 +117,7 @@ class ConsentManager {
117117 private consent : ConsentRecord | null = null ;
118118 private initialized = false ;
119119 private listeners : Set < ConsentChangeListener > = new Set ( ) ;
120+ private externalConsent : Partial < Record < ConsentCategory , boolean > > | null = null ;
120121 /**
121122 * Scripts waiting for a specific category's consent.
122123 * Keyed by category; values are loader functions to call when consent is granted.
@@ -187,7 +188,6 @@ class ConsentManager {
187188 personalization_storage : 'denied' ,
188189 wait_for_update : 2000 ,
189190 } ) ;
190- win . gtag ( 'js' , new Date ( ) ) ;
191191 win . __lynxGcmDefaultConsentSet = true ;
192192 }
193193
@@ -202,6 +202,9 @@ class ConsentManager {
202202 */
203203 isGranted ( category : ConsentCategory ) : boolean {
204204 if ( ALWAYS_ACTIVE . includes ( category ) ) return true ;
205+ if ( this . config ?. mode === 'builder' ) {
206+ return this . _isExternalCategoryGranted ( category ) ;
207+ }
205208 if ( ! this . consent ) return false ;
206209 if ( ! this . _isConsentFresh ( ) ) return false ;
207210 const cfg = this . config ?. hardcoded ;
@@ -480,6 +483,26 @@ class ConsentManager {
480483 }
481484 }
482485
486+ private _isExternalCategoryGranted ( category : ConsentCategory ) : boolean {
487+ if ( ! this . config ?. enabled || this . config . mode !== 'builder' ) return false ;
488+
489+ const cookiebotConsent = ( window as any ) . Cookiebot ?. consent ;
490+ if ( cookiebotConsent && this . config . builder ?. provider === 'cookiebot' ) {
491+ if ( category === 'preferences' ) return cookiebotConsent . preferences === true ;
492+ if ( category === 'analytics' ) return cookiebotConsent . statistics === true ;
493+ if ( category === 'marketing' ) return cookiebotConsent . marketing === true ;
494+ }
495+
496+ return this . externalConsent ?. [ category ] === true ;
497+ }
498+
499+ private _setExternalConsent ( categories : Record < ConsentCategory , boolean > ) : void {
500+ this . externalConsent = categories ;
501+ this . _dispatchGcmUpdate ( categories ) ;
502+ this . _dispatchPendingScripts ( ) ;
503+ this . _notifyListeners ( ) ;
504+ }
505+
483506 private _injectHtmlSnippet ( target : HTMLElement , html : string , markerId ?: string ) : boolean {
484507 const template = document . createElement ( 'template' ) ;
485508 template . innerHTML = html ;
@@ -544,6 +567,7 @@ _iub.csConfiguration = {
544567 console . warn ( '[LynxConsent] Cookiebot: missing scriptId (cbid)' ) ;
545568 return ;
546569 }
570+ this . _wireCookiebotConsentEvents ( ) ;
547571 const script = document . createElement ( 'script' ) ;
548572 script . id = 'lynx-cmp-script' ;
549573 script . setAttribute ( 'data-cbid' , cfg . scriptId ) ;
@@ -553,6 +577,29 @@ _iub.csConfiguration = {
553577 document . head . appendChild ( script ) ;
554578 }
555579
580+ private _wireCookiebotConsentEvents ( ) : void {
581+ const win = window as any ;
582+ if ( win . __lynxCookiebotConsentEventsWired ) return ;
583+ win . __lynxCookiebotConsentEventsWired = true ;
584+
585+ const syncCookiebotConsent = ( ) => {
586+ const consent = win . Cookiebot ?. consent ;
587+ if ( ! consent ) return ;
588+ this . _setExternalConsent ( {
589+ necessary : true ,
590+ preferences : consent . preferences === true ,
591+ analytics : consent . statistics === true ,
592+ marketing : consent . marketing === true ,
593+ } ) ;
594+ } ;
595+
596+ window . addEventListener ( 'CookiebotOnConsentReady' , syncCookiebotConsent ) ;
597+ window . addEventListener ( 'CookiebotOnAccept' , syncCookiebotConsent ) ;
598+ window . addEventListener ( 'CookiebotOnDecline' , syncCookiebotConsent ) ;
599+ window . addEventListener ( 'CookiebotOnLoad' , syncCookiebotConsent ) ;
600+ syncCookiebotConsent ( ) ;
601+ }
602+
556603 private _injectCookieYes ( cfg : BuilderConfig [ 'providerConfig' ] ) : void {
557604 if ( ! cfg . scriptId ) {
558605 console . warn ( '[LynxConsent] CookieYes: missing scriptId' ) ;
0 commit comments