Skip to content

Commit a19752b

Browse files
author
Tyler Brandt
authored
chore: 2.1.1 release (#118)
* Fix impression sent from feature experiment variation toggled off. (#117)
1 parent ad3d3de commit a19752b

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

packages/optimizely-sdk/CHANGELOG.MD

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.1
2+
June 19, 2018
3+
4+
* Fix: send impression event for Feature Test with Feature disabled ([#117](https://github.com/optimizely/javascript-sdk/pull/117))
5+
16
## 2.1.0
27
May 24, 2018
38

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,18 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes)
495495

496496
var decision = this.decisionService.getVariationForFeature(feature, userId, attributes);
497497
var variation = decision.variation;
498-
if (!!variation && variation.featureEnabled === true) {
499-
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
498+
if (!!variation) {
500499
if (decision.decisionSource === DECISION_SOURCES.EXPERIMENT) {
500+
// got a variation from the exp, so we track the impression
501501
this._sendImpressionEvent(decision.experiment.key, decision.variation.key, userId, attributes);
502502
}
503-
return true;
504-
} else {
505-
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
506-
return false;
503+
if (variation.featureEnabled === true) {
504+
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
505+
return true;
506+
}
507507
}
508+
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
509+
return false;
508510
};
509511

510512
/**

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

+58-1
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,7 @@ describe('lib/optimizely', function() {
26592659
});
26602660

26612661
describe('when the variation is toggled OFF', function() {
2662+
var result;
26622663
beforeEach(function() {
26632664
var experiment = optlyInstance.configObj.experimentKeyMap.test_shared_feature;
26642665
var variation = experiment.variations[1];
@@ -2667,10 +2668,10 @@ describe('lib/optimizely', function() {
26672668
variation: variation,
26682669
decisionSource: DECISION_SOURCES.EXPERIMENT,
26692670
});
2671+
result = optlyInstance.isFeatureEnabled('shared_feature', 'user1', attributes);
26702672
});
26712673

26722674
it('should return false', function() {
2673-
var result = optlyInstance.isFeatureEnabled('shared_feature', 'user1', attributes);
26742675
assert.strictEqual(result, false);
26752676
sinon.assert.calledOnce(optlyInstance.decisionService.getVariationForFeature);
26762677
var feature = optlyInstance.configObj.featureKeyMap.shared_feature;
@@ -2681,6 +2682,62 @@ describe('lib/optimizely', function() {
26812682
attributes
26822683
);
26832684
});
2685+
2686+
it('should dispatch an impression event', function() {
2687+
sinon.assert.calledOnce(eventDispatcher.dispatchEvent);
2688+
var expectedImpressionEvent = {
2689+
'httpVerb': 'POST',
2690+
'url': 'https://logx.optimizely.com/v1/events',
2691+
'params': {
2692+
'account_id': '572018',
2693+
'project_id': '594001',
2694+
'visitors': [
2695+
{
2696+
'snapshots': [
2697+
{
2698+
'decisions': [
2699+
{
2700+
'campaign_id': '599023',
2701+
'experiment_id': '599028',
2702+
'variation_id': '599027'
2703+
}
2704+
],
2705+
'events': [
2706+
{
2707+
'entity_id': '599023',
2708+
'timestamp': 1509489766569,
2709+
'key': 'campaign_activated',
2710+
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
2711+
}
2712+
]
2713+
}
2714+
],
2715+
'visitor_id': 'user1',
2716+
'attributes': [
2717+
{
2718+
'entity_id': '594014',
2719+
'key': 'test_attribute',
2720+
'type': 'custom',
2721+
'value': 'test_value',
2722+
}, {
2723+
'entity_id': '$opt_bot_filtering',
2724+
'key': '$opt_bot_filtering',
2725+
'type': 'custom',
2726+
'value': true,
2727+
},
2728+
],
2729+
}
2730+
],
2731+
'revision': '35',
2732+
'client_name': 'node-sdk',
2733+
'client_version': enums.NODE_CLIENT_VERSION,
2734+
'anonymize_ip': true
2735+
}
2736+
};
2737+
var callArgs = eventDispatcher.dispatchEvent.getCalls()[0].args;
2738+
assert.deepEqual(callArgs[0], expectedImpressionEvent);
2739+
assert.isFunction(callArgs[1]);
2740+
});
26842741
});
26852742

26862743
describe('when the variation is missing the toggle', function() {

packages/optimizely-sdk/lib/utils/enums/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ exports.CONTROL_ATTRIBUTES = {
137137

138138
exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
139139
exports.NODE_CLIENT_ENGINE = 'node-sdk';
140-
exports.NODE_CLIENT_VERSION = '2.1.0';
140+
exports.NODE_CLIENT_VERSION = '2.1.1';
141141

142142
/*
143143
* Notification types for use with NotificationCenter

packages/optimizely-sdk/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/optimizely-sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/optimizely-sdk",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "JavaScript SDK package for Optimizely X Full Stack",
55
"main": "dist/optimizely.node.js",
66
"browser": "lib/index.browser.js",

0 commit comments

Comments
 (0)