Skip to content

Commit ba217b0

Browse files
committed
Incorporate comments
1 parent 4b1371e commit ba217b0

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

packages/optimizely-sdk/lib/core/event_builder/event_helpers.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ interface ConversionEvent {
121121
* @param {ImpressionConfig} config
122122
* @return {ImpressionEvent} an ImpressionEvent object
123123
*/
124-
export const buildImpressionEvent = function(config: ImpressionConfig): ImpressionEvent {
125-
const configObj = config.configObj;
126-
const decisionObj = config.decisionObj;
127-
const userId = config.userId;
128-
const flagKey = config.flagKey;
129-
const enabled = config.enabled;
130-
const userAttributes = config.userAttributes;
131-
const clientEngine = config.clientEngine;
132-
const clientVersion = config.clientVersion;
124+
export const buildImpressionEvent = function({
125+
configObj,
126+
decisionObj,
127+
userId,
128+
flagKey,
129+
enabled,
130+
userAttributes,
131+
clientEngine,
132+
clientVersion,
133+
}: ImpressionConfig): ImpressionEvent {
134+
133135
const ruleType = decisionObj.decisionSource;
134136
const experimentKey = decision.getExperimentKey(decisionObj);
135137
const variationKey = decision.getVariationKey(decisionObj);
@@ -185,15 +187,16 @@ export const buildImpressionEvent = function(config: ImpressionConfig): Impressi
185187
* @param {ConversionConfig} config
186188
* @return {ConversionEvent} a ConversionEvent object
187189
*/
188-
export const buildConversionEvent = function(config: ConversionConfig): ConversionEvent {
189-
const configObj = config.configObj;
190-
const userId = config.userId;
191-
const userAttributes = config.userAttributes;
192-
const clientEngine = config.clientEngine;
193-
const clientVersion = config.clientVersion;
194-
195-
const eventKey = config.eventKey;
196-
const eventTags = config.eventTags;
190+
export const buildConversionEvent = function({
191+
configObj,
192+
userId,
193+
userAttributes,
194+
clientEngine,
195+
clientVersion,
196+
eventKey,
197+
eventTags,
198+
}: ConversionConfig): ConversionEvent {
199+
197200
const eventId = getEventId(configObj, eventKey);
198201

199202
const revenue = eventTags ? eventTagUtils.getRevenueValue(eventTags, logger) : null;

packages/optimizely-sdk/lib/core/event_builder/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { LoggerFacade } from '@optimizely/js-sdk-logging';
17+
import { EventV1 as CommonEventParams } from '@optimizely/js-sdk-event-processor';
18+
1619
import fns from '../../utils/fns';
1720
import { CONTROL_ATTRIBUTES, RESERVED_EVENT_KEYWORDS } from '../../utils/enums';
1821
import {
@@ -25,8 +28,6 @@ import {
2528
import * as eventTagUtils from '../../utils/event_tag_utils';
2629
import { isAttributeValid } from '../../utils/attributes_validator';
2730
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';
3031

3132
const ACTIVATE_EVENT_KEY = 'campaign_activated';
3233
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom';
@@ -116,15 +117,21 @@ interface Snapshot {
116117
* @param {ImpressionOptions|ConversionEventOptions} options Object containing values needed to build impression/conversion event
117118
* @return {CommonEventParams} Common params with properties that are used in both conversion and impression events
118119
*/
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+
122129
const anonymize_ip = configObj.anonymizeIP ? configObj.anonymizeIP : false;
123130
const botFiltering = configObj.botFiltering;
124131

125132
const visitor = {
126133
snapshots: [],
127-
visitor_id: options.userId,
134+
visitor_id: userId,
128135
attributes: [],
129136
};
130137

@@ -133,8 +140,8 @@ function getCommonEventParams(options: ImpressionOptions | ConversionEventOption
133140
project_id: configObj.projectId,
134141
visitors: [visitor],
135142
revision: configObj.revision,
136-
client_name: options.clientEngine,
137-
client_version: options.clientVersion,
143+
client_name: clientEngine,
144+
client_version: clientVersion,
138145
anonymize_ip: anonymize_ip,
139146
enrich_decisions: true,
140147
};
@@ -144,7 +151,7 @@ function getCommonEventParams(options: ImpressionOptions | ConversionEventOption
144151
Object.keys(attributes || {}).forEach(function(attributeKey) {
145152
const attributeValue = attributes[attributeKey];
146153
if (isAttributeValid(attributeKey, attributeValue)) {
147-
const attributeId = getAttributeId(options.configObj, attributeKey, options.logger);
154+
const attributeId = getAttributeId(configObj, attributeKey, logger);
148155
if (attributeId) {
149156
commonParams.visitors[0].attributes.push({
150157
entity_id: attributeId,
@@ -194,7 +201,7 @@ function getImpressionEventParams(
194201
const campaignId = experimentId ? getLayerId(configObj, experimentId) : null;
195202

196203
let variationKey = variationId ? getVariationKeyFromId(configObj, variationId) : null;
197-
variationKey = variationKey ? variationKey: '';
204+
variationKey = variationKey || '';
198205

199206
const impressionEventParams = {
200207
decisions: [

0 commit comments

Comments
 (0)