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

✨ Pass previous stored consent info to CMP iframe #20242

Merged
merged 3 commits into from Jan 11, 2019

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jan 10, 2019

This PR implements the feature to pass the previously stored/local consent information to CMP iframe.

return consentStateManager.getConsentInstanceInfo().then(consentInfo => {
return dict({
'clientConfig': this.clientConfig_,
'consentState': consentInfo['consentState'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use 'consentState' and 'consentString', instead of a 'consentInfo' object because this leaves me more flexibility to change the internal consentInfo object format in the future.

One thing I'd like to get your input is that: what do you think we should pass to the consentState. Right now, it's an enum value which essentially is a number. Do you think that we should keep a map and convert the enum value to a string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much like your idea of keeping this flexible, and passing parts of the consentInfo, as I am sure consent will evolve in the coming years, and require different information.

For the cosentState going from a number (0, 1, 2) to a string (accept, reject, dismiss), I definitely think we should use a string. It will make the code a lot more clear on their end, and isn't hard for us to do at all. Especially since they can simply build their own ENUMs and logic around a descriptive string, much easier than a number. I also feel like if we change/add new string values, it will probably be caught by an engineer, rather than someone scrolling through the documentation again 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I added a helper method to convert the enum value to string (accepted/rejected/unknown)

This brings another question : )
The API we provide to CMP looks like
action: 'accept/reject/dismiss', but the consent state we pass back looks like 'accepted/rejected/unknown'. Does this look confusing to any of you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummmm. To me it depends if unknown and dismiss mean the same thing?

If they don't I think that should be fine, because we are defining an action (present tense), and then we report back the state after the action has taken place (past tense).

If they do...Actually, I think distinguishing them still might be better. That way on the engineering side their is less confusion what was the action (request) vs. what is the state (response). Plus it would allow for more flexibility in the future, in case we ever want a state like "accepted, but now rejected" or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline. We agreed it's somewhat confusing in both ways. But dismiss doesn't necessary equal to unknown, because there could be stored value. Because of this, we decided to go with accepted/rejected/unknown

PTAL

Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl LGTM 😄

Just a bunch of style nits, I think you forgot to run the linter? Please fix before merging 👍

Thank you for this! I think this was a great solution 😄

extensions/amp-consent/0.1/consent-ui.js Outdated Show resolved Hide resolved
extensions/amp-consent/0.1/test/test-consent-ui.js Outdated Show resolved Hide resolved
const config = dict({
'promptUISrc': 'https//promptUISrc',
});
consentUI =
new ConsentUI(mockInstance, config);
expect(elementByTag(parent, 'iframe')).to.be.null;
consentUI.show();
yield macroTask();
yield macroTask();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you try this with one yield macroTask() ? I've found this works with just one and doesn't need 3? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh! Thank you for catching this. This was my attempt to fix the test, but it didn't work out. I ended up mocking the getConsentInstanceInfo from consent state manager.

test/manual/diy-consent.html Outdated Show resolved Hide resolved
test/manual/diy-consent.html Show resolved Hide resolved
@@ -241,7 +241,7 @@ <h3>Image that is NOT blocked by consent</h3>
"consents": {},
"postPromptUI": "postPromptUI",
"clientConfig": {
"CMP_id": "asdf",
"CMP_id": "test_id",
"other_info": "ahhhh"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhhhhhhh 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha 😂

extensions/amp-consent/0.1/consent-ui.js Show resolved Hide resolved
@zhouyx zhouyx merged commit 824c8b6 into ampproject:master Jan 11, 2019
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* pass stored consent to iframe

* pass string

* nit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants