Skip to content

Fix impression sent from feature experiment variation toggled off. #117

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 1 commit into from
Jun 19, 2018
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
14 changes: 8 additions & 6 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,18 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes)

var decision = this.decisionService.getVariationForFeature(feature, userId, attributes);
var variation = decision.variation;
if (!!variation && variation.featureEnabled === true) {
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
if (!!variation) {
if (decision.decisionSource === DECISION_SOURCES.EXPERIMENT) {
// got a variation from the exp, so we track the impression
this._sendImpressionEvent(decision.experiment.key, decision.variation.key, userId, attributes);
}
return true;
} else {
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
return false;
if (variation.featureEnabled === true) {
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
return true;
}
}
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM I see the early return. Trixy

return false;
};

/**
Expand Down
59 changes: 58 additions & 1 deletion packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,7 @@ describe('lib/optimizely', function() {
});

describe('when the variation is toggled OFF', function() {
var result;
beforeEach(function() {
var experiment = optlyInstance.configObj.experimentKeyMap.test_shared_feature;
var variation = experiment.variations[1];
Expand All @@ -2667,10 +2668,10 @@ describe('lib/optimizely', function() {
variation: variation,
decisionSource: DECISION_SOURCES.EXPERIMENT,
});
result = optlyInstance.isFeatureEnabled('shared_feature', 'user1', attributes);
});

it('should return false', function() {
var result = optlyInstance.isFeatureEnabled('shared_feature', 'user1', attributes);
assert.strictEqual(result, false);
sinon.assert.calledOnce(optlyInstance.decisionService.getVariationForFeature);
var feature = optlyInstance.configObj.featureKeyMap.shared_feature;
Expand All @@ -2681,6 +2682,62 @@ describe('lib/optimizely', function() {
attributes
);
});

it('should dispatch an impression event', function() {
sinon.assert.calledOnce(eventDispatcher.dispatchEvent);
var expectedImpressionEvent = {
'httpVerb': 'POST',
'url': 'https://logx.optimizely.com/v1/events',
'params': {
'account_id': '572018',
'project_id': '594001',
'visitors': [
{
'snapshots': [
{
'decisions': [
{
'campaign_id': '599023',
'experiment_id': '599028',
'variation_id': '599027'
}
],
'events': [
{
'entity_id': '599023',
'timestamp': 1509489766569,
'key': 'campaign_activated',
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
}
]
}
],
'visitor_id': 'user1',
'attributes': [
{
'entity_id': '594014',
'key': 'test_attribute',
'type': 'custom',
'value': 'test_value',
}, {
'entity_id': '$opt_bot_filtering',
'key': '$opt_bot_filtering',
'type': 'custom',
'value': true,
},
],
}
],
'revision': '35',
'client_name': 'node-sdk',
'client_version': enums.NODE_CLIENT_VERSION,
'anonymize_ip': true
}
};
var callArgs = eventDispatcher.dispatchEvent.getCalls()[0].args;
assert.deepEqual(callArgs[0], expectedImpressionEvent);
assert.isFunction(callArgs[1]);
});
});

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