Skip to content

feat: Add enabled to decision metadata #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/optimizely-sdk/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- 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))

### New Features

- 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))

## [4.4.1] - November 5, 2020

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ImpressionConfig {
decisionObj: DecisionObj;
userId: string;
flagKey: string;
enabled: boolean;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
Expand Down Expand Up @@ -65,6 +66,7 @@ interface ImpressionEvent {
ruleKey: string,
flagKey: string,
ruleType: string,
enabled: boolean,
}

interface ConversionConfig {
Expand Down
18 changes: 11 additions & 7 deletions packages/optimizely-sdk/lib/core/event_builder/event_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ var logger = getLogger('EVENT_BUILDER');

/**
* Creates an ImpressionEvent object from decision data
* @param {Object} config
* @param {Object} config.decisionObj
* @param {String} config.userId
* @param {Object} config.userAttributes
* @param {String} config.clientEngine
* @param {String} config.clientVersion
* @return {Object} an ImpressionEvent object
* @param {Object} config
* @param {Object} config.decisionObj
* @param {String} config.userId
* @param {String} config.flagKey
* @param {boolean} config.enabled
* @param {Object} config.userAttributes
* @param {String} config.clientEngine
* @param {String} config.clientVersion
* @return {Object} an ImpressionEvent object
*/
export var buildImpressionEvent = function(config) {
var configObj = config.configObj;
var decisionObj = config.decisionObj;
var userId = config.userId;
var flagKey = config.flagKey;
var enabled = config.enabled;
var userAttributes = config.userAttributes;
var clientEngine = config.clientEngine;
var clientVersion = config.clientVersion;
Expand Down Expand Up @@ -95,6 +98,7 @@ export var buildImpressionEvent = function(config) {
ruleKey: experimentKey,
flagKey: flagKey,
ruleType: ruleType,
enabled: enabled,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('lib/event_builder/event_helpers', function() {
var result = buildImpressionEvent({
configObj: configObj,
decisionObj: decision,
enabled: true,
flagKey: 'flagkey1',
userId: 'user1',
userAttributes: {
Expand Down Expand Up @@ -140,6 +141,7 @@ describe('lib/event_builder/event_helpers', function() {
ruleKey: "exp1",
flagKey: 'flagkey1',
ruleType: 'experiment',
enabled: true,
});
});
});
Expand Down Expand Up @@ -184,6 +186,7 @@ describe('lib/event_builder/event_helpers', function() {
configObj: configObj,
decisionObj: decision,
flagKey: 'flagkey1',
enabled: false,
userId: 'user1',
userAttributes: {
plan_type: 'bronze',
Expand Down Expand Up @@ -233,6 +236,7 @@ describe('lib/event_builder/event_helpers', function() {
ruleKey: "exp1",
flagKey: 'flagkey1',
ruleType: 'experiment',
enabled: false,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/optimizely-sdk/lib/core/event_builder/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ImpressionOptions {
experimentId: string | null;
ruleKey: string;
flagKey: string;
enabled: boolean;
ruleType: string;
eventKey?: string;
variationId: string | null;
Expand Down
46 changes: 25 additions & 21 deletions packages/optimizely-sdk/lib/core/event_builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ function getCommonEventParams(options) {

/**
* Creates object of params specific to impression events
* @param {Object} configObj Object representing project configuration
* @param {string} experimentId ID of experiment for which impression needs to be recorded
* @param {string} variationId ID for variation which would be presented to user
* @param {string} ruleKey Key of experiment for which impression needs to be recorded
* @param {string} ruleType Type for the decision source
* @param {string} flagKey Key for a feature flag
* @return {Object} Impression event params
* @param {Object} configObj Object representing project configuration
* @param {string} experimentId ID of experiment for which impression needs to be recorded
* @param {string} variationId ID for variation which would be presented to user
* @param {string} ruleKey Key of experiment for which impression needs to be recorded
* @param {string} ruleType Type for the decision source
* @param {string} flagKey Key for a feature flag
* @param {boolean} enabled Boolean representing if feature is enabled
* @return {Object} Impression event params
*/
function getImpressionEventParams(configObj, experimentId, variationId, ruleKey, ruleType, flagKey) {
function getImpressionEventParams(configObj, experimentId, variationId, ruleKey, ruleType, flagKey, enabled) {
let campaignId = null;
if (experimentId !== null) {
campaignId = projectConfig.getLayerId(configObj, experimentId);
Expand All @@ -120,6 +121,7 @@ function getImpressionEventParams(configObj, experimentId, variationId, ruleKey,
rule_key: ruleKey,
rule_type: ruleType,
variation_key: variationKey,
enabled: enabled,
}
},
],
Expand Down Expand Up @@ -176,18 +178,19 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, logger) {

/**
* Create impression event params to be sent to the logging endpoint
* @param {Object} options Object containing values needed to build impression event
* @param {Object} options.attributes Object representing user attributes and values which need to be recorded
* @param {string} options.clientEngine The client we are using: node or javascript
* @param {string} options.clientVersion The version of the client
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
* @param {string} options.experimentId Experiment for which impression needs to be recorded
* @param {string} options.userId ID for user
* @param {string} options.variationId ID for variation which would be presented to user
* @param {string} options.ruleKey Key of an experiment for which impression needs to be recorded
* @param {string} options.ruleType Type for the decision source
* @param {string} options.flagKey Key for a feature flag
* @return {Object} Params to be used in impression event logging endpoint call
* @param {Object} options Object containing values needed to build impression event
* @param {Object} options.attributes Object representing user attributes and values which need to be recorded
* @param {string} options.clientEngine The client we are using: node or javascript
* @param {string} options.clientVersion The version of the client
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
* @param {string} options.experimentId Experiment for which impression needs to be recorded
* @param {string} options.userId ID for user
* @param {string} options.variationId ID for variation which would be presented to user
* @param {string} options.ruleKey Key of an experiment for which impression needs to be recorded
* @param {string} options.ruleType Type for the decision source
* @param {string} options.flagKey Key for a feature flag
* @param {boolean} options.enabled Boolean representing if feature is enabled
* @return {Object} Params to be used in impression event logging endpoint call
*/
export var getImpressionEvent = function(options) {
var impressionEvent = {
Expand All @@ -203,7 +206,8 @@ export var getImpressionEvent = function(options) {
options.variationId,
options.ruleKey,
options.ruleType,
options.flagKey
options.flagKey,
options.enabled,
);
// combine Event params into visitor obj
commonParams.visitors[0].snapshots.push(impressionEventParams);
Expand Down
18 changes: 18 additions & 0 deletions packages/optimizely-sdk/lib/core/event_builder/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: true,
},
},
],
Expand Down Expand Up @@ -96,6 +97,7 @@ describe('lib/core/event_builder', function() {
experimentId: '111127',
ruleKey: 'exp1',
flagKey: 'flagKey1',
enabled: true,
ruleType: 'experiment',
variationId: '111128',
userId: 'testUser',
Expand Down Expand Up @@ -136,6 +138,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: false,
},
},
],
Expand Down Expand Up @@ -167,6 +170,7 @@ describe('lib/core/event_builder', function() {
variationId: '111128',
ruleKey: 'exp1',
flagKey: 'flagKey1',
enabled: false,
ruleType: 'experiment',
userId: 'testUser',
};
Expand Down Expand Up @@ -206,6 +210,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: true,
},
},
],
Expand Down Expand Up @@ -238,6 +243,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp1',
flagKey: 'flagKey1',
ruleType: 'experiment',
enabled: true,
variationId: '111128',
userId: 'testUser',
};
Expand Down Expand Up @@ -277,6 +283,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: true,
},
},
],
Expand Down Expand Up @@ -309,6 +316,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp1',
flagKey: 'flagKey1',
ruleType: 'experiment',
enabled: true,
variationId: '111128',
userId: 'testUser',
};
Expand Down Expand Up @@ -341,6 +349,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: false,
},
},
],
Expand Down Expand Up @@ -373,6 +382,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp1',
flagKey: 'flagKey1',
ruleType: 'experiment',
enabled: false,
variationId: '111128',
userId: 'testUser',
logger: mockLogger,
Expand Down Expand Up @@ -420,6 +430,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp2',
rule_type: 'experiment',
variation_key: 'var',
enabled: false,
},
},
],
Expand Down Expand Up @@ -452,6 +463,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp2',
flagKey: 'flagKey2',
ruleType: 'experiment',
enabled: false,
variationId: '595008',
userId: 'testUser',
};
Expand Down Expand Up @@ -499,6 +511,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp2',
rule_type: 'experiment',
variation_key: 'var',
enabled: false,
},
},
],
Expand Down Expand Up @@ -531,6 +544,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp2',
flagKey: 'flagKey2',
ruleType: 'experiment',
enabled: false,
variationId: '595008',
userId: 'testUser',
};
Expand Down Expand Up @@ -588,6 +602,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: false,
},
},
],
Expand Down Expand Up @@ -625,6 +640,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp1',
flagKey: 'flagKey1',
ruleType: 'experiment',
enabled: false,
variationId: '111128',
userId: 'testUser',
};
Expand Down Expand Up @@ -676,6 +692,7 @@ describe('lib/core/event_builder', function() {
rule_key: 'exp1',
rule_type: 'experiment',
variation_key: 'control',
enabled: true,
},
},
],
Expand Down Expand Up @@ -714,6 +731,7 @@ describe('lib/core/event_builder', function() {
ruleKey: 'exp1',
flagKey: 'flagKey1',
ruleType: 'experiment',
enabled: true,
variationId: '111128',
userId: 'testUser',
};
Expand Down
Loading