Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit d7c64e4

Browse files
authored
Release v1.2.2 (#47)
* Fix event tag formatting * Fix tests * Add event builder test * Add integration test * Increment version * Add EventBuilder unit test * Respond to Ali's CR feedback
1 parent 1eb2220 commit d7c64e4

File tree

6 files changed

+249
-9
lines changed

6 files changed

+249
-9
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
-------------------------------------------------------------------------------
2+
1.2.2
3+
-------------------------------------------------------------------------------
4+
* Use the 'name' field for tracking event tags instead of 'id'.
5+
16
-------------------------------------------------------------------------------
27
1.2.1
38
-------------------------------------------------------------------------------

lib/core/event_builder/event_builder_new_optimizely/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ module.exports = {
8888
conversionEventParams.eventMetrics = [];
8989

9090
if (eventTags) {
91-
_.forEach(eventTags, function(eventTagValue, eventTagId) {
92-
if (eventTagId === REVENUE_EVENT_METRIC_NAME) {
91+
_.forEach(eventTags, function(eventTagValue, eventTagKey) {
92+
if (eventTagKey === REVENUE_EVENT_METRIC_NAME) {
9393
var revenueMetric = {
9494
name: REVENUE_EVENT_METRIC_NAME,
9595
value: eventTagValue,
9696
};
9797
conversionEventParams.eventMetrics.push(revenueMetric);
9898
}
9999
var eventFeature = {
100-
id: eventTagId,
100+
name: eventTagKey,
101101
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
102102
value: eventTagValue,
103103
shouldIndex: false,

lib/core/event_builder/tests.js

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ describe('lib/core/event_builder', function() {
641641
value: 4200,
642642
}],
643643
eventFeatures: [{
644-
"id": "revenue",
644+
"name": "revenue",
645645
"type": 'custom',
646646
"value": 4200,
647647
"shouldIndex": false,
@@ -704,7 +704,7 @@ describe('lib/core/event_builder', function() {
704704
value: 4200,
705705
}],
706706
eventFeatures: [{
707-
"id": "revenue",
707+
"name": "revenue",
708708
"type": 'custom',
709709
"value": 4200,
710710
"shouldIndex": false,
@@ -768,7 +768,7 @@ describe('lib/core/event_builder', function() {
768768
value: 4200,
769769
}],
770770
eventFeatures: [{
771-
"id": "revenue",
771+
"name": "revenue",
772772
"type": 'custom',
773773
"value": 4200,
774774
"shouldIndex": false,
@@ -796,6 +796,123 @@ describe('lib/core/event_builder', function() {
796796
assert.deepEqual(actualParams, expectedParams);
797797
});
798798

799+
it('should create proper params for getConversionEvent in New Optimizely with event tags', function() {
800+
var expectedParams = {
801+
url: 'https://logx.optimizely.com/log/event',
802+
httpVerb: 'POST',
803+
params: {
804+
visitorId: 'testUser',
805+
timestamp: Math.round(new Date().getTime()),
806+
clientEngine: 'node-sdk',
807+
clientVersion: packageJSON.version,
808+
projectId: '111001',
809+
revision: '42',
810+
accountId: '12001',
811+
userFeatures: [],
812+
layerStates: [{
813+
layerId: '4',
814+
revision: '42',
815+
decision: {
816+
variationId: '111128',
817+
isLayerHoldback: false,
818+
experimentId: '111127',
819+
},
820+
actionTriggered: true,
821+
}],
822+
eventEntityId: '111095',
823+
eventName: 'testEvent',
824+
eventMetrics: [],
825+
eventFeatures: [{
826+
"name": "non-revenue",
827+
"type": 'custom',
828+
"value": "cool",
829+
"shouldIndex": false,
830+
}],
831+
isGlobalHoldback: false,
832+
},
833+
};
834+
835+
var eventOptions = {
836+
clientEngine: 'node-sdk',
837+
clientVersion: packageJSON.version,
838+
configObj: configObjNewOptly,
839+
eventKey: 'testEvent',
840+
eventTags: {
841+
'non-revenue': 'cool',
842+
},
843+
userId: 'testUser',
844+
variationIds: ['111128'],
845+
validExperimentKeysForEvent: ['testExperiment'],
846+
};
847+
848+
var actualParams = eventBuilder.getConversionEvent(eventOptions);
849+
850+
assert.deepEqual(actualParams, expectedParams);
851+
});
852+
853+
it('should create proper params for getConversionEvent in New Optimizely with event tags and revenue', function() {
854+
var expectedParams = {
855+
url: 'https://logx.optimizely.com/log/event',
856+
httpVerb: 'POST',
857+
params: {
858+
visitorId: 'testUser',
859+
timestamp: Math.round(new Date().getTime()),
860+
clientEngine: 'node-sdk',
861+
clientVersion: packageJSON.version,
862+
projectId: '111001',
863+
revision: '42',
864+
accountId: '12001',
865+
userFeatures: [],
866+
layerStates: [{
867+
layerId: '4',
868+
revision: '42',
869+
decision: {
870+
variationId: '111128',
871+
isLayerHoldback: false,
872+
experimentId: '111127',
873+
},
874+
actionTriggered: true,
875+
}],
876+
eventEntityId: '111095',
877+
eventName: 'testEvent',
878+
eventMetrics: [{
879+
name: 'revenue',
880+
value: 4200,
881+
}],
882+
eventFeatures: [{
883+
"name": "revenue",
884+
"type": 'custom',
885+
"value": 4200,
886+
"shouldIndex": false,
887+
}, {
888+
"name": "non-revenue",
889+
"type": 'custom',
890+
"value": "cool",
891+
"shouldIndex": false,
892+
}],
893+
isGlobalHoldback: false,
894+
},
895+
};
896+
897+
var eventOptions = {
898+
clientEngine: 'node-sdk',
899+
clientVersion: packageJSON.version,
900+
configObj: configObjNewOptly,
901+
eventKey: 'testEvent',
902+
eventTags: {
903+
'revenue': 4200,
904+
'non-revenue': 'cool',
905+
},
906+
userId: 'testUser',
907+
variationIds: ['111128'],
908+
validExperimentKeysForEvent: ['testExperiment'],
909+
};
910+
911+
var actualParams = eventBuilder.getConversionEvent(eventOptions);
912+
913+
assert.deepEqual(actualParams, expectedParams);
914+
});
915+
799916
it('should not fill in userFeatures for getConversion when attribute is not in datafile in Optimizely X', function() {
800917
var expectedParams = {
801918
url: 'https://logx.optimizely.com/log/event',

lib/optimizely/tests.js

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ describe('lib/optimizely', function() {
14081408
eventEntityId: '111095',
14091409
eventName: 'testEvent',
14101410
eventFeatures: [{
1411-
"id": "revenue",
1411+
"name": "revenue",
14121412
"type": 'custom',
14131413
"value": 4200,
14141414
"shouldIndex": false,
@@ -1447,6 +1447,124 @@ describe('lib/optimizely', function() {
14471447
JSON.stringify(expectedObj.params)));
14481448
});
14491449

1450+
it('should call bucketer and dispatchEvent with proper args when including event tags', function() {
1451+
bucketStub.returns('111129');
1452+
newOptlyInstance.track('testEvent', 'testUser', undefined, {eventTag: 'chill'});
1453+
1454+
sinon.assert.calledOnce(bucketer.bucket);
1455+
sinon.assert.calledOnce(eventDispatcher.dispatchEvent);
1456+
sinon.assert.calledOnce(createdLogger.log);
1457+
1458+
var expectedObj = {
1459+
url: 'https://logx.optimizely.com/log/event',
1460+
httpVerb: 'POST',
1461+
params: {
1462+
accountId: '12001',
1463+
projectId: '111001',
1464+
revision: '42',
1465+
visitorId: 'testUser',
1466+
timestamp: Math.round(new Date().getTime()),
1467+
isGlobalHoldback: false,
1468+
userFeatures: [],
1469+
clientEngine: 'node-sdk',
1470+
clientVersion: enums.NODE_CLIENT_VERSION,
1471+
eventEntityId: '111095',
1472+
eventName: 'testEvent',
1473+
eventFeatures: [{
1474+
"name": "eventTag",
1475+
"type": 'custom',
1476+
"value": 'chill',
1477+
"shouldIndex": false,
1478+
}],
1479+
layerStates: [
1480+
{
1481+
layerId: '4',
1482+
revision: '42',
1483+
decision: {
1484+
isLayerHoldback: false,
1485+
experimentId: '111127',
1486+
variationId: '111129',
1487+
},
1488+
actionTriggered: true,
1489+
},
1490+
],
1491+
eventMetrics: [],
1492+
}
1493+
};
1494+
var eventDispatcherCall = eventDispatcher.dispatchEvent.args[0];
1495+
assert.deepEqual(eventDispatcherCall[0], expectedObj);
1496+
1497+
var logMessage1 = createdLogger.log.args[0][1];
1498+
assert.strictEqual(logMessage1, sprintf(LOG_MESSAGES.DISPATCH_CONVERSION_EVENT,
1499+
'OPTIMIZELY',
1500+
expectedObj.url,
1501+
JSON.stringify(expectedObj.params)));
1502+
});
1503+
1504+
it('should call bucketer and dispatchEvent with proper args when including event tags and revenue', function() {
1505+
bucketStub.returns('111129');
1506+
newOptlyInstance.track('testEvent', 'testUser', undefined, {revenue: 4200, eventTag: 'chill'});
1507+
1508+
sinon.assert.calledOnce(bucketer.bucket);
1509+
sinon.assert.calledOnce(eventDispatcher.dispatchEvent);
1510+
sinon.assert.calledOnce(createdLogger.log);
1511+
1512+
var expectedObj = {
1513+
url: 'https://logx.optimizely.com/log/event',
1514+
httpVerb: 'POST',
1515+
params: {
1516+
accountId: '12001',
1517+
projectId: '111001',
1518+
revision: '42',
1519+
visitorId: 'testUser',
1520+
timestamp: Math.round(new Date().getTime()),
1521+
isGlobalHoldback: false,
1522+
userFeatures: [],
1523+
clientEngine: 'node-sdk',
1524+
clientVersion: enums.NODE_CLIENT_VERSION,
1525+
eventEntityId: '111095',
1526+
eventName: 'testEvent',
1527+
eventFeatures: [{
1528+
"name": "revenue",
1529+
"type": 'custom',
1530+
"value": 4200,
1531+
"shouldIndex": false,
1532+
}, {
1533+
"name": "eventTag",
1534+
"type": 'custom',
1535+
"value": 'chill',
1536+
"shouldIndex": false,
1537+
}],
1538+
layerStates: [
1539+
{
1540+
layerId: '4',
1541+
revision: '42',
1542+
decision: {
1543+
isLayerHoldback: false,
1544+
experimentId: '111127',
1545+
variationId: '111129',
1546+
},
1547+
actionTriggered: true,
1548+
},
1549+
],
1550+
eventMetrics: [
1551+
{
1552+
name: 'revenue',
1553+
value: 4200,
1554+
},
1555+
],
1556+
}
1557+
};
1558+
var eventDispatcherCall = eventDispatcher.dispatchEvent.args[0];
1559+
assert.deepEqual(eventDispatcherCall[0], expectedObj);
1560+
1561+
var logMessage1 = createdLogger.log.args[0][1];
1562+
assert.strictEqual(logMessage1, sprintf(LOG_MESSAGES.DISPATCH_CONVERSION_EVENT,
1563+
'OPTIMIZELY',
1564+
expectedObj.url,
1565+
JSON.stringify(expectedObj.params)));
1566+
});
1567+
14501568
it('should call bucketer and dispatchEvent with proper args when including invalid event value', function() {
14511569
bucketStub.returns('111129');
14521570
newOptlyInstance.track('testEvent', 'testUser', undefined, '4200');

lib/utils/enums/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ exports.LOG_MESSAGES = {
7878
exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
7979
exports.NEW_OPTIMIZELY_VERSION = '2';
8080
exports.NODE_CLIENT_ENGINE = 'node-sdk';
81-
exports.NODE_CLIENT_VERSION = '1.2.1';
81+
exports.NODE_CLIENT_VERSION = '1.2.2';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "optimizely-server-sdk",
33
"description": "Node SDK for Optimizely X Full Stack",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/optimizely/node-sdk.git"

0 commit comments

Comments
 (0)