Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/event_processor/event_builder/log_event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ describe('buildConversionEventV1', () => {
},

tags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
foo: 'bar',
value: '123',
revenue: '1000',
Expand Down Expand Up @@ -496,6 +498,8 @@ describe('buildConversionEventV1', () => {
},

tags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
foo: 'bar',
value: 0,
revenue: 0,
Expand Down Expand Up @@ -582,6 +586,8 @@ describe('buildConversionEventV1', () => {
},

tags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
foo: 'bar',
value: '123',
revenue: '1000',
Expand Down Expand Up @@ -665,6 +671,8 @@ describe('makeEventBatch', () => {
},

tags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
foo: 'bar',
value: '123',
revenue: '1000',
Expand Down
8 changes: 2 additions & 6 deletions lib/event_processor/event_builder/log_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
EventTags,
ConversionEvent,
ImpressionEvent,
UserEvent,
} from './user_event';
import { ConversionEvent, ImpressionEvent, UserEvent } from './user_event';

import { LogEvent } from '../event_dispatcher/event_dispatcher';
import { EventTags } from '../../shared_types';

const ACTIVATE_EVENT_KEY = 'campaign_activated'
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'
Expand Down
6 changes: 1 addition & 5 deletions lib/event_processor/event_builder/user_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ProjectConfig,
} from '../../project_config/project_config';

import { UserAttributes } from '../../shared_types';
import { EventTags, UserAttributes } from '../../shared_types';
import { LoggerFacade } from '../../logging/logger';

export type VisitorAttribute = {
Expand Down Expand Up @@ -79,10 +79,6 @@ export type ImpressionEvent = BaseUserEvent & {
cmabUuid?: string;
};

export type EventTags = {
[key: string]: string | number | null;
};

export type ConversionEvent = BaseUserEvent & {
type: 'conversion';

Expand Down
5 changes: 3 additions & 2 deletions lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ export default class Optimizely extends BaseService implements Client {
*/
private filterEmptyValues(map: EventTags | undefined): EventTags | undefined {
for (const key in map) {
if (map.hasOwnProperty(key) && (map[key] === null || map[key] === undefined)) {
delete map[key];
const typedKey = key as keyof EventTags;
if (map.hasOwnProperty(typedKey) && (map[typedKey] === null || map[typedKey] === undefined)) {
delete map[typedKey];
}
}
return map;
Expand Down
4 changes: 3 additions & 1 deletion lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export interface UserProfile {
}

export type EventTags = {
[key: string]: string | number | null;
revenue?: string | number | null;
value?: string | number | null;
$opt_event_properties?: Record<string, unknown>;
};

export interface UserProfileService {
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/event_tag_utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('getRevenueValue', () => {
});

it('should return null if the revenue value is not present in the event tags', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const parsedRevenueValue = eventTagUtils.getRevenueValue({ not_revenue: '1337' }, logger);

expect(parsedRevenueValue).toBe(null);
Expand Down Expand Up @@ -81,6 +83,8 @@ describe('getEventValue', () => {
});

it('should return null if the value is not present in the event tags', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const parsedNumericValue = eventTagUtils.getEventValue({ not_value: '13.37' }, logger);

expect(parsedNumericValue).toBe(null);
Expand Down
18 changes: 10 additions & 8 deletions lib/utils/event_tag_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import {
PARSED_NUMERIC_VALUE,
PARSED_REVENUE_VALUE,
} from 'log_message';
import { EventTags } from '../../event_processor/event_builder/user_event';
import { LoggerFacade } from '../../logging/logger';

import {
RESERVED_EVENT_KEYWORDS,
} from '../enums';
import { RESERVED_EVENT_KEYWORDS } from '../enums';
import { EventTags } from '../../shared_types';

/**
* Provides utility method for parsing event tag values
Expand All @@ -41,7 +39,8 @@ const VALUE_EVENT_METRIC_NAME = RESERVED_EVENT_KEYWORDS.VALUE;
export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): number | null {
const rawValue = eventTags[REVENUE_EVENT_METRIC_NAME];

if (rawValue == null) { // null or undefined event values
if (rawValue == null) {
// null or undefined event values
return null;
}

Expand All @@ -50,7 +49,8 @@ export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): nu
if (isFinite(parsedRevenueValue)) {
logger?.info(PARSED_REVENUE_VALUE, parsedRevenueValue);
return parsedRevenueValue;
} else { // NaN, +/- infinity values
} else {
// NaN, +/- infinity values
logger?.info(FAILED_TO_PARSE_REVENUE, rawValue);
return null;
}
Expand All @@ -65,7 +65,8 @@ export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): nu
export function getEventValue(eventTags: EventTags, logger?: LoggerFacade): number | null {
const rawValue = eventTags[VALUE_EVENT_METRIC_NAME];

if (rawValue == null) { // null or undefined event values
if (rawValue == null) {
// null or undefined event values
return null;
}

Expand All @@ -74,7 +75,8 @@ export function getEventValue(eventTags: EventTags, logger?: LoggerFacade): numb
if (isFinite(parsedEventValue)) {
logger?.info(PARSED_NUMERIC_VALUE, parsedEventValue);
return parsedEventValue;
} else { // NaN, +/- infinity values
} else {
// NaN, +/- infinity values
logger?.info(FAILED_TO_PARSE_VALUE, rawValue);
return null;
}
Expand Down
Loading