Skip to content
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

✨ Temporarily clear dirty bit on consent response if configured #36979

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions extensions/amp-consent/0.1/amp-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,30 @@ export class AmpConsent extends AMP.BaseElement {
* @param {!ConsentMetadataDef=} opt_consentMetadata
*/
handleAction_(action, consentString, opt_consentMetadata) {
const setDirtyBitPromise =
isEnumValue(ACTION_TYPE, action) &&
this.consentConfig_['clearDirtyBitOnResponse_dontUseThisItMightBeRemoved']
? this.consentStateManager_.setDirtyBit(false)
: Promise.resolve();
setDirtyBitPromise.then(() => {
this.handleActionAfterClearingDirtyBit_(
action,
consentString,
opt_consentMetadata
);
});
}

/**
* @param {string} action
* @param {string=} consentString
* @param {!ConsentMetadataDef=} opt_consentMetadata
*/
handleActionAfterClearingDirtyBit_(
action,
consentString,
opt_consentMetadata
) {
this.consentStateChangedViaPromptUI_ = true;

if (action == ACTION_TYPE.ACCEPT) {
Expand Down Expand Up @@ -521,10 +545,13 @@ export class AmpConsent extends AMP.BaseElement {
*/
handleReprompt_(invocation) {
const {args} = invocation;
if (args && args['expireCache'] === true) {
this.consentStateManager_.setDirtyBit();
}
this.scheduleDisplay_(true);
const setDirtyBitPromise =
args?.['expireCache'] === true
? this.consentStateManager_.setDirtyBit()
: Promise.resolve();
setDirtyBitPromise.then(() => {
this.scheduleDisplay_(true);
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-consent/0.1/cmps.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ CMP_CONFIG['googlefc'] = {
'uiConfig': {
'overlay': true,
},
'clearDirtyBitOnResponse_dontUseThisItMightBeRemoved': true,
};
27 changes: 17 additions & 10 deletions extensions/amp-consent/0.1/consent-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,15 @@ export class ConsentStateManager {
}

/**
* Sets the dirty bit so current consent info won't be used for
* decision making on next visit
* Set dirtyBit to current consent info. Refresh stored consent value with
* dirtyBit
* @param {boolean=} dirty
* @return {Promise<void>}
* TODO(alanorozco): Remove `dirty` argument and always set to true once
* we remove clearDirtyBitOnResponse_dontUseThisItMightBeRemoved.
*/
setDirtyBit() {
this.instance_.setDirtyBit();
setDirtyBit(dirty = true) {
return this.instance_.setDirtyBit(dirty);
}

/**
Expand Down Expand Up @@ -320,14 +324,17 @@ export class ConsentInstance {
/**
* Set dirtyBit to current consent info. Refresh stored consent value with
* dirtyBit
* @return {*} TODO(#23582): Specify return type
* @param {boolean=} dirty
* @return {Promise<void>}
* TODO(alanorozco): Remove `dirty` argument and always set to true once
* we remove clearDirtyBitOnResponse_dontUseThisItMightBeRemoved.
*/
setDirtyBit() {
// Note: this.hasDirtyBitNext_ is only set to true when 'forcePromptNext'
setDirtyBit(dirty = true) {
// Note: this.hasDirtyBitNext_ is only set to true when 'forcePromptOnNext'
// is set to true and we need to set dirtyBit for next visit.
this.hasDirtyBitNext_ = true;
this.hasDirtyBitNext_ = dirty;
return this.get().then((info) => {
if (hasDirtyBit(info)) {
if (hasDirtyBit(info) === dirty) {
// Current stored value has dirtyBit and is no longer valid.
// No need to update with dirtyBit
return;
Expand All @@ -337,7 +344,7 @@ export class ConsentInstance {
info['consentString'],
info['purposeConsents'],
info['consentMetadata'],
true
dirty
);
});
}
Expand Down