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

✨Analytics: CookieWriter #18406

Merged
merged 5 commits into from
Sep 28, 2018
Merged

✨Analytics: CookieWriter #18406

merged 5 commits into from
Sep 28, 2018

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Sep 27, 2018

The PR introduces the change to read the writeCookies config. Expand the value and write to cookie.

Decision highlights.

  1. cookie writer won't work with proxy origin
  2. cookie writer won't work in FIE (AMPHTML ad)
  3. cookie writer won't work in inabox runtime
  4. cookie writer block <amp-analytics>'s initialization
  5. Start with a whitelist that only contains QUERY_PARAM and LINKER_PARAM(to be added in separate PR)
  6. We agree to support writing static string to cookies, but not empty string.

cc @calebcordry

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

Good work. Some nits.


if (isInFie(this.element_)) {
// TODO: Need the consider the case for shadow doc.
// QQ: Is this even an error since vendor defines it?
Copy link
Contributor

Choose a reason for hiding this comment

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

right, let's not print an error

this.readyPromise_.resolve();
return;
}
if (isProxyOrigin(this.win_.location)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's move cases that we ignore to the beginning (together with FIE).

const ids = Object.keys(inputConfig);
for (let i = 0; i < ids.length; i++) {
const cookieId = ids[i];
const cookieStr = inputConfig[cookieId];
Copy link
Contributor

Choose a reason for hiding this comment

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

let's call them cookieName & cookieValue

const cookieStr = inputConfig[cookieId];
if (typeof cookieStr === 'string') {
this.promises_.push(this.expandAndWrite_(cookieId, cookieStr));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

print user error otherwise

}
}

Promise.all(this.promises_).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this.readyPromise_.resolve(Promise.all(this.promises_))

/** @private {!../../../src/utils/promise.Deferred} */
this.readyPromise_ = new Deferred();

this.init_(config);
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing all the work in constructor, we can move it to whenReady. Actually, we'd rename whenReady to write or run

run() {
  ...
  return readyPromise;
}

Copy link
Contributor Author

@zhouyx zhouyx Sep 27, 2018

Choose a reason for hiding this comment

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

Good idea. I'll switch to write, but one thing I want to make sure is that we only write cookies once no matter how many times the write() has been invoked. To achieve that I'll need to make some extra change.
For example can longer switch to this.readyPromise_.resolve(Promise.all(this.promises_))

@zhouyx
Copy link
Contributor Author

zhouyx commented Sep 27, 2018

One design change:
prefix, static string will no longer be allowed.
This is to prevent case like pre-QUERY_PARAM(abc), where even when there's no abc param, we overwrite the useful cookie with pre-.

Instead, for now, cookie write will check the string, and make sure that only string like QUERY_PARAM() and LINKER_PARAM is allowed.

@zhouyx
Copy link
Contributor Author

zhouyx commented Sep 28, 2018

@lannka Please take another look. I added logic to apply stricter rule to the cookieValue format.

@zhouyx zhouyx merged commit c91d520 into ampproject:master Sep 28, 2018
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Oct 10, 2018
* init commit

* linter

* address comment

* apply stricter rule

* disable inabox
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
* init commit

* linter

* address comment

* apply stricter rule

* disable inabox
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.

3 participants