feat: New exposure method to specify variant and payload #62
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.
Summary
This PR adds a new method to the
Experiment
protocol to perform an exposure specifying which variant was exposed to the user.In our project we used all kinds of feature flag providers: initially we had our own solution on our server, then we used Firebase Remote Config, then Optimizely, now Amplitude. As a result, we have a robust internal framework developed to isolate ourselves from third party dependencies that might change... unexpectedly 🥲
To integrate with the Amplitude SDK we implemented the SDK as usual, turned off automatic exposure, and implemented a callback to pass exposure events from our framework to Amplitude's
ExperimentClient.exposure(key: String)
method.Our framework has its own caching and override layers. Our usual workflow is the following:
This implies that once a feature flag value changes, the app will actually display the latest value with a delay of 1 app launch, because:
The issue is that during "app launch 1", Amplitude SDK has the latest flag values, while our layer is serving the old feature flag value from cache. When our callback calls
ExperimentClient.exposure(key: String)
, the SDK loads the variant from its internal data, without knowledge of our cache layer, determines that the flag must be true and reports that to analytics, while the application is actually displaying the previous flag value.This PR introduces a new exposure method to pass explicitly which variant and payload values were exposed to the user, so that our framework can pass accurate exposure information to Amplitude SDK.
Checklist