-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathtrack.ts
More file actions
26 lines (23 loc) · 912 Bytes
/
track.ts
File metadata and controls
26 lines (23 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {
type TrackEventType,
generateMapTransform,
} from '@segment/analytics-react-native';
import { firebaseAnalytics } from '../firebaseAnalytics';
import { mapEventProps, transformMap } from './parameterMapping';
const mappedPropNames = generateMapTransform(mapEventProps, transformMap);
const sanitizeName = (name: string) => {
return name.replace(/[^a-zA-Z0-9]/g, '_');
};
export default async (event: TrackEventType) => {
const safeEvent = mappedPropNames(
event as unknown as Record<string, unknown>
);
const convertedName = safeEvent.event as string;
let safeEventName = sanitizeName(convertedName);
const safeProps = safeEvent.properties as { [key: string]: unknown };
// Clip the event name if it exceeds 40 characters
if (safeEventName.length > 40) {
safeEventName = safeEventName.substring(0, 40);
}
await firebaseAnalytics.logEvent(safeEventName, safeProps);
};