13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+ import { LoggerFacade } from '@optimizely/js-sdk-logging' ;
17
+ import { EventV1 as CommonEventParams } from '@optimizely/js-sdk-event-processor' ;
18
+
16
19
import fns from '../../utils/fns' ;
17
20
import { CONTROL_ATTRIBUTES , RESERVED_EVENT_KEYWORDS } from '../../utils/enums' ;
18
21
import {
@@ -25,8 +28,6 @@ import {
25
28
import * as eventTagUtils from '../../utils/event_tag_utils' ;
26
29
import { isAttributeValid } from '../../utils/attributes_validator' ;
27
30
import { EventTags , UserAttributes , Event as EventLoggingEndpoint } from '../../shared_types' ;
28
- import { LoggerFacade } from '@optimizely/js-sdk-logging' ;
29
- import { EventV1 as CommonEventParams } from '@optimizely/js-sdk-event-processor' ;
30
31
31
32
const ACTIVATE_EVENT_KEY = 'campaign_activated' ;
32
33
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom' ;
@@ -116,15 +117,21 @@ interface Snapshot {
116
117
* @param {ImpressionOptions|ConversionEventOptions } options Object containing values needed to build impression/conversion event
117
118
* @return {CommonEventParams } Common params with properties that are used in both conversion and impression events
118
119
*/
119
- function getCommonEventParams ( options : ImpressionOptions | ConversionEventOptions ) : CommonEventParams {
120
- const attributes = options . attributes ;
121
- const configObj = options . configObj ;
120
+ function getCommonEventParams ( {
121
+ attributes,
122
+ userId,
123
+ clientEngine,
124
+ clientVersion,
125
+ configObj,
126
+ logger,
127
+ } : ImpressionOptions | ConversionEventOptions ) : CommonEventParams {
128
+
122
129
const anonymize_ip = configObj . anonymizeIP ? configObj . anonymizeIP : false ;
123
130
const botFiltering = configObj . botFiltering ;
124
131
125
132
const visitor = {
126
133
snapshots : [ ] ,
127
- visitor_id : options . userId ,
134
+ visitor_id : userId ,
128
135
attributes : [ ] ,
129
136
} ;
130
137
@@ -133,8 +140,8 @@ function getCommonEventParams(options: ImpressionOptions | ConversionEventOption
133
140
project_id : configObj . projectId ,
134
141
visitors : [ visitor ] ,
135
142
revision : configObj . revision ,
136
- client_name : options . clientEngine ,
137
- client_version : options . clientVersion ,
143
+ client_name : clientEngine ,
144
+ client_version : clientVersion ,
138
145
anonymize_ip : anonymize_ip ,
139
146
enrich_decisions : true ,
140
147
} ;
@@ -144,7 +151,7 @@ function getCommonEventParams(options: ImpressionOptions | ConversionEventOption
144
151
Object . keys ( attributes || { } ) . forEach ( function ( attributeKey ) {
145
152
const attributeValue = attributes [ attributeKey ] ;
146
153
if ( isAttributeValid ( attributeKey , attributeValue ) ) {
147
- const attributeId = getAttributeId ( options . configObj , attributeKey , options . logger ) ;
154
+ const attributeId = getAttributeId ( configObj , attributeKey , logger ) ;
148
155
if ( attributeId ) {
149
156
commonParams . visitors [ 0 ] . attributes . push ( {
150
157
entity_id : attributeId ,
@@ -194,7 +201,7 @@ function getImpressionEventParams(
194
201
const campaignId = experimentId ? getLayerId ( configObj , experimentId ) : null ;
195
202
196
203
let variationKey = variationId ? getVariationKeyFromId ( configObj , variationId ) : null ;
197
- variationKey = variationKey ? variationKey : '' ;
204
+ variationKey = variationKey || '' ;
198
205
199
206
const impressionEventParams = {
200
207
decisions : [
0 commit comments