Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Conversation

@f2prateek
Copy link
Contributor

@f2prateek f2prateek commented Jun 12, 2019

Previously cross domain analytics metadata was stored as client side cookies. This change allows us to set the cookies from a server as httpOnly cookies. We also store the identifier in localStorage To allow the current domain to read it from javascript. This behaviour is behind a flag saveCrossDomainIdInLocalStorage that is off by default.

This also removes some of the extraneous metadata that we don't use (such as the domain of the cookie and timestamp of the cookie), and also removes code to migrate legacy cookies.

lib/index.js Outdated
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.withCredentials = true;
xhr.send();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle XHR errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think so - I'm going to update it so that the localStorage value is only set once the HTTP request completes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

lib/index.js Outdated

var cachedCrossDomainId = this.getCachedCrossDomainId();
if (cachedCrossDomainId) {
callback(null, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do if(callback) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated!

we've verified that the legacy cookies are not in use anymore, hence we can get rid of this migration logic to simplify the client side code.

here's a link to the same change we made on the server (internal link) https://github.com/segmentio/xid/pull/12.
Previously xid metadata was stored as client side cookies. This change allows us to set the cookies from a server as httpOnly cookies. We also store the identifier in localStorage To allow the current domain to read it from javascript. This is only set if the request completes succesfully. This behaviour is behind a flag `saveCrossDomainIdInLocalStorage` that is off by default.

This also removes some of the metadata that we don't use (such as the domain of the cookie and timestamp of the cookie)
@f2prateek f2prateek merged commit 4e4de47 into master Jul 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants