Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/analytics.ts
2498 views
1
/**
2
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
export const IAnalyticsWriter = Symbol("IAnalyticsWriter");
8
9
type Identity = { userId?: string | number; anonymousId?: string | number; subjectId?: string };
10
11
interface Message {
12
messageId?: string;
13
}
14
15
export type IdentifyMessage = Message &
16
Identity & {
17
traits?: any;
18
timestamp?: Date;
19
context?: any;
20
};
21
22
export type TrackMessage = Message &
23
Identity & {
24
event: string;
25
properties?: any;
26
timestamp?: Date;
27
context?: any;
28
};
29
30
export type PageMessage = Message &
31
Identity & {
32
properties?: any;
33
timestamp?: Date;
34
context?: any;
35
};
36
37
export type RemoteTrackMessage = Omit<TrackMessage, "timestamp" | "userId">;
38
export type RemotePageMessage = Omit<PageMessage, "timestamp" | "userId"> & {
39
includePII?: boolean;
40
};
41
42
export type RemoteIdentifyMessage = Omit<IdentifyMessage, "timestamp" | "userId">;
43
44
export interface IAnalyticsWriter {
45
identify(msg: IdentifyMessage): void;
46
47
track(msg: TrackMessage): void;
48
49
page(msg: PageMessage): void;
50
}
51
52
export const NullAnalyticsWriter: IAnalyticsWriter = {
53
identify(msg: IdentifyMessage): void {
54
// noop
55
},
56
track(msg: TrackMessage): void {
57
// noop
58
},
59
page(msg: PageMessage): void {
60
// noop
61
},
62
};
63
64