Skip to content

Commit 02ddf27

Browse files
committed
[Editor] Add some telemetry for the commenting feature (bug 1991172)
1 parent f64ece2 commit 02ddf27

4 files changed

Lines changed: 82 additions & 5 deletions

File tree

src/display/annotation_storage.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,22 @@ class AnnotationStorage {
222222
get editorStats() {
223223
let stats = null;
224224
const typeToEditor = new Map();
225+
let numberOfEditedComments = 0;
226+
let numberOfDeletedComments = 0;
225227
for (const value of this.#storage.values()) {
226228
if (!(value instanceof AnnotationEditor)) {
229+
if (value.popup.deleted) {
230+
numberOfDeletedComments += 1;
231+
} else if (value.popup) {
232+
numberOfEditedComments += 1;
233+
}
227234
continue;
228235
}
236+
if (value.isCommentDeleted) {
237+
numberOfDeletedComments += 1;
238+
} else if (value.hasEditedComment) {
239+
numberOfEditedComments += 1;
240+
}
229241
const editorStats = value.telemetryFinalData;
230242
if (!editorStats) {
231243
continue;
@@ -249,6 +261,16 @@ class AnnotationStorage {
249261
counters.set(val, count + 1);
250262
}
251263
}
264+
if (numberOfDeletedComments > 0 || numberOfEditedComments > 0) {
265+
stats ||= Object.create(null);
266+
stats.comments = {
267+
deleted: numberOfDeletedComments,
268+
edited: numberOfEditedComments,
269+
};
270+
}
271+
if (!stats) {
272+
return null;
273+
}
252274
for (const [type, editor] of typeToEditor) {
253275
stats[type] = editor.computeTelemetryFinalData(stats[type]);
254276
}

src/display/editor/editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,10 @@ class AnnotationEditor {
12411241
return this.#comment?.hasBeenEdited();
12421242
}
12431243

1244+
get hasDeletedComment() {
1245+
return this.#comment?.isDeleted();
1246+
}
1247+
12441248
get hasComment() {
12451249
return (
12461250
!!this.#comment && !this.#comment.isEmpty() && !this.#comment.isDeleted()

web/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,12 +1288,13 @@ const PDFViewerApplication = {
12881288
this._saveInProgress = false;
12891289
}
12901290

1291-
if (this._hasAnnotationEditors) {
1291+
const editorStats = this.pdfDocument?.annotationStorage.editorStats;
1292+
if (editorStats) {
12921293
this.externalServices.reportTelemetry({
12931294
type: "editing",
12941295
data: {
12951296
type: "save",
1296-
stats: this.pdfDocument?.annotationStorage.editorStats,
1297+
stats: editorStats,
12971298
},
12981299
});
12991300
}

web/comment_manager.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ class CommentManager {
5050
dateStyle: "long",
5151
});
5252
this.dialogElement = commentDialog.dialog;
53-
this.#dialog = new CommentDialog(commentDialog, overlayManager, ltr);
54-
this.#popup = new CommentPopup(dateFormat, ltr, this.dialogElement);
53+
this.#dialog = new CommentDialog(
54+
commentDialog,
55+
overlayManager,
56+
eventBus,
57+
ltr
58+
);
59+
this.#popup = new CommentPopup(
60+
eventBus,
61+
dateFormat,
62+
ltr,
63+
this.dialogElement
64+
);
5565
this.#sidebar = new CommentSidebar(
5666
sidebar,
5767
eventBus,
@@ -134,6 +144,8 @@ class CommentManager {
134144
class CommentSidebar {
135145
#annotations = null;
136146

147+
#eventBus;
148+
137149
#boundCommentClick = this.#commentClick.bind(this);
138150

139151
#boundCommentKeydown = this.#commentKeydown.bind(this);
@@ -199,6 +211,7 @@ class CommentSidebar {
199211
this.#popup = popup;
200212
this.#dateFormat = dateFormat;
201213
this.#ltr = ltr;
214+
this.#eventBus = eventBus;
202215

203216
const style = window.getComputedStyle(sidebar);
204217
this.#minWidth = parseFloat(style.getPropertyValue("--sidebar-min-width"));
@@ -306,6 +319,13 @@ class CommentSidebar {
306319
this.#setCommentsCount();
307320
}
308321
this.#sidebar.hidden = false;
322+
this.#eventBus.dispatch("reporttelemetry", {
323+
source: this,
324+
details: {
325+
type: "commentSidebar",
326+
data: { numberOfAnnotations: annotations.length },
327+
},
328+
});
309329
}
310330

311331
hide() {
@@ -672,14 +692,18 @@ class CommentDialog {
672692

673693
#isLTR;
674694

695+
#eventBus;
696+
675697
constructor(
676698
{ dialog, toolbar, title, textInput, cancelButton, saveButton },
677699
overlayManager,
700+
eventBus,
678701
ltr
679702
) {
680703
this.#dialog = dialog;
681704
this.#textInput = textInput;
682705
this.#overlayManager = overlayManager;
706+
this.#eventBus = eventBus;
683707
this.#saveButton = saveButton;
684708
this.#title = title;
685709
this.#isLTR = ltr;
@@ -863,6 +887,20 @@ class CommentDialog {
863887
}
864888

865889
#finish() {
890+
if (!this.#editor) {
891+
return;
892+
}
893+
const edited = this.#textInput.value !== this.#commentText;
894+
this.#eventBus.dispatch("reporttelemetry", {
895+
source: this,
896+
details: {
897+
type: "comment",
898+
data: {
899+
edited,
900+
},
901+
},
902+
});
903+
866904
this.#editor?.focusCommentButton();
867905
this.#editor = null;
868906
this.#textInput.value = this.#previousText = this.#commentText = "";
@@ -882,6 +920,8 @@ class CommentDialog {
882920
class CommentPopup {
883921
#buttonsContainer = null;
884922

923+
#eventBus;
924+
885925
#commentDialog;
886926

887927
#dateFormat;
@@ -910,7 +950,8 @@ class CommentPopup {
910950

911951
#visible = false;
912952

913-
constructor(dateFormat, ltr, commentDialog) {
953+
constructor(eventBus, dateFormat, ltr, commentDialog) {
954+
this.#eventBus = eventBus;
914955
this.#dateFormat = dateFormat;
915956
this.#isLTR = ltr;
916957
this.#commentDialog = commentDialog;
@@ -994,6 +1035,15 @@ class CommentPopup {
9941035
);
9951036
del.append(delLabel);
9961037
del.addEventListener("click", () => {
1038+
this.#eventBus.dispatch("reporttelemetry", {
1039+
source: this,
1040+
details: {
1041+
type: "comment",
1042+
data: {
1043+
deleted: true,
1044+
},
1045+
},
1046+
});
9971047
this.#editor.comment = null;
9981048
this.destroy();
9991049
});

0 commit comments

Comments
 (0)