Skip to content

Commit a204cb7

Browse files
[FSSDK-11197] EventTags type fix for v5 (#1040)
1 parent 90ef0d7 commit a204cb7

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

lib/core/event_builder/build_event_v1.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {
17-
EventTags,
18-
ConversionEvent,
19-
ImpressionEvent,
20-
} from '../../modules/event_processor';
16+
import { ConversionEvent, ImpressionEvent } from '../../modules/event_processor';
2117

22-
import { Event } from '../../shared_types';
18+
import { Event, EventTags } from '../../shared_types';
2319

2420
type ProcessableEvent = ConversionEvent | ImpressionEvent
2521

lib/modules/event_processor/events.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EventTags } from "../../shared_types"
2+
13
/**
24
* Copyright 2022, Optimizely
35
*
@@ -82,10 +84,6 @@ export interface ConversionEvent extends BaseEvent {
8284
tags: EventTags | undefined
8385
}
8486

85-
export type EventTags = {
86-
[key: string]: string | number | null
87-
}
88-
8987
export function areEventContextsEqual(eventA: BaseEvent, eventB: BaseEvent): boolean {
9088
const contextA = eventA.context
9189
const contextB = eventB.context

lib/modules/event_processor/v1/buildEventV1.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events'
16+
import { ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events'
1717
import { ProcessableEvent } from '../eventProcessor'
1818
import { EventV1Request } from '../eventDispatcher'
19+
import { EventTags } from '../../../shared_types'
1920

2021
const ACTIVATE_EVENT_KEY = 'campaign_activated'
2122
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'

lib/shared_types.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export interface UserProfile {
7474
}
7575

7676
export type EventTags = {
77-
[key: string]: string | number | null;
77+
revenue?: string | number | null;
78+
value?: string | number | null;
79+
$opt_event_properties?: Record<string, unknown>;
80+
[key: string]: unknown;
7881
};
7982

8083
export interface UserProfileService {

lib/utils/event_tag_utils/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { EventTags } from '../../modules/event_processor';
16+
import { EventTags } from '../../shared_types';
1717
import { LoggerFacade } from '../../modules/logging';
18-
1918
import {
2019
LOG_LEVEL,
2120
LOG_MESSAGES,
@@ -42,7 +41,7 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num
4241
return null;
4342
}
4443

45-
const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue;
44+
const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : Math.trunc(rawValue);
4645

4746
if (isFinite(parsedRevenueValue)) {
4847
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
6665
return null;
6766
}
6867

69-
const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue;
68+
const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue): rawValue;
7069

7170
if (isFinite(parsedEventValue)) {
7271
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
7574
logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue);
7675
return null;
7776
}
78-
}
77+
}

0 commit comments

Comments
 (0)