forked from eanders-ms/microcode
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.ts
More file actions
33 lines (31 loc) · 756 Bytes
/
analytics.ts
File metadata and controls
33 lines (31 loc) · 756 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
27
28
29
30
31
32
33
namespace microcode {
export interface AnalyticsEvent {
type: "event"
msg: string
data?: { [name: string]: string | number }
}
/**
* Sends an event to analytics.
*/
//% shim=TD_NOOP
export function reportEvent(
event: string,
data?: { [name: string]: string | number }
) {
const msg: AnalyticsEvent = {
type: "event",
msg: event,
}
if (data) msg.data = data
report(msg)
}
/**
* Sends an analytics message
* @param msg
*/
//% shim=TD_NOOP
function report(msg: AnalyticsEvent) {
const buf = Buffer.fromUTF8(JSON.stringify(msg))
control.simmessages.send("analytics", buf)
}
}