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

Cid optout action #9952

Merged
merged 20 commits into from
Jun 30, 2017
Merged

Cid optout action #9952

merged 20 commits into from
Jun 30, 2017

Conversation

aghassemi
Copy link
Contributor

Closes #9810

return this.getCidService_()
.then(cid => cid.optOutOfCid())
.then(this.dismiss.bind(this))
.catch(reason => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move this into the first then (nested), so that optout always dismisses regardless of error:

cidService()
  .then(cid => cid.optOutOfCid().catch(reason => {}))
  .then(this.dismiss)

@aghassemi aghassemi changed the title [WIP] Cid optout action Cid optout action Jun 27, 2017
.then(this.dismiss.bind(this), reason => {
dev().error('amp-user-notification',
'Failed to opt out of Cid', reason);
// If optout fails, dismiss notification without persisting.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed to me as the most reasonable thing to do if opting out fails, thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

const CID_OPTOUT_STORAGE_KEY = 'amp-cid-optout';

// TODO(aghassemi): replace with real viewer message when implemented.
const CID_OPTOUT_VIEWER_MESSAGE = 'cidOptout';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lannka Does viewer already have support for sending a message to inform user has opted out? For now I am just sending a message with this key

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, they're working on that. the key is cidOptOut

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed the key to match

return isOptedOutOfCid(this.ampdoc).then(optedOut => {
// TODO(aghassemi): null or '' ?
if (optedOut) {
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, although get can already resolve to null, I have seen places that do not check for null (e.g extractClientIdFromGaCookie). Maybe '' is better? thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

'' is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, also moved the check after consent check (since user can optout while consent is pending)

viewerForDoc(ampdoc).sendMessage(CID_OPTOUT_VIEWER_MESSAGE);

// Store the optout bit in storage
return storageForDoc(ampdoc).then(storage => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we want localStorage or storage service here?

Copy link
Member

Choose a reason for hiding this comment

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

This is right.

Copy link
Contributor

Choose a reason for hiding this comment

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

will user be able to ever opt-in again? is there such an API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, do we need that @cramforce?

* @private
*/
getCidService_() {
cidForDoc(this.element);
Copy link
Member

Choose a reason for hiding this comment

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

Missing return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh, extension was not type-checked, added type checking (caught an unquoted JSON issues as well)

Copy link
Member

Choose a reason for hiding this comment

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

WAT

return isOptedOutOfCid(this.ampdoc).then(optedOut => {
// TODO(aghassemi): null or '' ?
if (optedOut) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

'' is better

viewerForDoc(ampdoc).sendMessage(CID_OPTOUT_VIEWER_MESSAGE);

// Store the optout bit in storage
return storageForDoc(ampdoc).then(storage => {
Copy link
Member

Choose a reason for hiding this comment

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

This is right.

const CID_OPTOUT_STORAGE_KEY = 'amp-cid-optout';

// TODO(aghassemi): replace with real viewer message when implemented.
const CID_OPTOUT_VIEWER_MESSAGE = 'cidOptout';
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, they're working on that. the key is cidOptOut

export function optOutOfCid(ampdoc) {

// Tell the viewer that user has opted out.
viewerForDoc(ampdoc).sendMessage(CID_OPTOUT_VIEWER_MESSAGE);
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to move this little thing into cid-impl? so we have centralized place managing the CID APIs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this whole thing is in amp-impl.js, did you mean somewhere else?

.then(this.dismiss.bind(this), reason => {
dev().error('amp-user-notification',
'Failed to opt out of Cid', reason);
// If optout fails, dismiss notification without persisting.
Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

*/
dismiss() {
dismiss(opt_forceNoPersist = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Danger! This requires auditing every call to dismiss, since there may have been a values passed into it through callbacks (the thens are already doing it in this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow good catch Justin. Only issue was registerAction ( which actually was caught after I enabled type checking ).

Anyway now I am a bit worried about this. Should we start preferring explicit () => func() over bind?

Copy link
Member

Choose a reason for hiding this comment

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

Type checking will often have a hard time finding these since the type of the arg will often be ?

@aghassemi
Copy link
Contributor Author

@cramforce @lannka @jridgewell PTAL

Copy link
Member

@cramforce cramforce left a comment

Choose a reason for hiding this comment

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

LG with one comment.

*/
dismiss() {
dismiss(opt_forceNoPersist = false) {
Copy link
Member

Choose a reason for hiding this comment

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

Type checking will often have a hard time finding these since the type of the arg will often be ?

* @return {!Promise}
* @visibleForTesting
*/
export function optOutOfCid(ampdoc) {
Copy link
Contributor

Choose a reason for hiding this comment

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

was this because you had some trouble with the tests?
if so, check out #10200

@aghassemi aghassemi merged commit 4b9718e into ampproject:master Jun 30, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants