-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
✨Analytics: CookieWriter #18406
Conversation
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.
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? |
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.
right, let's not print an error
this.readyPromise_.resolve(); | ||
return; | ||
} | ||
if (isProxyOrigin(this.win_.location)) { |
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.
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]; |
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.
let's call them cookieName
& cookieValue
const cookieStr = inputConfig[cookieId]; | ||
if (typeof cookieStr === 'string') { | ||
this.promises_.push(this.expandAndWrite_(cookieId, cookieStr)); | ||
} |
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.
print user error otherwise
} | ||
} | ||
|
||
Promise.all(this.promises_).then(() => { |
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.
nit: this.readyPromise_.resolve(Promise.all(this.promises_))
/** @private {!../../../src/utils/promise.Deferred} */ | ||
this.readyPromise_ = new Deferred(); | ||
|
||
this.init_(config); |
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.
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;
}
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.
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_))
One design change: Instead, for now, cookie write will check the string, and make sure that only string like |
@lannka Please take another look. I added logic to apply stricter rule to the cookieValue format. |
* init commit * linter * address comment * apply stricter rule * disable inabox
* init commit * linter * address comment * apply stricter rule * disable inabox
The PR introduces the change to read the
writeCookies
config. Expand the value and write to cookie.Decision highlights.
<amp-analytics>
's initializationQUERY_PARAM
andLINKER_PARAM
(to be added in separate PR)cc @calebcordry