Skip to content

fix(event-tags): do not exclude falsy revenue and event values in the event payload #213

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 2 commits into from
Jan 28, 2019
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: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/event_builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, logger) {

if (eventTags) {
var revenue = eventTagUtils.getRevenueValue(eventTags, logger);
if (revenue) {
if (revenue !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check for undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah because the getRevenueValue function will always return either null or the parsed value

Copy link
Contributor

Choose a reason for hiding this comment

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

The most robust (redundant) solution would be to check whether the returned value is a number, but I'm not sure it matters

eventDict[enums.RESERVED_EVENT_KEYWORDS.REVENUE] = revenue;
}

var eventValue = eventTagUtils.getEventValue(eventTags, logger);
if (eventValue) {
if (eventValue !== null) {
eventDict[enums.RESERVED_EVENT_KEYWORDS.VALUE] = eventValue;
}

Expand Down
96 changes: 96 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 @@ -1097,6 +1097,54 @@ describe('lib/core/event_builder', function() {
assert.deepEqual(actualParams, expectedParams);
});

it('should include revenue value of 0 in the event object', function() {
var expectedParams = {
url: 'https://logx.optimizely.com/v1/events',
httpVerb: 'POST',
params: {
'client_version': packageJSON.version,
'project_id': '111001',
'visitors': [{
'attributes': [],
'visitor_id': 'testUser',
'snapshots': [{
'events': [{
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
'tags': {
'revenue': 0
},
'timestamp': Math.round(new Date().getTime()),
'revenue': 0,
'key': 'testEvent',
'entity_id': '111095'
}]
}]
}],
'account_id': '12001',
'client_name': 'node-sdk',
'revision': '42',
'anonymize_ip': false,
'enrich_decisions': true,
},
};

var eventOptions = {
clientEngine: 'node-sdk',
clientVersion: packageJSON.version,
configObj: configObj,
eventKey: 'testEvent',
eventTags: {
'revenue': 0,
},
logger: mockLogger,
userId: 'testUser',
};

var actualParams = eventBuilder.getConversionEvent(eventOptions);

assert.deepEqual(actualParams, expectedParams);
});

describe('and the revenue value is invalid', function() {
it('should not include the revenue value in the event object', function() {
var expectedParams = {
Expand Down Expand Up @@ -1200,6 +1248,54 @@ describe('lib/core/event_builder', function() {
assert.deepEqual(actualParams, expectedParams);
});

it('should include the falsy event values in the event object', function() {
var expectedParams = {
url: 'https://logx.optimizely.com/v1/events',
httpVerb: 'POST',
params: {
'client_version': packageJSON.version,
'project_id': '111001',
'visitors': [{
'attributes': [],
'visitor_id': 'testUser',
'snapshots': [{
'events': [{
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
'tags': {
'value': '0.0'
},
'timestamp': Math.round(new Date().getTime()),
'value': 0.0,
'key': 'testEvent',
'entity_id': '111095'
}]
}]
}],
'account_id': '12001',
'client_name': 'node-sdk',
'revision': '42',
'anonymize_ip': false,
'enrich_decisions': true,
},
};

var eventOptions = {
clientEngine: 'node-sdk',
clientVersion: packageJSON.version,
configObj: configObj,
eventKey: 'testEvent',
eventTags: {
'value': '0.0',
},
logger: mockLogger,
userId: 'testUser',
};

var actualParams = eventBuilder.getConversionEvent(eventOptions);

assert.deepEqual(actualParams, expectedParams);
});

describe('and the event value is invalid', function() {
it('should not include the event value in the event object', function() {
var expectedParams = {
Expand Down
1 change: 0 additions & 1 deletion packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) {

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

var conversionEventOptions = {
attributes: attributes,
clientEngine: this.clientEngine,
Expand Down