-
Notifications
You must be signed in to change notification settings - Fork 132
Allow multiple apps v2 #45
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
Merged
Merged
Conversation
This file contains hidden or 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
…on-default instances
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adding support for multiple apps. This is an backwards-compatibility-breaking change.
Changes:
Notes:
API Change:
Amplitude now functions as an instance manager, like what we already do for iOS and Android SDKs. You call Amplitude.getInstance() to fetch a default instance if you want to log events to a single Amplitude App. Updated Readme examples to use this notation. To have separate instances, you assign names to each instance and call Amplitude.getInstance('instance_name') to fetch separate instances.
Existing public methods on Amplitude (logEvent, setUserProperties, etc) are deprecated, but have been mapped to Amplitude.getInstance() equivalents, so they are still usable. Javascript supports object pointers, so we are able to have Amplitude.options point to Amplitude.getInstance.options. Private properties on Amplitude (such as _sessionId) no longer work. Users will need to change references to be on the default instance, for example: Amplitude.getInstance()._sessionId.
The default instance is backwards compatible with existing data. Users who are staying with 1 app should continue using default instance.
Updating cookie data:
To support different settings for different apps, each instance needs its own cookie, so we append the instance name as a suffix to each instance's cookie name.
The default instance continues to use the old cookie name. To maintain backwards compatibility on the default instance, we need to consolidate all cookie data. In cookies we store deviceId, userId, sessionId, lastEventTime, eventId, identifyId, sequenceNumber. We need to migrate all of those values from 3 possible cases:
Updating localStorage keys
We save unsent events to localStorage. To support different apps, we also need to append the instance name as a suffix to the localStorage key names. Like with cookie, the default instance will use the old localStorage keys for backwards compatibilty.
Proxying in the snippet:
We keep the existing Amplitude._q queue, which handles the deprecated public methods on Amplitude. We add a Amplitude_iq = {}, which keeps a mapping of instance names to objects that have their own _q queues. In index we move all the _q to their appropriate instances, and then in runQueuedFunctions we playback all function calls in Amplitude._q and all the function calls in each instances _q.
This feature needs to be released in tandem with a product email update so that people are aware of the API breaks.