-
Notifications
You must be signed in to change notification settings - Fork 4.1k
amp-consent metadata values #28187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-consent metadata values #28187
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,15 +23,27 @@ import {isEnumValue, isObject} from '../../../src/types'; | |
| * STATE: Set when user accept or reject consent. | ||
| * STRING: Set when a consent string is used to store more granular consent info | ||
| * on vendors. | ||
| * METADATA: set when consent metadata is passed in to store more granular consent info | ||
| * on vendors. | ||
| * DITRYBIT: Set when the stored consent info need to be revoked next time. | ||
| * @enum {string} | ||
| */ | ||
| export const STORAGE_KEY = { | ||
| STATE: 's', | ||
| STRING: 'r', | ||
| IS_DIRTY: 'd', | ||
| METADATA: 'm', | ||
| }; | ||
|
|
||
| /** | ||
| * Key values for retriving/storing metadata values within consent info | ||
| * TODO(micajuineho) | ||
| * GDPR_APPLIES: 'ga' | ||
| * CONSENT_STRING_TYPE: 'cst' | ||
| * @enum {string} | ||
| */ | ||
| export const METADATA_STORAGE_KEY = {}; | ||
|
|
||
| /** | ||
| * @enum {number} | ||
| */ | ||
|
|
@@ -50,6 +62,7 @@ export const CONSENT_ITEM_STATE = { | |
| * @typedef {{ | ||
| * consentState: CONSENT_ITEM_STATE, | ||
| * consentString: (string|undefined), | ||
| * consentMetadata: (Object|undefined), | ||
| * isDirty: (boolean|undefined), | ||
| * }} | ||
| */ | ||
|
|
@@ -65,6 +78,7 @@ export function getStoredConsentInfo(value) { | |
| return constructConsentInfo( | ||
| CONSENT_ITEM_STATE.UNKNOWN, | ||
| undefined, | ||
| undefined, | ||
| undefined | ||
| ); | ||
| } | ||
|
|
@@ -80,6 +94,7 @@ export function getStoredConsentInfo(value) { | |
| return constructConsentInfo( | ||
| consentState, | ||
| value[STORAGE_KEY.STRING], | ||
| convertStorageMetadata(value[STORAGE_KEY.METADATA]), | ||
| value[STORAGE_KEY.IS_DIRTY] && value[STORAGE_KEY.IS_DIRTY] === 1 | ||
| ); | ||
| } | ||
|
|
@@ -145,6 +160,12 @@ export function composeStoreValue(consentInfo) { | |
| obj[STORAGE_KEY.IS_DIRTY] = 1; | ||
| } | ||
|
|
||
| if (consentInfo['consentMetadata']) { | ||
| obj[STORAGE_KEY.METADATA] = composeMetadataStoreValue( | ||
| consentInfo['consentMetadata'] | ||
| ); | ||
| } | ||
|
|
||
| if (Object.keys(obj) == 0) { | ||
| return null; | ||
| } | ||
|
|
@@ -191,36 +212,55 @@ export function isConsentInfoStoredValueSame(infoA, infoB, opt_isDirty) { | |
| } else { | ||
| isDirtyEqual = !!infoA['isDirty'] === !!infoB['isDirty']; | ||
| } | ||
| return stateEqual && stringEqual && isDirtyEqual; | ||
| const metadataEqual = isMetadataEqual( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I introduced this check to help prevent some unnecessary call to the storageAPI.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still worth it, since checking the metadata shouldn't be too much work compared to fetching and parsing info from local storage. Happy to remove the check if you think otherwise.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked offline: we will measure performance of this later and determine if it should be removed or not. |
||
| infoA['consentMetadata'], | ||
| infoB['consentMetadata'] | ||
| ); | ||
| return stateEqual && stringEqual && metadataEqual && isDirtyEqual; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Compares metadata values from consentInfo | ||
| * | ||
| * @param {Object=} unusedMetadataA | ||
| * @param {Object=} unusedMetadataB | ||
| * @return {boolean} | ||
| */ | ||
| function isMetadataEqual(unusedMetadataA, unusedMetadataB) { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Convert the legacy boolean stored value to consentInfo object | ||
| * @param {boolean} value | ||
| * @return {!ConsentInfoDef} | ||
| */ | ||
| function getLegacyStoredConsentInfo(value) { | ||
| const state = convertValueToState(value); | ||
| return constructConsentInfo(state, undefined, undefined); | ||
| return constructConsentInfo(state); | ||
| } | ||
|
|
||
| /** | ||
| * Construct the consentInfo object from values | ||
| * | ||
| * @param {CONSENT_ITEM_STATE} consentState | ||
| * @param {string=} opt_consentString | ||
| * @param {Object=} opt_consentMetadata | ||
| * @param {boolean=} opt_isDirty | ||
| * @return {!ConsentInfoDef} | ||
| */ | ||
| export function constructConsentInfo( | ||
| consentState, | ||
| opt_consentString, | ||
| opt_consentMetadata, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why you want to pass the consent metadata before the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. Done |
||
| opt_isDirty | ||
| ) { | ||
| return { | ||
| 'consentState': consentState, | ||
| 'consentString': opt_consentString, | ||
| 'consentMetadata': opt_consentMetadata, | ||
| 'isDirty': opt_isDirty, | ||
| }; | ||
| } | ||
|
|
@@ -286,3 +326,29 @@ export function getConsentStateValue(enumState) { | |
|
|
||
| return 'unknown'; | ||
| } | ||
|
|
||
| /** | ||
| * Converts metadata to stroage value: | ||
| * {'gdprApplies': true, 'consentStringType': 'tcf-v2'} => | ||
| * {'ga': true, 'cst': 'tcf-v2'} | ||
| * | ||
| * @param {Object} unused | ||
| * @return {Object} | ||
| */ | ||
| function composeMetadataStoreValue(unused) { | ||
| const storageMetadata = map(); | ||
| // TODO(micajuineho) if (metadata['gdprApplies']) {...} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my idea as well. Just wanted to lay the skeleton out here, and then add implementation as we add
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me! Correct me, but I think you have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, it shouldn't do anything, and I wanted to make sure my ideas were valid by fleshing it out. Should I remove it? Will remove for now
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SG. Thanks |
||
| return storageMetadata; | ||
| } | ||
|
|
||
| /** | ||
| * TODO(micajuineho) Converts stroage metadata to human readable object: | ||
| * {'ga': true, 'cst': 'tcf-v2'} => | ||
| * {'gdprApplies': true, 'consentStringType': 'tcf-v2'} | ||
| * | ||
| * @param {Object=} unused | ||
| * @return {Object=} | ||
| */ | ||
| function convertStorageMetadata(unused) { | ||
| return undefined; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.