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
Allow sending RTC with consentState policy adherence #15951
Allow sending RTC with consentState policy adherence #15951
Conversation
/** | ||
* Returns whether a given callout object is valid to send an RTC request | ||
* to, for the given consentState. | ||
* @param {Object|string} callout |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
build-system/amp.extern.js
Outdated
@@ -445,3 +445,10 @@ AMP.require; | |||
* @typedef {function(number, boolean):?|function(number):?} | |||
*/ | |||
var TransitionDef; | |||
|
|||
const CONSENT_POLICY_STATE = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add /** @enum {number} ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
build-system/amp.extern.js
Outdated
* See src/consent-state.js for more information. | ||
* @enum {number} | ||
*/ | ||
const CONSENT_POLICY_STATE = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this is now externed can we delete src/consent-state.js (and carry-over documentation)?
/** | ||
* Returns whether a given callout object is valid to send an RTC request | ||
* to, for the given consentState. | ||
* @param {Object|string} callout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calloutConfig sounds like a better name IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Returns whether a given callout object is valid to send an RTC request | ||
* to, for the given consentState. | ||
* @param {Object|string} callout | ||
* @return {boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return false; | ||
} | ||
|
||
const sendRegardlessOfConsentState = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (typeof callout.sendRegardlessOfConsentState) {
case 'boolean':
return callout.sendRegardlessOfConsentState;
case 'Array':
return sendRegardlessOfConsentState.includes(this.consentState_);
default:
user().warn(TAG, 'WHAT?! ...');
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
* custom URL. | ||
*/ | ||
modifyRtcConfigForConsentStateSettings() { | ||
if (!(this.consentState_ == CONSENT_POLICY_STATE.INSUFFICIENT || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate code? Can you just call isValidCalloutForConsentState with the global value? Also what if global sendRegardlessOfConsentState is false but individual callout is true (or array with value)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, and the current setup is that the default is the global is false, and any individual can override.
// 'macros'. This is for backwards compatability. | ||
const vendorMacros = | ||
this.rtcConfig_.vendors[vendor]['macros'] && | ||
isObject(this.rtcConfig_.vendors[vendor]['macros']) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the first check here? I would assume isObject returns false if undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
This pull request introduces 1 alert when merging 0eda166 into 289a745 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
This pull request introduces 1 alert when merging 5f9bd7a into 289a745 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
customMacros = this.assignMacros(customMacros); | ||
this.rtcStartTime_ = Date.now(); | ||
this.handleRtcForCustomUrls(customMacros); | ||
this.handleRtcForVendorUrls(customMacros); | ||
return Promise.all(this.promiseArray_); | ||
return this.promiseArray_.length ? Promise.all(this.promiseArray_) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume that Promise.all empty array is equivalent to Promise.resolve... Why return null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same thing but I was having issues in testing where that was not the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still surprises me... r u sure?
} | ||
return false; | ||
} | ||
user().warn(TAG, 'Invalid value for sendRegardlessOfConsentState'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include callout info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isArray(sendRegardlessOfConsentState)) { | ||
for (let i = 0; i < sendRegardlessOfConsentState.length; i++) { | ||
if (this.consentState_ == | ||
CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could warn here when a constent state given does not exist in the enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do a switch here:
switch (sendRegardlessOfConsentState[i]) {
case this.consentState_:
return true;
case undefined:
Log... break;
}
urls.push(this.rtcConfig_.urls[i]); | ||
} | ||
} | ||
this.rtcConfig_.urls = urls; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.rtcConfig_.urls = this.rtcConfig_.urls.filter(url => this.isValidCalloutForConsentState(url));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return; | ||
} | ||
|
||
if (this.isValidCalloutForConsentState(this.rtcConfig_)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So global overrides the value on a per callout/vendor level? Image pub has:
{vendors: {foo: {sendRegardlessOfConsentState: ['unknown']}}, sendRegardlessOfConsentState: true}
If consent state is insufficient should we call out to vendor foo? I would argue no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isArray(sendRegardlessOfConsentState)) { | ||
for (let i = 0; i < sendRegardlessOfConsentState.length; i++) { | ||
if (this.consentState_ == | ||
CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do a switch here:
switch (sendRegardlessOfConsentState[i]) {
case this.consentState_:
return true;
case undefined:
Log... break;
}
* Returns whether a given callout object is valid to send an RTC request | ||
* to, for the given consentState. | ||
* @param {Object|string} calloutConfig | ||
* @param {boolean=} optIsGloballyValid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make this not optional and just pass false when calling on the global object
customMacros = this.assignMacros(customMacros); | ||
this.rtcStartTime_ = Date.now(); | ||
this.handleRtcForCustomUrls(customMacros); | ||
this.handleRtcForVendorUrls(customMacros); | ||
return Promise.all(this.promiseArray_); | ||
return this.promiseArray_.length ? Promise.all(this.promiseArray_) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still surprises me... r u sure?
See #15588