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

Commit 787271d

Browse files
authored
Merge pull request #42 from optimizely/devel
Bump version to 1.2.0
2 parents 7237979 + e1c7259 commit 787271d

File tree

12 files changed

+291
-141
lines changed

12 files changed

+291
-141
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
-------------------------------------------------------------------------------
2+
1.2.0
3+
-------------------------------------------------------------------------------
4+
* Introduce support for event tags.
5+
* Add optional eventTags argument to track method signature.
6+
* Removed optional eventValue argument from track method signature.
7+
* Removed optional sessionId argument from activate and track method signatures.
8+
* Allow log level config on createInstance method
9+
-------------------------------------------------------------------------------
10+
111
-------------------------------------------------------------------------------
212
1.1.0
313
-------------------------------------------------------------------------------

lib/core/event_builder/event_builder_new_optimizely/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var _ = require('lodash/core');
1717
var projectConfig = require('../../project_config');
1818

1919
var REVENUE_EVENT_METRIC_NAME = 'revenue';
20+
var CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom';
2021

2122
module.exports = {
2223

@@ -26,7 +27,7 @@ module.exports = {
2627

2728
POST_METHOD: 'POST',
2829

29-
CUSTOM_ATTRIBUTE_FEATURE_TYPE: 'custom',
30+
CUSTOM_ATTRIBUTE_FEATURE_TYPE: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
3031

3132
/**
3233
* Creates object of params specific to impression events
@@ -51,12 +52,12 @@ module.exports = {
5152
* Creates object of params specific to conversion events
5253
* @param {Object} configObj Object representing project configuration
5354
* @param {string} eventKey Event key representing the event which needs to be recorded
54-
* @param {number} eventValue Value associated with the event. Can be used to represent revenue in cents
55+
* @param {Object} eventTags Values associated with the event.
5556
* @param {Array} variationIds Experiment variation ID(s) which are being tracked
5657
* @param {Array} validExperimentKeysForEvent Array of valid experiment keys that are associated with the event key
5758
* @return {Object} Conversion event specific params for New Optimizely endpoint
5859
*/
59-
getConversionEventParams: function(configObj, eventKey, eventValue, variationIds, validExperimentKeysForEvent) {
60+
getConversionEventParams: function(configObj, eventKey, eventTags, variationIds, validExperimentKeysForEvent) {
6061
var conversionEventParams = {
6162
eventEntityId: projectConfig.getEventId(configObj, eventKey),
6263
eventName: eventKey,
@@ -85,13 +86,26 @@ module.exports = {
8586
});
8687

8788
conversionEventParams.eventMetrics = [];
88-
if (eventValue) {
89-
var revenueMetric = {
90-
name: REVENUE_EVENT_METRIC_NAME,
91-
value: eventValue,
92-
};
93-
conversionEventParams.eventMetrics.push(revenueMetric);
89+
90+
if (eventTags) {
91+
_.forEach(eventTags, function(eventTagValue, eventTagId) {
92+
if (eventTagId === REVENUE_EVENT_METRIC_NAME) {
93+
var revenueMetric = {
94+
name: REVENUE_EVENT_METRIC_NAME,
95+
value: eventTagValue,
96+
};
97+
conversionEventParams.eventMetrics.push(revenueMetric);
98+
}
99+
var eventFeature = {
100+
id: eventTagId,
101+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
102+
value: eventTagValue,
103+
shouldIndex: false,
104+
};
105+
conversionEventParams.eventFeatures.push(eventFeature);
106+
});
94107
}
108+
95109
return conversionEventParams;
96110
},
97111
};

lib/core/event_builder/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@ function getHTTPVerb(configObj) {
3838
* @param {string} options.clientVersion The version of the client
3939
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
4040
* @param {string} options.userId ID for user
41-
* @param {string} options.sessionId ID for user's current session
4241
* @return {Object} Common params with properties that are used in both conversion and impression events
4342
*/
4443
function getCommonEventParams(options) {
4544
var attributes = options.attributes;
4645
var configObj = options.configObj;
4746
var userId = options.userId;
48-
var sessionId = options.sessionId || null;
4947

5048
if (configObj.version === enums.NEW_OPTIMIZELY_VERSION) {
5149
var commonParams = {
5250
accountId: configObj.accountId,
5351
projectId: configObj.projectId,
5452
revision: configObj.revision,
5553
visitorId: userId,
56-
sessionId: sessionId,
5754
timestamp: Math.round(new Date().getTime()),
5855
isGlobalHoldback: false,
5956
userFeatures: [],
@@ -106,7 +103,6 @@ module.exports = {
106103
* @param {string} options.experimentKey Experiment for which impression needs to be recorded
107104
* @param {string} options.userId ID for user
108105
* @param {string} options.variationId ID for variation which would be presented to user
109-
* @param {string} options.sessionId ID for user's current session
110106
* @return {Object} Params to be used in impression event logging endpoint call
111107
*/
112108
getImpressionEvent: function(options) {
@@ -140,11 +136,10 @@ module.exports = {
140136
* @param {string} options.clientVersion The version of the client
141137
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
142138
* @param {string} options.eventKey Event key representing the event which needs to be recorded
143-
* @param {string} options.eventValue Value associated with the event. Can be used to represent revenue in cents
139+
* @param {Object} options.eventTags Object with event-specific tags
144140
* @param {string} options.userId ID for user
145141
* @param {Array} options.variationIds Experiment variation ID(s) which are being tracked
146142
* @param {Array} options.validExperimentKeysForEvent Array of valid experiment keys that are associated with the event key
147-
* @param {string} options.sessionId ID for user's current session
148143
* @return {Object} Params to be used in conversion event logging endpoint call
149144
*/
150145
getConversionEvent: function(options) {
@@ -159,7 +154,7 @@ module.exports = {
159154

160155
var conversionEventParams = newOptimizelyEventBuilder.getConversionEventParams(options.configObj,
161156
options.eventKey,
162-
options.eventValue,
157+
options.eventTags,
163158
options.variationIds,
164159
options.validExperimentKeysForEvent);
165160
conversionEvent.params = _.assignIn(commonParams, conversionEventParams);
@@ -169,7 +164,7 @@ module.exports = {
169164

170165
var conversionEventParams = classicOptimizelyEventBuilder.getConversionGoalParams(options.configObj,
171166
options.eventKey,
172-
options.eventValue);
167+
options.eventTags && options.eventTags.revenue);
173168
var experimentVariationParams = classicOptimizelyEventBuilder.getExperimentVariationParams(options.configObj,
174169
options.variationIds,
175170
options.validExperimentKeysForEvent);

0 commit comments

Comments
 (0)