-
Notifications
You must be signed in to change notification settings - Fork 5
/
TyperighterTelemetryAdapter.ts
116 lines (106 loc) · 3.22 KB
/
TyperighterTelemetryAdapter.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {
ITyperighterTelemetryEvent,
TYPERIGHTER_TELEMETRY_TYPE,
} from "../interfaces/ITelemetryData";
import TelemetryService from './TelemetryService';
import { IMatch } from "..";
class TyperighterTelemetryAdapter {
constructor(
private telemetryService: TelemetryService,
private app: string,
private stage: string
) {}
public suggestionIsAccepted(match: IMatch, documentUrl: string, suggestion: string) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_SUGGESTION_IS_ACCEPTED,
value: 1,
eventTime: new Date().toISOString(),
tags: {
suggestion,
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}
public matchIsMarkedAsCorrect(match: IMatch, documentUrl: string) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_MARK_AS_CORRECT,
value: 1,
eventTime: new Date().toISOString(),
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}
public documentIsChecked(tags: ITyperighterTelemetryEvent["tags"]) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_CHECK_DOCUMENT,
value: 1,
eventTime: new Date().toISOString(),
tags
});
}
public typerighterIsOpened(tags: ITyperighterTelemetryEvent["tags"]) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_OPEN_STATE_CHANGED,
value: 1,
eventTime: new Date().toISOString(),
tags
});
}
public typerighterIsClosed(tags: ITyperighterTelemetryEvent["tags"]) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_OPEN_STATE_CHANGED,
value: 0,
eventTime: new Date().toISOString(),
tags
});
}
public sidebarMatchClicked(match: IMatch, documentUrl: string) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_SIDEBAR_MATCH_CLICK,
value: 1,
eventTime: new Date().toISOString(),
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}
public matchFound(match: IMatch, documentUrl: string) {
this.telemetryService.addEvent({
app: this.app,
stage: this.stage,
type: TYPERIGHTER_TELEMETRY_TYPE.TYPERIGHTER_MATCH_FOUND,
value: 1,
eventTime: new Date().toISOString(),
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}
private getTelemetryTagsFromMatch = (match: IMatch) => ({
matcherType: match.matcherType,
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchHasReplacement: match.replacement ? 'true' : 'false',
matchIsAdvisory: 'false',
matchIsMarkedAsCorrect: match.markAsCorrect ? 'true' : 'false',
})
}
export default TyperighterTelemetryAdapter;