Skip to content

Commit 827d633

Browse files
author
Mike Ng
committed
fix(event-tags): do not exclude falsy revenue and event values in the event payload.
1 parent d6e6809 commit 827d633

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, logger) {
133133

134134
if (eventTags) {
135135
var revenue = eventTagUtils.getRevenueValue(eventTags, logger);
136-
if (revenue) {
136+
if (revenue !== null) {
137137
eventDict[enums.RESERVED_EVENT_KEYWORDS.REVENUE] = revenue;
138138
}
139139

140140
var eventValue = eventTagUtils.getEventValue(eventTags, logger);
141-
if (eventValue) {
141+
if (eventValue !== null) {
142142
eventDict[enums.RESERVED_EVENT_KEYWORDS.VALUE] = eventValue;
143143
}
144144

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,54 @@ describe('lib/core/event_builder', function() {
10971097
assert.deepEqual(actualParams, expectedParams);
10981098
});
10991099

1100+
it('should include falsy revenue values in the event object', function() {
1101+
var expectedParams = {
1102+
url: 'https://logx.optimizely.com/v1/events',
1103+
httpVerb: 'POST',
1104+
params: {
1105+
'client_version': packageJSON.version,
1106+
'project_id': '111001',
1107+
'visitors': [{
1108+
'attributes': [],
1109+
'visitor_id': 'testUser',
1110+
'snapshots': [{
1111+
'events': [{
1112+
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
1113+
'tags': {
1114+
'revenue': 0
1115+
},
1116+
'timestamp': Math.round(new Date().getTime()),
1117+
'revenue': 0,
1118+
'key': 'testEvent',
1119+
'entity_id': '111095'
1120+
}]
1121+
}]
1122+
}],
1123+
'account_id': '12001',
1124+
'client_name': 'node-sdk',
1125+
'revision': '42',
1126+
'anonymize_ip': false,
1127+
'enrich_decisions': true,
1128+
},
1129+
};
1130+
1131+
var eventOptions = {
1132+
clientEngine: 'node-sdk',
1133+
clientVersion: packageJSON.version,
1134+
configObj: configObj,
1135+
eventKey: 'testEvent',
1136+
eventTags: {
1137+
'revenue': 0,
1138+
},
1139+
logger: mockLogger,
1140+
userId: 'testUser',
1141+
};
1142+
1143+
var actualParams = eventBuilder.getConversionEvent(eventOptions);
1144+
1145+
assert.deepEqual(actualParams, expectedParams);
1146+
});
1147+
11001148
describe('and the revenue value is invalid', function() {
11011149
it('should not include the revenue value in the event object', function() {
11021150
var expectedParams = {
@@ -1200,6 +1248,54 @@ describe('lib/core/event_builder', function() {
12001248
assert.deepEqual(actualParams, expectedParams);
12011249
});
12021250

1251+
it('should include the falsy event values in the event object', function() {
1252+
var expectedParams = {
1253+
url: 'https://logx.optimizely.com/v1/events',
1254+
httpVerb: 'POST',
1255+
params: {
1256+
'client_version': packageJSON.version,
1257+
'project_id': '111001',
1258+
'visitors': [{
1259+
'attributes': [],
1260+
'visitor_id': 'testUser',
1261+
'snapshots': [{
1262+
'events': [{
1263+
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
1264+
'tags': {
1265+
'value': '0.0'
1266+
},
1267+
'timestamp': Math.round(new Date().getTime()),
1268+
'value': 0.0,
1269+
'key': 'testEvent',
1270+
'entity_id': '111095'
1271+
}]
1272+
}]
1273+
}],
1274+
'account_id': '12001',
1275+
'client_name': 'node-sdk',
1276+
'revision': '42',
1277+
'anonymize_ip': false,
1278+
'enrich_decisions': true,
1279+
},
1280+
};
1281+
1282+
var eventOptions = {
1283+
clientEngine: 'node-sdk',
1284+
clientVersion: packageJSON.version,
1285+
configObj: configObj,
1286+
eventKey: 'testEvent',
1287+
eventTags: {
1288+
'value': '0.0',
1289+
},
1290+
logger: mockLogger,
1291+
userId: 'testUser',
1292+
};
1293+
1294+
var actualParams = eventBuilder.getConversionEvent(eventOptions);
1295+
1296+
assert.deepEqual(actualParams, expectedParams);
1297+
});
1298+
12031299
describe('and the event value is invalid', function() {
12041300
it('should not include the event value in the event object', function() {
12051301
var expectedParams = {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ Optimizely.prototype.track = function(eventKey, userId, attributes, eventTags) {
231231

232232
// remove null values from eventTags
233233
eventTags = this.__filterEmptyValues(eventTags);
234-
235234
var conversionEventOptions = {
236235
attributes: attributes,
237236
clientEngine: this.clientEngine,

0 commit comments

Comments
 (0)