import { AbstractConsentHandler, BeslistConsentType, ConsentStatusData, ConsentTypeMapping } from './abstract.consent-handler'; export type ComplianzConsentType = 'necessary' | 'functional' | 'preferences' | 'statistics' | 'marketing'; export class ComplianzConsentHandler extends AbstractConsentHandler { public static consentHandlerName = 'complianz-gdpr'; public static consentTypeMapping: ConsentTypeMapping = { necessary: 'functional', functional: 'functional', analytics: 'statistics', performance: undefined, marketing: 'marketing', } public static cookieNameMapping: ConsentTypeMapping = { necessary: 'cmplz_functional', functional: 'cmplz_functional', analytics: 'cmplz_statistics', performance: undefined, marketing: 'cmplz_marketing', }; protected getConsentHandlerName(): string { return ComplianzConsentHandler.consentHandlerName; }; protected getConsentTypeMapping(): ConsentTypeMapping { return ComplianzConsentHandler.consentTypeMapping; } protected getCookieNameMapping(): ConsentTypeMapping { return ComplianzConsentHandler.cookieNameMapping; } protected getInitialConsent(): ConsentStatusData { return { necessary: this.getConsentFromCookie('necessary') === true ? 'granted' : 'denied', functional: this.getConsentFromCookie('functional') === true ? 'granted' : 'denied', analytics: this.getConsentFromCookie('analytics') === true ? 'granted' : 'denied', performance: this.getConsentFromCookie('performance') === true ? 'granted' : 'denied', marketing: this.getConsentFromCookie('marketing') === true ? 'granted' : 'denied', }; } public initializeConsentUpdateListener(): void { document.addEventListener('cmplz_status_change', (event: any) => { const consentStatusData: ConsentStatusData = {}; if (event.detail.category === this.mapConsentType('necessary')) { consentStatusData.necessary = event.detail.value === 'allow' ? 'granted' : 'denied'; } if (event.detail.category === this.mapConsentType('functional')) { consentStatusData.functional = event.detail.value === 'allow' ? 'granted' : 'denied'; } if (event.detail.category === this.mapConsentType('analytics')) { consentStatusData.analytics = event.detail.value === 'allow' ? 'granted' : 'denied'; } if (event.detail.category === this.mapConsentType('marketing')) { consentStatusData.marketing = event.detail.value === 'allow' ? 'granted' : 'denied'; } this.updateConsent(consentStatusData); }); } protected parseConsentCookieValue(consentType: BeslistConsentType, cookieValue: string): boolean { return cookieValue.includes('allow'); } }