|
1 | 1 | /** |
2 | | - * Copyright 2016-2019, Optimizely |
| 2 | + * Copyright 2016-2020, Optimizely |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -var enums = require('../../utils/enums'); |
17 | | -var fns = require('../../utils/fns'); |
18 | | -var eventTagUtils = require('../../utils/event_tag_utils'); |
19 | | -var projectConfig = require('../project_config'); |
20 | | -var attributeValidator = require('../../utils/attributes_validator'); |
| 16 | +import fns from '../../utils/fns'; |
| 17 | +import enums from '../../utils/enums'; |
| 18 | +import projectConfig from '../project_config'; |
| 19 | +import eventTagUtils from '../../utils/event_tag_utils'; |
| 20 | +import attributeValidator from '../../utils/attributes_validator'; |
21 | 21 |
|
22 | 22 | var ACTIVATE_EVENT_KEY = 'campaign_activated'; |
23 | 23 | var CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'; |
@@ -153,62 +153,65 @@ function getVisitorSnapshot(configObj, eventKey, eventTags, logger) { |
153 | 153 | return snapshot; |
154 | 154 | } |
155 | 155 |
|
156 | | -module.exports = { |
157 | | - /** |
158 | | - * Create impression event params to be sent to the logging endpoint |
159 | | - * @param {Object} options Object containing values needed to build impression event |
160 | | - * @param {Object} options.attributes Object representing user attributes and values which need to be recorded |
161 | | - * @param {string} options.clientEngine The client we are using: node or javascript |
162 | | - * @param {string} options.clientVersion The version of the client |
163 | | - * @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup |
164 | | - * @param {string} options.experimentId Experiment for which impression needs to be recorded |
165 | | - * @param {string} options.userId ID for user |
166 | | - * @param {string} options.variationId ID for variation which would be presented to user |
167 | | - * @return {Object} Params to be used in impression event logging endpoint call |
168 | | - */ |
169 | | - getImpressionEvent: function(options) { |
170 | | - var impressionEvent = { |
171 | | - httpVerb: HTTP_VERB, |
172 | | - }; |
173 | | - |
174 | | - var commonParams = getCommonEventParams(options); |
175 | | - impressionEvent.url = ENDPOINT; |
176 | | - |
177 | | - var impressionEventParams = getImpressionEventParams(options.configObj, options.experimentId, options.variationId); |
178 | | - // combine Event params into visitor obj |
179 | | - commonParams.visitors[0].snapshots.push(impressionEventParams); |
180 | | - |
181 | | - impressionEvent.params = commonParams; |
182 | | - |
183 | | - return impressionEvent; |
184 | | - }, |
185 | | - |
186 | | - /** |
187 | | - * Create conversion event params to be sent to the logging endpoint |
188 | | - * @param {Object} options Object containing values needed to build conversion event |
189 | | - * @param {Object} options.attributes Object representing user attributes and values which need to be recorded |
190 | | - * @param {string} options.clientEngine The client we are using: node or javascript |
191 | | - * @param {string} options.clientVersion The version of the client |
192 | | - * @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup |
193 | | - * @param {string} options.eventKey Event key representing the event which needs to be recorded |
194 | | - * @param {Object} options.eventTags Object with event-specific tags |
195 | | - * @param {Object} options.logger Logger object |
196 | | - * @param {string} options.userId ID for user |
197 | | - * @return {Object} Params to be used in conversion event logging endpoint call |
198 | | - */ |
199 | | - getConversionEvent: function(options) { |
200 | | - var conversionEvent = { |
201 | | - httpVerb: HTTP_VERB, |
202 | | - }; |
203 | | - |
204 | | - var commonParams = getCommonEventParams(options); |
205 | | - conversionEvent.url = ENDPOINT; |
206 | | - |
207 | | - var snapshot = getVisitorSnapshot(options.configObj, options.eventKey, options.eventTags, options.logger); |
208 | | - |
209 | | - commonParams.visitors[0].snapshots = [snapshot]; |
210 | | - conversionEvent.params = commonParams; |
211 | | - |
212 | | - return conversionEvent; |
213 | | - }, |
| 156 | +/** |
| 157 | + * Create impression event params to be sent to the logging endpoint |
| 158 | + * @param {Object} options Object containing values needed to build impression event |
| 159 | + * @param {Object} options.attributes Object representing user attributes and values which need to be recorded |
| 160 | + * @param {string} options.clientEngine The client we are using: node or javascript |
| 161 | + * @param {string} options.clientVersion The version of the client |
| 162 | + * @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup |
| 163 | + * @param {string} options.experimentId Experiment for which impression needs to be recorded |
| 164 | + * @param {string} options.userId ID for user |
| 165 | + * @param {string} options.variationId ID for variation which would be presented to user |
| 166 | + * @return {Object} Params to be used in impression event logging endpoint call |
| 167 | + */ |
| 168 | +export var getImpressionEvent = function(options) { |
| 169 | + var impressionEvent = { |
| 170 | + httpVerb: HTTP_VERB, |
| 171 | + }; |
| 172 | + |
| 173 | + var commonParams = getCommonEventParams(options); |
| 174 | + impressionEvent.url = ENDPOINT; |
| 175 | + |
| 176 | + var impressionEventParams = getImpressionEventParams(options.configObj, options.experimentId, options.variationId); |
| 177 | + // combine Event params into visitor obj |
| 178 | + commonParams.visitors[0].snapshots.push(impressionEventParams); |
| 179 | + |
| 180 | + impressionEvent.params = commonParams; |
| 181 | + |
| 182 | + return impressionEvent; |
| 183 | +}; |
| 184 | + |
| 185 | +/** |
| 186 | + * Create conversion event params to be sent to the logging endpoint |
| 187 | + * @param {Object} options Object containing values needed to build conversion event |
| 188 | + * @param {Object} options.attributes Object representing user attributes and values which need to be recorded |
| 189 | + * @param {string} options.clientEngine The client we are using: node or javascript |
| 190 | + * @param {string} options.clientVersion The version of the client |
| 191 | + * @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup |
| 192 | + * @param {string} options.eventKey Event key representing the event which needs to be recorded |
| 193 | + * @param {Object} options.eventTags Object with event-specific tags |
| 194 | + * @param {Object} options.logger Logger object |
| 195 | + * @param {string} options.userId ID for user |
| 196 | + * @return {Object} Params to be used in conversion event logging endpoint call |
| 197 | + */ |
| 198 | +export var getConversionEvent = function(options) { |
| 199 | + var conversionEvent = { |
| 200 | + httpVerb: HTTP_VERB, |
| 201 | + }; |
| 202 | + |
| 203 | + var commonParams = getCommonEventParams(options); |
| 204 | + conversionEvent.url = ENDPOINT; |
| 205 | + |
| 206 | + var snapshot = getVisitorSnapshot(options.configObj, options.eventKey, options.eventTags, options.logger); |
| 207 | + |
| 208 | + commonParams.visitors[0].snapshots = [snapshot]; |
| 209 | + conversionEvent.params = commonParams; |
| 210 | + |
| 211 | + return conversionEvent; |
| 212 | +}; |
| 213 | + |
| 214 | +export default { |
| 215 | + getConversionEvent: getConversionEvent, |
| 216 | + getImpressionEvent: getImpressionEvent, |
214 | 217 | }; |
0 commit comments