forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.ts
More file actions
54 lines (48 loc) · 1.55 KB
/
Copy pathevents.ts
File metadata and controls
54 lines (48 loc) · 1.55 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
buildPageView,
buildSelfDescribingEvent,
buildStructEvent,
PageViewEvent,
SelfDescribingJson,
TrackerCore,
} from '@snowplow/tracker-core';
import { EventContext, MessageNotificationProps, StructuredProps, TimingProps } from './types';
export function newTrackEventFunctions(core: TrackerCore) {
const trackSelfDescribingEvent = <T extends Record<string, unknown> = Record<string, unknown>>(
argmap: SelfDescribingJson<T>,
contexts?: EventContext[]
) => {
core.track(buildSelfDescribingEvent({ event: argmap }), contexts);
};
const trackStructuredEvent = (argmap: StructuredProps, contexts?: EventContext[]) => {
return core.track(buildStructEvent(argmap), contexts)?.eid;
};
const trackPageViewEvent = (argmap: PageViewEvent, contexts?: EventContext[]) => {
return core.track(buildPageView(argmap), contexts)?.eid;
};
const trackTimingEvent = (argmap: TimingProps, contexts?: EventContext[]) => {
trackSelfDescribingEvent(
{
schema: 'iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0',
data: argmap,
},
contexts
);
};
const trackMessageNotificationEvent = (argmap: MessageNotificationProps, contexts?: EventContext[]) => {
trackSelfDescribingEvent(
{
schema: 'iglu:com.snowplowanalytics.mobile/message_notification/jsonschema/1-0-0',
data: argmap,
},
contexts
);
};
return {
trackSelfDescribingEvent,
trackStructuredEvent,
trackPageViewEvent,
trackTimingEvent,
trackMessageNotificationEvent,
};
}