Skip to content

Commit aaf2e12

Browse files
mikeproeng37oakbani
authored andcommitted
fix(event-tags): do not exclude falsy revenue and event values in the event payload (#213)
(cherry picked from commit cac996b)
1 parent d6c3276 commit aaf2e12

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
@@ -144,12 +144,12 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, experimentsToVariati
144144

145145
if (eventTags) {
146146
var revenue = eventTagUtils.getRevenueValue(eventTags, logger);
147-
if (revenue) {
147+
if (revenue !== null) {
148148
eventDict[enums.RESERVED_EVENT_KEYWORDS.REVENUE] = revenue;
149149
}
150150

151151
var eventValue = eventTagUtils.getEventValue(eventTags, logger);
152-
if (eventValue) {
152+
if (eventValue !== null) {
153153
eventDict[enums.RESERVED_EVENT_KEYWORDS.VALUE] = eventValue;
154154
}
155155

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

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

1084+
it('should include revenue value of 0 in the event object', function() {
1085+
var expectedParams = {
1086+
url: 'https://logx.optimizely.com/v1/events',
1087+
httpVerb: 'POST',
1088+
params: {
1089+
'client_version': packageJSON.version,
1090+
'project_id': '111001',
1091+
'visitors': [{
1092+
'attributes': [],
1093+
'visitor_id': 'testUser',
1094+
'snapshots': [{
1095+
'events': [{
1096+
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
1097+
'tags': {
1098+
'revenue': 0
1099+
},
1100+
'timestamp': Math.round(new Date().getTime()),
1101+
'revenue': 0,
1102+
'key': 'testEvent',
1103+
'entity_id': '111095'
1104+
}]
1105+
}]
1106+
}],
1107+
'account_id': '12001',
1108+
'client_name': 'node-sdk',
1109+
'revision': '42',
1110+
'anonymize_ip': false,
1111+
'enrich_decisions': true,
1112+
},
1113+
};
1114+
1115+
var eventOptions = {
1116+
clientEngine: 'node-sdk',
1117+
clientVersion: packageJSON.version,
1118+
configObj: configObj,
1119+
eventKey: 'testEvent',
1120+
eventTags: {
1121+
'revenue': 0,
1122+
},
1123+
logger: mockLogger,
1124+
userId: 'testUser',
1125+
};
1126+
1127+
var actualParams = eventBuilder.getConversionEvent(eventOptions);
1128+
1129+
assert.deepEqual(actualParams, expectedParams);
1130+
});
1131+
10841132
describe('and the revenue value is invalid', function() {
10851133
it('should not include the revenue value in the event object', function() {
10861134
var expectedParams = {
@@ -1194,6 +1242,54 @@ describe('lib/core/event_builder', function() {
11941242
assert.deepEqual(actualParams, expectedParams);
11951243
});
11961244

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

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

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

238238
// remove null values from eventTags
239239
eventTags = this.__filterEmptyValues(eventTags);
240-
241240
var conversionEventOptions = {
242241
attributes: attributes,
243242
clientEngine: this.clientEngine,

0 commit comments

Comments
 (0)