Skip to content

Commit

Permalink
Rename trackImpressions to impressionsDisabled
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Dec 26, 2024
1 parent 58040dc commit 249b078
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/dtos/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export interface ISplit {
[treatmentName: string]: string
},
sets?: string[],
trackImpressions?: boolean
impressionsDisabled?: boolean
}

// Split definition used in offline mode
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ function getEvaluation(
return evaluation.then(result => {
result.changeNumber = split.getChangeNumber();
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
result.track = splitJSON.trackImpressions;
result.impressionsDisabled = splitJSON.impressionsDisabled;

return result;
});
} else {
evaluation.changeNumber = split.getChangeNumber(); // Always sync and optional
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
evaluation.track = splitJSON.trackImpressions;
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IEvaluation {
config?: string | null
}

export type IEvaluationResult = IEvaluation & { treatment: string; track?: boolean }
export type IEvaluationResult = IEvaluation & { treatment: string; impressionsDisabled?: boolean }

export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>

Expand Down
4 changes: 2 additions & 2 deletions src/sdkClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
const matchingKey = getMatching(key);
const bucketingKey = getBucketing(key);

const { treatment, label, changeNumber, config = null, track } = evaluation;
const { treatment, label, changeNumber, config = null, impressionsDisabled } = evaluation;
log.info(IMPRESSION, [featureFlagName, matchingKey, treatment, label]);

if (validateSplitExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
Expand All @@ -149,7 +149,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
label,
changeNumber: changeNumber as number,
},
track
disabled: impressionsDisabled
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdkManager/__tests__/mocks/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
},
"sets": ["set_a"],
"defaultTreatment": "off",
"trackImpressions": true
"impressionsDisabled": false
}
2 changes: 1 addition & 1 deletion src/sdkManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
configs: splitObject.configurations || {},
sets: splitObject.sets || [],
defaultTreatment: splitObject.defaultTreatment,
trackImpressions: splitObject.trackImpressions !== false
impressionsDisabled: splitObject.impressionsDisabled === true
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/trackers/__tests__/impressionsTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Impressions Tracker', () => {

expect(fakeImpressionsCache.track).not.toBeCalled(); // cache method should not be called by just creating a tracker

tracker.track([{ imp: imp1 }, { imp: imp2, track: true }, { imp: imp3, track: false }]);
tracker.track([{ imp: imp1 }, { imp: imp2, disabled: false }, { imp: imp3, disabled: true }]);

expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([imp1, imp2]); // Should call the storage track method once we invoke .track() method, passing impressions with `track` enabled
});
Expand All @@ -90,7 +90,7 @@ describe('Impressions Tracker', () => {
expect(fakeIntegrationsManager.handleImpression).not.toBeCalled(); // The integrations manager handleImpression method should not be invoked if we haven't tracked impressions.

// We signal that we actually want to track the queued impressions.
tracker.track([{ imp: fakeImpression }, { imp: fakeImpression2, track: false }], fakeAttributes);
tracker.track([{ imp: fakeImpression }, { imp: fakeImpression2, disabled: true }], fakeAttributes);

expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([fakeImpression]); // Even with a listener, impressions (with `track` enabled) should be sent to the cache
expect(fakeListener.logImpression).not.toBeCalled(); // The listener should not be executed synchronously.
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Impressions Tracker', () => {
expect(fakeImpressionsCache.track).not.toBeCalled(); // storage method should not be called until impressions are tracked.

trackers.forEach(tracker => {
tracker.track([{ imp: impression, track: true }, { imp: impression2 }, { imp: impression3 }]);
tracker.track([{ imp: impression, disabled: false }, { imp: impression2 }, { imp: impression3 }]);

const lastArgs = fakeImpressionsCache.track.mock.calls[fakeImpressionsCache.track.mock.calls.length - 1];

Expand Down
4 changes: 2 additions & 2 deletions src/trackers/impressionsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export function impressionsTrackerFactory(
track(impressions: ImpressionDecorated[], attributes?: SplitIO.Attributes) {
if (settings.userConsent === CONSENT_DECLINED) return;

const impressionsToStore = impressions.filter(({ imp, track }) => {
return track === false ?
const impressionsToStore = impressions.filter(({ imp, disabled }) => {
return disabled ?
noneStrategy.process(imp) :
strategy.process(imp);
});
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type ImpressionDecorated = {
/**
* Whether the impression should be tracked or not
*/
track?: boolean
disabled?: boolean
};

export interface IImpressionsTracker {
Expand Down
4 changes: 2 additions & 2 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,9 @@ declare namespace SplitIO {
*/
defaultTreatment: string;
/**
* Whether the feature flag has impressions tracking enabled or not.
* Whether the feature flag has impressions tracking disabled or not.
*/
trackImpressions: boolean;
impressionsDisabled: boolean;
};
/**
* A promise that resolves to a feature flag view or null if the feature flag is not found.
Expand Down

0 comments on commit 249b078

Please sign in to comment.