Skip to content

Commit 6c1f9c5

Browse files
Merge pull request #382 from splitio/impressions_toggle_refactor
[Impressions toggle] Rename `trackImpressions` to `impressionsDisabled`
2 parents 58040dc + 249b078 commit 6c1f9c5

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

src/dtos/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export interface ISplit {
209209
[treatmentName: string]: string
210210
},
211211
sets?: string[],
212-
trackImpressions?: boolean
212+
impressionsDisabled?: boolean
213213
}
214214

215215
// Split definition used in offline mode

src/evaluator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ function getEvaluation(
156156
return evaluation.then(result => {
157157
result.changeNumber = split.getChangeNumber();
158158
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
159-
result.track = splitJSON.trackImpressions;
159+
result.impressionsDisabled = splitJSON.impressionsDisabled;
160160

161161
return result;
162162
});
163163
} else {
164164
evaluation.changeNumber = split.getChangeNumber(); // Always sync and optional
165165
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
166-
evaluation.track = splitJSON.trackImpressions;
166+
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
167167
}
168168
}
169169

src/evaluator/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface IEvaluation {
2525
config?: string | null
2626
}
2727

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

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

src/sdkClient/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
134134
const matchingKey = getMatching(key);
135135
const bucketingKey = getBucketing(key);
136136

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

140140
if (validateSplitExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
@@ -149,7 +149,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
149149
label,
150150
changeNumber: changeNumber as number,
151151
},
152-
track
152+
disabled: impressionsDisabled
153153
});
154154
}
155155

src/sdkManager/__tests__/mocks/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
},
1010
"sets": ["set_a"],
1111
"defaultTreatment": "off",
12-
"trackImpressions": true
12+
"impressionsDisabled": false
1313
}

src/sdkManager/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
3232
configs: splitObject.configurations || {},
3333
sets: splitObject.sets || [],
3434
defaultTreatment: splitObject.defaultTreatment,
35-
trackImpressions: splitObject.trackImpressions !== false
35+
impressionsDisabled: splitObject.impressionsDisabled === true
3636
};
3737
}
3838

src/trackers/__tests__/impressionsTracker.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('Impressions Tracker', () => {
6767

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

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

7272
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
7373
});
@@ -90,7 +90,7 @@ describe('Impressions Tracker', () => {
9090
expect(fakeIntegrationsManager.handleImpression).not.toBeCalled(); // The integrations manager handleImpression method should not be invoked if we haven't tracked impressions.
9191

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

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

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

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

src/trackers/impressionsTracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export function impressionsTrackerFactory(
2626
track(impressions: ImpressionDecorated[], attributes?: SplitIO.Attributes) {
2727
if (settings.userConsent === CONSENT_DECLINED) return;
2828

29-
const impressionsToStore = impressions.filter(({ imp, track }) => {
30-
return track === false ?
29+
const impressionsToStore = impressions.filter(({ imp, disabled }) => {
30+
return disabled ?
3131
noneStrategy.process(imp) :
3232
strategy.process(imp);
3333
});

src/trackers/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type ImpressionDecorated = {
2525
/**
2626
* Whether the impression should be tracked or not
2727
*/
28-
track?: boolean
28+
disabled?: boolean
2929
};
3030

3131
export interface IImpressionsTracker {

types/splitio.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,9 @@ declare namespace SplitIO {
863863
*/
864864
defaultTreatment: string;
865865
/**
866-
* Whether the feature flag has impressions tracking enabled or not.
866+
* Whether the feature flag has impressions tracking disabled or not.
867867
*/
868-
trackImpressions: boolean;
868+
impressionsDisabled: boolean;
869869
};
870870
/**
871871
* A promise that resolves to a feature flag view or null if the feature flag is not found.

0 commit comments

Comments
 (0)