Skip to content
Closed
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
8 changes: 3 additions & 5 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Optimizely(config) {
if (typeof config.datafile === 'string' || config.datafile instanceof String) {
config.datafile = JSON.parse(config.datafile);
}

if (config.skipJSONValidation === true) {
this.configObj = projectConfig.createProjectConfig(config.datafile);
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.SKIPPING_JSON_VALIDATION, MODULE_NAME));
Expand Down Expand Up @@ -137,9 +137,6 @@ Optimizely.prototype.activate = function (experimentKey, userId, attributes) {
return variationKey;
}

// remove null values from attributes
attributes = this.__filterEmptyValues(attributes);

this._sendImpressionEvent(experimentKey, variationKey, userId, attributes);

return variationKey;
Expand Down Expand Up @@ -169,6 +166,7 @@ Optimizely.prototype.activate = function (experimentKey, userId, attributes) {
Optimizely.prototype._sendImpressionEvent = function(experimentKey, variationKey, userId, attributes) {
var variationId = projectConfig.getVariationIdFromExperimentAndVariationKey(this.configObj, experimentKey, variationKey);
var experimentId = projectConfig.getExperimentId(this.configObj, experimentKey);
this.__filterEmptyValues(attributes);
var impressionEventOptions = {
attributes: attributes,
clientEngine: this.clientEngine,
Expand Down Expand Up @@ -217,7 +215,7 @@ Optimizely.prototype._sendImpressionEvent = function(experimentKey, variationKey
*/
Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) {
try {

if (!this.isValidInstance) {
this.logger.log(LOG_LEVEL.ERROR, sprintf(LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'track'));
return;
Expand Down
17 changes: 17 additions & 0 deletions packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,23 @@ describe('lib/optimizely', function() {
sinon.assert.calledWith(createdLogger.log, LOG_LEVEL.INFO, 'OPTIMIZELY: Feature test_feature_for_experiment is enabled for user user1.');
});

it('filters null attribute values from the impression event', function () {
var attrsWithNull = {test_attribute: null};
optlyInstance.isFeatureEnabled('test_feature_for_experiment', 'user1', attrsWithNull);
sinon.assert.calledOnce(eventDispatcher.dispatchEvent);
var impressionEvent = eventDispatcher.dispatchEvent.getCalls()[0].args[0];
var impressionEventAttrs = impressionEvent.params.visitors[0].attributes;
var expectedAttrs = [
{
'entity_id': '$opt_bot_filtering',
'key': '$opt_bot_filtering',
'type': 'custom',
'value': true,
},
];
assert.deepEqual(impressionEventAttrs, expectedAttrs);
});

it('returns false and does not dispatch an impression event when feature key is null', function() {
var result = optlyInstance.isFeatureEnabled(null, 'user1', attributes);
assert.strictEqual(result, false);
Expand Down