Skip to content

Commit

Permalink
fix: optimize variant cache access and exposure tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Sep 18, 2023
1 parent f260654 commit 4523f66
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/experiment-browser/src/experimentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class ExperimentClient implements Client {
): SourceVariant {
let defaultSourceVariant: SourceVariant = {};
// Local storage
const localStorageVariant = this.variants.getAll()[key];
const localStorageVariant = this.variants.get(key);
const isLocalStorageDefault = localStorageVariant?.metadata
?.default as boolean;
if (!isNullOrUndefined(localStorageVariant) && !isLocalStorageDefault) {
Expand Down Expand Up @@ -588,7 +588,7 @@ export class ExperimentClient implements Client {
};
}
// Local storage
const localStorageVariant = this.variants.getAll()[key];
const localStorageVariant = this.variants.get(key);
const isLocalStorageDefault = localStorageVariant?.metadata
?.default as boolean;
if (!isNullOrUndefined(localStorageVariant) && !isLocalStorageDefault) {
Expand Down Expand Up @@ -839,13 +839,15 @@ export class ExperimentClient implements Client {
variant: Variant | undefined,
source: VariantSource | undefined,
): void {
const user = this.addContext(this.getUser());
const event = exposureEvent(user, key, variant, source);
if (isFallback(source) || !variant?.value) {
this.analyticsProvider?.unsetUserProperty?.(event);
} else if (variant?.value) {
this.analyticsProvider?.setUserProperty?.(event);
this.analyticsProvider?.track(event);
if (this.analyticsProvider) {
const user = this.addContext(this.getUser());
const event = exposureEvent(user, key, variant, source);
if (isFallback(source) || !variant?.value) {
this.analyticsProvider?.unsetUserProperty?.(event);
} else if (variant?.value) {
this.analyticsProvider?.setUserProperty?.(event);
this.analyticsProvider?.track(event);
}
}
}

Expand Down

0 comments on commit 4523f66

Please sign in to comment.