Skip to content

[FSSDK-11197] EventTags type fix #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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: 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 @@ -609,8 +609,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
5 changes: 4 additions & 1 deletion lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ 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>;
[key: string]: unknown;
};

export interface UserProfileService {
Expand Down
20 changes: 11 additions & 9 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,16 +39,18 @@ 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;
}

const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue;
const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : Math.trunc(rawValue);

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