-
Notifications
You must be signed in to change notification settings - Fork 134
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
fix: assign domain after cookie storage options are given #528
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
im curious how this impacts sdk usages that did not use defer init. would they have existing cookie without the domain suffix? if we move it up to this line, then would it look for cookie with the domain prefix, which it may not find?
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.
It is really interesting that we actually have two cookie names: with domain and without domain.


And it does not defer init

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.
When initializing the metadata storage without domain, all cookies saved by the metadata storage does not include the domain suffix. After domain is assigned to
this.options.domain
, SDK looks for cookie but cannot find it, and then a new cookies with domain suffix is created. I think this is the flow.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.
Hmm not sure about that, but isn't metadata storage only instantiated once for the most part? then does this mean even if
this.options.domain
changes, it would still use the initial storage key?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.
If deferInitialization is not set, then it is only one metadata storage instance. But for defer init, a new metadata storage instance is initialized with the new domain value.
If
this.options.domain
changes, the storage key is still the initial one.Here we have two options:
this.options.domain = this.cookieStorage.options().domain;
before initialize metadata storage, so the cookies include domain suffix.this.options.domain = this.cookieStorage.options().domain;
after the defer init check, so the metadata storage is initialized again, the storage key is still the same.I pick the first one option, but I am thinking if you have any other concern.
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.
From
setDomain
method, thethis.options.domain
is updated immediately.Amplitude-JavaScript/src/amplitude-client.js
Lines 862 to 880 in 52abaf0
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.
Yeah my concern is what I mentioned in my first comment. Like if they don't defer init, which is default behavior, and client devices have an existing cookie key with no suffix. If we go with option 1, then it will not find the existing cookies right? If it does not find existing cookies, then it will generate new session ids and device ids and potentially disassociate events that would have been for the same amplitude ID, I'm thinking.
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. I think it is a valid concern. I will move to option 2.