-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathutils.ts
More file actions
18 lines (17 loc) · 800 Bytes
/
utils.ts
File metadata and controls
18 lines (17 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { PayloadBuilder } from '@snowplow/tracker-core';
// Returns the "useful" schema, i.e. what would someone want to use to identify events.
// For some events this is the 'e' property but for self-describing events, this is the
// 'schema' from the 'ue_px' field.
export function getUsefulSchemaAndData(sb: PayloadBuilder) {
let eventJson = sb.getJson();
for (const json of eventJson) {
if (json.keyIfEncoded === 'ue_px' && typeof json.json['data'] === 'object') {
const schema = (json.json['data'] as Record<string, unknown>)['schema'];
if (typeof schema == 'string') {
const data = json.json['data'] as Record<string, unknown>;
return { schema, data: data.data as Record<string, unknown>, eventPayload: json.json };
}
}
}
return undefined;
}