-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from generoi/feature/tcf-api
Feature/tcf api
- Loading branch information
Showing
17 changed files
with
204 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
AD_STORAGE_CONSENT, | ||
ANALYTICS_STORAGE_CONSENT, | ||
EVENT_CONSENT, | ||
NECESSARY_STORAGE_CONSENT, | ||
PREFERENCES_STORAGE_CONSENT | ||
} from './api'; | ||
|
||
/** | ||
* @param {TCData} tcData | ||
* @returns {ConsentData} | ||
*/ | ||
function getTcfMappedConsentData({purpose}) { | ||
const {consents} = purpose; | ||
|
||
const hasStorageConsent = consents[1]; | ||
const hasRegularAdsConsent = consents[2]; | ||
const hasPersonalizedAdProfileConsent = consents[3]; | ||
const hasPersonalizedAdsConsent = consents[4]; | ||
const hasPersonalizedContentProfileConsent = consents[5]; | ||
const hasPersonalizedSelectionConsent = consents[6]; | ||
const hasAdMeasurementConsent = consents[7]; | ||
const hasContentMeasurementConsent = consents[8]; | ||
const hasMarketResearchConsent = consents[9]; | ||
const hasProductDevelopmentConsent = consents[10]; | ||
|
||
const hasNecessaryConsent = ( | ||
true | ||
); | ||
|
||
const hasPreferencesConsent = ( | ||
hasStorageConsent | ||
); | ||
|
||
const hasStatisticsConsent = ( | ||
hasStorageConsent && | ||
hasAdMeasurementConsent && | ||
// hasContentMeasurementConsent && | ||
hasMarketResearchConsent | ||
); | ||
|
||
const hasMarketingConsent = ( | ||
hasStorageConsent && | ||
hasRegularAdsConsent && | ||
hasPersonalizedAdProfileConsent && | ||
hasPersonalizedAdsConsent | ||
) | ||
|
||
return { | ||
consents: { | ||
[NECESSARY_STORAGE_CONSENT]: hasNecessaryConsent, | ||
[PREFERENCES_STORAGE_CONSENT]: hasPreferencesConsent, | ||
[AD_STORAGE_CONSENT]: hasMarketingConsent, | ||
[ANALYTICS_STORAGE_CONSENT]: hasStatisticsConsent, | ||
}, | ||
version: undefined, | ||
} | ||
} | ||
|
||
function getConsentData() { | ||
return window.gdsCmp?.tcfMappedConsents; | ||
} | ||
|
||
function tcfapi() { | ||
if (!window.__tcfapi) { | ||
return setTimeout(() => tcfapi(...arguments), 100); | ||
} | ||
window.__tcfapi(...arguments); | ||
} | ||
|
||
function runEvent() { | ||
window.dispatchEvent(new CustomEvent(EVENT_CONSENT)); | ||
for (const [consent, value] of Object.entries(getConsentData().consents)) { | ||
if (value) { | ||
window.dispatchEvent(new CustomEvent(`${EVENT_CONSENT}.${consent}`)); | ||
} | ||
} | ||
} | ||
|
||
window.gdsCmp = { | ||
...(window.gdsCmp || {}), | ||
tcfMappedConsents: { | ||
version: undefined, | ||
consents: {}, | ||
}, | ||
getConsentData, | ||
show() { | ||
tcfapi('displayConsentUi', 2, () => {}); | ||
}, | ||
hide() { | ||
tcfapi('displayConsentUi', 2, () => {}); | ||
}, | ||
withdraw() { | ||
// @TODO | ||
} | ||
} | ||
|
||
tcfapi('addEventListener', 2, (tcData, success) => { | ||
if (success && ['tcloaded', 'useractioncomplete'].includes(tcData.eventStatus)) { | ||
window.gdsCmp.tcfMappedConsents = getTcfMappedConsentData(tcData); | ||
runEvent(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'e064a2729d9d042442a81e09bf0482eb'); | ||
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'a50f67649c9c1c5300c2d05e245f7589'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.