From a204cb7ca21b615e47e0815e3f1249ca756c7e20 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Tue, 6 May 2025 18:16:02 +0600 Subject: [PATCH] [FSSDK-11197] EventTags type fix for v5 (#1040) --- lib/core/event_builder/build_event_v1.ts | 8 ++------ lib/modules/event_processor/events.ts | 6 ++---- lib/modules/event_processor/v1/buildEventV1.ts | 3 ++- lib/shared_types.ts | 5 ++++- lib/utils/event_tag_utils/index.ts | 9 ++++----- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/core/event_builder/build_event_v1.ts b/lib/core/event_builder/build_event_v1.ts index b1f5b271d..a6506792b 100644 --- a/lib/core/event_builder/build_event_v1.ts +++ b/lib/core/event_builder/build_event_v1.ts @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - EventTags, - ConversionEvent, - ImpressionEvent, -} from '../../modules/event_processor'; +import { ConversionEvent, ImpressionEvent } from '../../modules/event_processor'; -import { Event } from '../../shared_types'; +import { Event, EventTags } from '../../shared_types'; type ProcessableEvent = ConversionEvent | ImpressionEvent diff --git a/lib/modules/event_processor/events.ts b/lib/modules/event_processor/events.ts index 65cce503b..61abab4e5 100644 --- a/lib/modules/event_processor/events.ts +++ b/lib/modules/event_processor/events.ts @@ -1,3 +1,5 @@ +import { EventTags } from "../../shared_types" + /** * Copyright 2022, Optimizely * @@ -82,10 +84,6 @@ export interface ConversionEvent extends BaseEvent { tags: EventTags | undefined } -export type EventTags = { - [key: string]: string | number | null -} - export function areEventContextsEqual(eventA: BaseEvent, eventB: BaseEvent): boolean { const contextA = eventA.context const contextB = eventB.context diff --git a/lib/modules/event_processor/v1/buildEventV1.ts b/lib/modules/event_processor/v1/buildEventV1.ts index 699498dc4..c0ab1aba7 100644 --- a/lib/modules/event_processor/v1/buildEventV1.ts +++ b/lib/modules/event_processor/v1/buildEventV1.ts @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' +import { ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' import { ProcessableEvent } from '../eventProcessor' import { EventV1Request } from '../eventDispatcher' +import { EventTags } from '../../../shared_types' const ACTIVATE_EVENT_KEY = 'campaign_activated' const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom' diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 495051866..75885b83e 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -74,7 +74,10 @@ export interface UserProfile { } export type EventTags = { - [key: string]: string | number | null; + revenue?: string | number | null; + value?: string | number | null; + $opt_event_properties?: Record; + [key: string]: unknown; }; export interface UserProfileService { diff --git a/lib/utils/event_tag_utils/index.ts b/lib/utils/event_tag_utils/index.ts index 7917f3baa..e3550a73d 100644 --- a/lib/utils/event_tag_utils/index.ts +++ b/lib/utils/event_tag_utils/index.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventTags } from '../../modules/event_processor'; +import { EventTags } from '../../shared_types'; import { LoggerFacade } from '../../modules/logging'; - import { LOG_LEVEL, LOG_MESSAGES, @@ -42,7 +41,7 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num return null; } - const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue; + const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : Math.trunc(rawValue); if (isFinite(parsedRevenueValue)) { logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue); @@ -66,7 +65,7 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe return null; } - const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue; + const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue): rawValue; if (isFinite(parsedEventValue)) { logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue); @@ -75,4 +74,4 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue); return null; } -} \ No newline at end of file +}