Skip to content

Commit

Permalink
Merge dfc36ba into 8e4a67c
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Sep 17, 2020
2 parents 8e4a67c + dfc36ba commit 455922e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 46 deletions.
8 changes: 1 addition & 7 deletions src/ts/components/SidebarMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ const SidebarMatch = ({
e.preventDefault();
e.stopPropagation();

telemetryAdapter?.sidebarMatchClicked({
documentUrl: document.URL,
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchContext: match.matchContext
});
telemetryAdapter?.sidebarMatchClicked(match, document.URL);

if (!editorScrollElement) {
return;
Expand Down
13 changes: 5 additions & 8 deletions src/ts/components/Suggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,11 @@ const Suggestion = ({ match, suggestion, applySuggestions }: IProps) => {
}
]);

telemetryAdapter?.suggestionIsAccepted({
documentUrl: document.URL,
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchContext: match.matchContext,
suggestion: suggestion.text
});
telemetryAdapter?.suggestionIsAccepted(
match,
document.URL,
suggestion.text
);
};
switch (suggestion.type) {
case "TEXT_SUGGESTION": {
Expand Down
8 changes: 1 addition & 7 deletions src/ts/createView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ const createView = ({
onMarkCorrect(match);
// See the previous comment re: focusing in `applySuggestions`.
view.focus();
telemetryAdapter?.matchIsMarkedAsCorrect({
documentUrl: document.URL,
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchContext: match.matchContext
});
telemetryAdapter?.matchIsMarkedAsCorrect(match, document.URL);
})
}
feedbackHref={feedbackHref}
Expand Down
5 changes: 5 additions & 0 deletions src/ts/interfaces/ITelemetryData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type TelemetryBool = 'true' | 'false';

export interface ITelemetryEvent {
/**
* The application sending the event
Expand Down Expand Up @@ -55,6 +57,9 @@ interface IMatchEventTags {
ruleId: string,
suggestion?: string;
matchId: string;
matchIsMarkedAsCorrect: TelemetryBool;
matchIsAdvisory: TelemetryBool;
matchHasReplacement: TelemetryBool;
matchedText: string;
matchContext: string;
}
Expand Down
22 changes: 10 additions & 12 deletions src/ts/services/MatcherService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IBlock, IMatch, ICategory } from "../interfaces/IMatch";
import { IMatcherAdapter, TMatchesReceivedCallback } from "../interfaces/IMatcherAdapter";
import {
IMatcherAdapter,
TMatchesReceivedCallback
} from "../interfaces/IMatcherAdapter";
import Store, {
STORE_EVENT_NEW_MATCHES,
STORE_EVENT_NEW_DIRTIED_RANGES
Expand All @@ -25,7 +28,7 @@ class MatcherService<TMatch extends IMatch> {
private adapter: IMatcherAdapter<TMatch>,
private telemetryAdapter?: TyperighterTelemetryAdapter,
// The initial throttle duration for pending requests.
private initialThrottle = 2000,
private initialThrottle = 2000
) {
this.currentThrottle = this.initialThrottle;
this.store.on(STORE_EVENT_NEW_MATCHES, (requestId, requestsInFlight) => {
Expand All @@ -37,15 +40,10 @@ class MatcherService<TMatch extends IMatch> {
}

private sendMatchTelemetryEvents = (matches: TMatch[]) => {
matches.forEach((match: TMatch) => this.telemetryAdapter?.matchFound({
documentUrl: document.URL,
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchContext: match.matchContext
}));
}

matches.forEach((match: TMatch) =>
this.telemetryAdapter?.matchFound(match, document.URL)
);
};

/**
* Get all of the available categories from the matcher service.
Expand Down Expand Up @@ -75,7 +73,7 @@ class MatcherService<TMatch extends IMatch> {
* Fetch matches for a set of blocks.
*/
public async fetchMatches(requestId: string, blocks: IBlock[]) {
const applyMatcherResponse: TMatchesReceivedCallback<TMatch> = (response) => {
const applyMatcherResponse: TMatchesReceivedCallback<TMatch> = response => {
this.sendMatchTelemetryEvents(response.matches);
this.commands.applyMatcherResponse(response);
};
Expand Down
44 changes: 32 additions & 12 deletions src/ts/services/TyperighterTelemetryAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
ITyperighterTelemetryEvent,
ISuggestionAcceptedEvent,
TYPERIGHTER_TELEMETRY_TYPE,
IMarkAsCorrectEvent,
ISidebarClickEvent,
IMatchFoundEvent
} from "../interfaces/ITelemetryData";
import TelemetryService from './TelemetryService';
import { IMatch } from "..";

class TyperighterTelemetryAdapter {
constructor(
Expand All @@ -15,25 +12,32 @@ class TyperighterTelemetryAdapter {
private stage: string
) {}

public suggestionIsAccepted(tags: ISuggestionAcceptedEvent["tags"]) {
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
tags: {
suggestion,
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}

public matchIsMarkedAsCorrect(tags: IMarkAsCorrectEvent["tags"]) {
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
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}

Expand Down Expand Up @@ -70,27 +74,43 @@ class TyperighterTelemetryAdapter {
});
}

public sidebarMatchClicked(tags: ISidebarClickEvent["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
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}

public matchFound(tags: IMatchFoundEvent["tags"]) {
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
tags: {
documentUrl,
...this.getTelemetryTagsFromMatch(match)
}
});
}

private getTelemetryTagsFromMatch = (match: IMatch) => ({
ruleId: match.ruleId,
matchId: match.matchId,
matchedText: match.matchedText,
matchContext: match.matchContext,
matchHasReplacement: match.replacement ? 'true' : 'false',
matchIsAdvisory: 'false',
matchIsMarkedAsCorrect: match.markAsCorrect ? 'true' : 'false',
})
}

export default TyperighterTelemetryAdapter;

0 comments on commit 455922e

Please sign in to comment.