Skip to content

Commit 170ab61

Browse files
authored
feat: Add enabled to decision metadata (#619)
* Add enabled to metadata * Update comments * Upgrade event-processor to 0.8.0 * Fix unit tests * Update changelog
1 parent 1fb0013 commit 170ab61

File tree

11 files changed

+93
-35
lines changed

11 files changed

+93
-35
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
- In `Optimizely` class, use `any` type when assigning the return value of `setTimeout`. This is to allow it to type check regardless of whether it uses the browser or Node version of `setTimeout` ([PR #623](https://github.com/optimizely/javascript-sdk/pull/623)), ([Issue #622](https://github.com/optimizely/javascript-sdk/issues/622))
1212

13+
### New Features
14+
15+
- Added `enabled` field to decision metadata structure to support upcoming application-controlled introduction of tracking for non-experiment Flag decisions ([#619](https://github.com/optimizely/javascript-sdk/pull/619))
16+
1317
## [4.4.1] - November 5, 2020
1418

1519
### Bug fixes

packages/optimizely-sdk/lib/core/event_builder/event_helpers.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface ImpressionConfig {
2121
decisionObj: DecisionObj;
2222
userId: string;
2323
flagKey: string;
24+
enabled: boolean;
2425
userAttributes?: UserAttributes;
2526
clientEngine: string;
2627
clientVersion: string;
@@ -65,6 +66,7 @@ interface ImpressionEvent {
6566
ruleKey: string,
6667
flagKey: string,
6768
ruleType: string,
69+
enabled: boolean,
6870
}
6971

7072
interface ConversionConfig {

packages/optimizely-sdk/lib/core/event_builder/event_helpers.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ var logger = getLogger('EVENT_BUILDER');
2525

2626
/**
2727
* Creates an ImpressionEvent object from decision data
28-
* @param {Object} config
29-
* @param {Object} config.decisionObj
30-
* @param {String} config.userId
31-
* @param {Object} config.userAttributes
32-
* @param {String} config.clientEngine
33-
* @param {String} config.clientVersion
34-
* @return {Object} an ImpressionEvent object
28+
* @param {Object} config
29+
* @param {Object} config.decisionObj
30+
* @param {String} config.userId
31+
* @param {String} config.flagKey
32+
* @param {boolean} config.enabled
33+
* @param {Object} config.userAttributes
34+
* @param {String} config.clientEngine
35+
* @param {String} config.clientVersion
36+
* @return {Object} an ImpressionEvent object
3537
*/
3638
export var buildImpressionEvent = function(config) {
3739
var configObj = config.configObj;
3840
var decisionObj = config.decisionObj;
3941
var userId = config.userId;
4042
var flagKey = config.flagKey;
43+
var enabled = config.enabled;
4144
var userAttributes = config.userAttributes;
4245
var clientEngine = config.clientEngine;
4346
var clientVersion = config.clientVersion;
@@ -95,6 +98,7 @@ export var buildImpressionEvent = function(config) {
9598
ruleKey: experimentKey,
9699
flagKey: flagKey,
97100
ruleType: ruleType,
101+
enabled: enabled,
98102
};
99103
};
100104

packages/optimizely-sdk/lib/core/event_builder/event_helpers.tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe('lib/event_builder/event_helpers', function() {
9090
var result = buildImpressionEvent({
9191
configObj: configObj,
9292
decisionObj: decision,
93+
enabled: true,
9394
flagKey: 'flagkey1',
9495
userId: 'user1',
9596
userAttributes: {
@@ -140,6 +141,7 @@ describe('lib/event_builder/event_helpers', function() {
140141
ruleKey: "exp1",
141142
flagKey: 'flagkey1',
142143
ruleType: 'experiment',
144+
enabled: true,
143145
});
144146
});
145147
});
@@ -184,6 +186,7 @@ describe('lib/event_builder/event_helpers', function() {
184186
configObj: configObj,
185187
decisionObj: decision,
186188
flagKey: 'flagkey1',
189+
enabled: false,
187190
userId: 'user1',
188191
userAttributes: {
189192
plan_type: 'bronze',
@@ -233,6 +236,7 @@ describe('lib/event_builder/event_helpers', function() {
233236
ruleKey: "exp1",
234237
flagKey: 'flagkey1',
235238
ruleType: 'experiment',
239+
enabled: false,
236240
});
237241
});
238242
});

packages/optimizely-sdk/lib/core/event_builder/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface ImpressionOptions {
2525
experimentId: string | null;
2626
ruleKey: string;
2727
flagKey: string;
28+
enabled: boolean;
2829
ruleType: string;
2930
eventKey?: string;
3031
variationId: string | null;

packages/optimizely-sdk/lib/core/event_builder/index.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ function getCommonEventParams(options) {
9090

9191
/**
9292
* Creates object of params specific to impression events
93-
* @param {Object} configObj Object representing project configuration
94-
* @param {string} experimentId ID of experiment for which impression needs to be recorded
95-
* @param {string} variationId ID for variation which would be presented to user
96-
* @param {string} ruleKey Key of experiment for which impression needs to be recorded
97-
* @param {string} ruleType Type for the decision source
98-
* @param {string} flagKey Key for a feature flag
99-
* @return {Object} Impression event params
93+
* @param {Object} configObj Object representing project configuration
94+
* @param {string} experimentId ID of experiment for which impression needs to be recorded
95+
* @param {string} variationId ID for variation which would be presented to user
96+
* @param {string} ruleKey Key of experiment for which impression needs to be recorded
97+
* @param {string} ruleType Type for the decision source
98+
* @param {string} flagKey Key for a feature flag
99+
* @param {boolean} enabled Boolean representing if feature is enabled
100+
* @return {Object} Impression event params
100101
*/
101-
function getImpressionEventParams(configObj, experimentId, variationId, ruleKey, ruleType, flagKey) {
102+
function getImpressionEventParams(configObj, experimentId, variationId, ruleKey, ruleType, flagKey, enabled) {
102103
let campaignId = null;
103104
if (experimentId !== null) {
104105
campaignId = projectConfig.getLayerId(configObj, experimentId);
@@ -120,6 +121,7 @@ function getImpressionEventParams(configObj, experimentId, variationId, ruleKey,
120121
rule_key: ruleKey,
121122
rule_type: ruleType,
122123
variation_key: variationKey,
124+
enabled: enabled,
123125
}
124126
},
125127
],
@@ -176,18 +178,19 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, logger) {
176178

177179
/**
178180
* Create impression event params to be sent to the logging endpoint
179-
* @param {Object} options Object containing values needed to build impression event
180-
* @param {Object} options.attributes Object representing user attributes and values which need to be recorded
181-
* @param {string} options.clientEngine The client we are using: node or javascript
182-
* @param {string} options.clientVersion The version of the client
183-
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
184-
* @param {string} options.experimentId Experiment for which impression needs to be recorded
185-
* @param {string} options.userId ID for user
186-
* @param {string} options.variationId ID for variation which would be presented to user
187-
* @param {string} options.ruleKey Key of an experiment for which impression needs to be recorded
188-
* @param {string} options.ruleType Type for the decision source
189-
* @param {string} options.flagKey Key for a feature flag
190-
* @return {Object} Params to be used in impression event logging endpoint call
181+
* @param {Object} options Object containing values needed to build impression event
182+
* @param {Object} options.attributes Object representing user attributes and values which need to be recorded
183+
* @param {string} options.clientEngine The client we are using: node or javascript
184+
* @param {string} options.clientVersion The version of the client
185+
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
186+
* @param {string} options.experimentId Experiment for which impression needs to be recorded
187+
* @param {string} options.userId ID for user
188+
* @param {string} options.variationId ID for variation which would be presented to user
189+
* @param {string} options.ruleKey Key of an experiment for which impression needs to be recorded
190+
* @param {string} options.ruleType Type for the decision source
191+
* @param {string} options.flagKey Key for a feature flag
192+
* @param {boolean} options.enabled Boolean representing if feature is enabled
193+
* @return {Object} Params to be used in impression event logging endpoint call
191194
*/
192195
export var getImpressionEvent = function(options) {
193196
var impressionEvent = {
@@ -203,7 +206,8 @@ export var getImpressionEvent = function(options) {
203206
options.variationId,
204207
options.ruleKey,
205208
options.ruleType,
206-
options.flagKey
209+
options.flagKey,
210+
options.enabled,
207211
);
208212
// combine Event params into visitor obj
209213
commonParams.visitors[0].snapshots.push(impressionEventParams);

packages/optimizely-sdk/lib/core/event_builder/index.tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('lib/core/event_builder', function() {
6666
rule_key: 'exp1',
6767
rule_type: 'experiment',
6868
variation_key: 'control',
69+
enabled: true,
6970
},
7071
},
7172
],
@@ -96,6 +97,7 @@ describe('lib/core/event_builder', function() {
9697
experimentId: '111127',
9798
ruleKey: 'exp1',
9899
flagKey: 'flagKey1',
100+
enabled: true,
99101
ruleType: 'experiment',
100102
variationId: '111128',
101103
userId: 'testUser',
@@ -136,6 +138,7 @@ describe('lib/core/event_builder', function() {
136138
rule_key: 'exp1',
137139
rule_type: 'experiment',
138140
variation_key: 'control',
141+
enabled: false,
139142
},
140143
},
141144
],
@@ -167,6 +170,7 @@ describe('lib/core/event_builder', function() {
167170
variationId: '111128',
168171
ruleKey: 'exp1',
169172
flagKey: 'flagKey1',
173+
enabled: false,
170174
ruleType: 'experiment',
171175
userId: 'testUser',
172176
};
@@ -206,6 +210,7 @@ describe('lib/core/event_builder', function() {
206210
rule_key: 'exp1',
207211
rule_type: 'experiment',
208212
variation_key: 'control',
213+
enabled: true,
209214
},
210215
},
211216
],
@@ -238,6 +243,7 @@ describe('lib/core/event_builder', function() {
238243
ruleKey: 'exp1',
239244
flagKey: 'flagKey1',
240245
ruleType: 'experiment',
246+
enabled: true,
241247
variationId: '111128',
242248
userId: 'testUser',
243249
};
@@ -277,6 +283,7 @@ describe('lib/core/event_builder', function() {
277283
rule_key: 'exp1',
278284
rule_type: 'experiment',
279285
variation_key: 'control',
286+
enabled: true,
280287
},
281288
},
282289
],
@@ -309,6 +316,7 @@ describe('lib/core/event_builder', function() {
309316
ruleKey: 'exp1',
310317
flagKey: 'flagKey1',
311318
ruleType: 'experiment',
319+
enabled: true,
312320
variationId: '111128',
313321
userId: 'testUser',
314322
};
@@ -341,6 +349,7 @@ describe('lib/core/event_builder', function() {
341349
rule_key: 'exp1',
342350
rule_type: 'experiment',
343351
variation_key: 'control',
352+
enabled: false,
344353
},
345354
},
346355
],
@@ -373,6 +382,7 @@ describe('lib/core/event_builder', function() {
373382
ruleKey: 'exp1',
374383
flagKey: 'flagKey1',
375384
ruleType: 'experiment',
385+
enabled: false,
376386
variationId: '111128',
377387
userId: 'testUser',
378388
logger: mockLogger,
@@ -420,6 +430,7 @@ describe('lib/core/event_builder', function() {
420430
rule_key: 'exp2',
421431
rule_type: 'experiment',
422432
variation_key: 'var',
433+
enabled: false,
423434
},
424435
},
425436
],
@@ -452,6 +463,7 @@ describe('lib/core/event_builder', function() {
452463
ruleKey: 'exp2',
453464
flagKey: 'flagKey2',
454465
ruleType: 'experiment',
466+
enabled: false,
455467
variationId: '595008',
456468
userId: 'testUser',
457469
};
@@ -499,6 +511,7 @@ describe('lib/core/event_builder', function() {
499511
rule_key: 'exp2',
500512
rule_type: 'experiment',
501513
variation_key: 'var',
514+
enabled: false,
502515
},
503516
},
504517
],
@@ -531,6 +544,7 @@ describe('lib/core/event_builder', function() {
531544
ruleKey: 'exp2',
532545
flagKey: 'flagKey2',
533546
ruleType: 'experiment',
547+
enabled: false,
534548
variationId: '595008',
535549
userId: 'testUser',
536550
};
@@ -588,6 +602,7 @@ describe('lib/core/event_builder', function() {
588602
rule_key: 'exp1',
589603
rule_type: 'experiment',
590604
variation_key: 'control',
605+
enabled: false,
591606
},
592607
},
593608
],
@@ -625,6 +640,7 @@ describe('lib/core/event_builder', function() {
625640
ruleKey: 'exp1',
626641
flagKey: 'flagKey1',
627642
ruleType: 'experiment',
643+
enabled: false,
628644
variationId: '111128',
629645
userId: 'testUser',
630646
};
@@ -676,6 +692,7 @@ describe('lib/core/event_builder', function() {
676692
rule_key: 'exp1',
677693
rule_type: 'experiment',
678694
variation_key: 'control',
695+
enabled: true,
679696
},
680697
},
681698
],
@@ -714,6 +731,7 @@ describe('lib/core/event_builder', function() {
714731
ruleKey: 'exp1',
715732
flagKey: 'flagKey1',
716733
ruleType: 'experiment',
734+
enabled: true,
717735
variationId: '111128',
718736
userId: 'testUser',
719737
};

0 commit comments

Comments
 (0)