From 249b07864c8f68b1b5d0e857abefa5c954e57aa6 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 26 Dec 2024 17:00:29 -0300 Subject: [PATCH] Rename trackImpressions to impressionsDisabled --- src/dtos/types.ts | 2 +- src/evaluator/index.ts | 4 ++-- src/evaluator/types.ts | 2 +- src/sdkClient/client.ts | 4 ++-- src/sdkManager/__tests__/mocks/output.json | 2 +- src/sdkManager/index.ts | 2 +- src/trackers/__tests__/impressionsTracker.spec.ts | 6 +++--- src/trackers/impressionsTracker.ts | 4 ++-- src/trackers/types.ts | 2 +- types/splitio.d.ts | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/dtos/types.ts b/src/dtos/types.ts index 41b0edab..7573183c 100644 --- a/src/dtos/types.ts +++ b/src/dtos/types.ts @@ -209,7 +209,7 @@ export interface ISplit { [treatmentName: string]: string }, sets?: string[], - trackImpressions?: boolean + impressionsDisabled?: boolean } // Split definition used in offline mode diff --git a/src/evaluator/index.ts b/src/evaluator/index.ts index d76a9d93..2d06ad10 100644 --- a/src/evaluator/index.ts +++ b/src/evaluator/index.ts @@ -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; } } diff --git a/src/evaluator/types.ts b/src/evaluator/types.ts index 4c968fbd..79bcda18 100644 --- a/src/evaluator/types.ts +++ b/src/evaluator/types.ts @@ -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 diff --git a/src/sdkClient/client.ts b/src/sdkClient/client.ts index 7a280122..1139a272 100644 --- a/src/sdkClient/client.ts +++ b/src/sdkClient/client.ts @@ -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)) { @@ -149,7 +149,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl label, changeNumber: changeNumber as number, }, - track + disabled: impressionsDisabled }); } diff --git a/src/sdkManager/__tests__/mocks/output.json b/src/sdkManager/__tests__/mocks/output.json index ef956a69..52a0b636 100644 --- a/src/sdkManager/__tests__/mocks/output.json +++ b/src/sdkManager/__tests__/mocks/output.json @@ -9,5 +9,5 @@ }, "sets": ["set_a"], "defaultTreatment": "off", - "trackImpressions": true + "impressionsDisabled": false } diff --git a/src/sdkManager/index.ts b/src/sdkManager/index.ts index ef43335e..82423016 100644 --- a/src/sdkManager/index.ts +++ b/src/sdkManager/index.ts @@ -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 }; } diff --git a/src/trackers/__tests__/impressionsTracker.spec.ts b/src/trackers/__tests__/impressionsTracker.spec.ts index 60c7e5e9..1db3875f 100644 --- a/src/trackers/__tests__/impressionsTracker.spec.ts +++ b/src/trackers/__tests__/impressionsTracker.spec.ts @@ -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 }); @@ -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. @@ -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]; diff --git a/src/trackers/impressionsTracker.ts b/src/trackers/impressionsTracker.ts index b56b4a24..0d64a8ed 100644 --- a/src/trackers/impressionsTracker.ts +++ b/src/trackers/impressionsTracker.ts @@ -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); }); diff --git a/src/trackers/types.ts b/src/trackers/types.ts index fb54f3b6..a0dd2dd4 100644 --- a/src/trackers/types.ts +++ b/src/trackers/types.ts @@ -25,7 +25,7 @@ export type ImpressionDecorated = { /** * Whether the impression should be tracked or not */ - track?: boolean + disabled?: boolean }; export interface IImpressionsTracker { diff --git a/types/splitio.d.ts b/types/splitio.d.ts index 113999fc..0cab4b66 100644 --- a/types/splitio.d.ts +++ b/types/splitio.d.ts @@ -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.