[Editor] Add some telemetry for the commenting feature (bug 1991172)

This commit is contained in:
Calixte Denizet 2025-09-26 19:55:27 +02:00
parent f64ece2a97
commit 02ddf277ab
4 changed files with 82 additions and 5 deletions

View File

@ -222,10 +222,22 @@ class AnnotationStorage {
get editorStats() { get editorStats() {
let stats = null; let stats = null;
const typeToEditor = new Map(); const typeToEditor = new Map();
let numberOfEditedComments = 0;
let numberOfDeletedComments = 0;
for (const value of this.#storage.values()) { for (const value of this.#storage.values()) {
if (!(value instanceof AnnotationEditor)) { if (!(value instanceof AnnotationEditor)) {
if (value.popup.deleted) {
numberOfDeletedComments += 1;
} else if (value.popup) {
numberOfEditedComments += 1;
}
continue; continue;
} }
if (value.isCommentDeleted) {
numberOfDeletedComments += 1;
} else if (value.hasEditedComment) {
numberOfEditedComments += 1;
}
const editorStats = value.telemetryFinalData; const editorStats = value.telemetryFinalData;
if (!editorStats) { if (!editorStats) {
continue; continue;
@ -249,6 +261,16 @@ class AnnotationStorage {
counters.set(val, count + 1); counters.set(val, count + 1);
} }
} }
if (numberOfDeletedComments > 0 || numberOfEditedComments > 0) {
stats ||= Object.create(null);
stats.comments = {
deleted: numberOfDeletedComments,
edited: numberOfEditedComments,
};
}
if (!stats) {
return null;
}
for (const [type, editor] of typeToEditor) { for (const [type, editor] of typeToEditor) {
stats[type] = editor.computeTelemetryFinalData(stats[type]); stats[type] = editor.computeTelemetryFinalData(stats[type]);
} }

View File

@ -1241,6 +1241,10 @@ class AnnotationEditor {
return this.#comment?.hasBeenEdited(); return this.#comment?.hasBeenEdited();
} }
get hasDeletedComment() {
return this.#comment?.isDeleted();
}
get hasComment() { get hasComment() {
return ( return (
!!this.#comment && !this.#comment.isEmpty() && !this.#comment.isDeleted() !!this.#comment && !this.#comment.isEmpty() && !this.#comment.isDeleted()

View File

@ -1288,12 +1288,13 @@ const PDFViewerApplication = {
this._saveInProgress = false; this._saveInProgress = false;
} }
if (this._hasAnnotationEditors) { const editorStats = this.pdfDocument?.annotationStorage.editorStats;
if (editorStats) {
this.externalServices.reportTelemetry({ this.externalServices.reportTelemetry({
type: "editing", type: "editing",
data: { data: {
type: "save", type: "save",
stats: this.pdfDocument?.annotationStorage.editorStats, stats: editorStats,
}, },
}); });
} }

View File

@ -50,8 +50,18 @@ class CommentManager {
dateStyle: "long", dateStyle: "long",
}); });
this.dialogElement = commentDialog.dialog; this.dialogElement = commentDialog.dialog;
this.#dialog = new CommentDialog(commentDialog, overlayManager, ltr); this.#dialog = new CommentDialog(
this.#popup = new CommentPopup(dateFormat, ltr, this.dialogElement); commentDialog,
overlayManager,
eventBus,
ltr
);
this.#popup = new CommentPopup(
eventBus,
dateFormat,
ltr,
this.dialogElement
);
this.#sidebar = new CommentSidebar( this.#sidebar = new CommentSidebar(
sidebar, sidebar,
eventBus, eventBus,
@ -134,6 +144,8 @@ class CommentManager {
class CommentSidebar { class CommentSidebar {
#annotations = null; #annotations = null;
#eventBus;
#boundCommentClick = this.#commentClick.bind(this); #boundCommentClick = this.#commentClick.bind(this);
#boundCommentKeydown = this.#commentKeydown.bind(this); #boundCommentKeydown = this.#commentKeydown.bind(this);
@ -199,6 +211,7 @@ class CommentSidebar {
this.#popup = popup; this.#popup = popup;
this.#dateFormat = dateFormat; this.#dateFormat = dateFormat;
this.#ltr = ltr; this.#ltr = ltr;
this.#eventBus = eventBus;
const style = window.getComputedStyle(sidebar); const style = window.getComputedStyle(sidebar);
this.#minWidth = parseFloat(style.getPropertyValue("--sidebar-min-width")); this.#minWidth = parseFloat(style.getPropertyValue("--sidebar-min-width"));
@ -306,6 +319,13 @@ class CommentSidebar {
this.#setCommentsCount(); this.#setCommentsCount();
} }
this.#sidebar.hidden = false; this.#sidebar.hidden = false;
this.#eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "commentSidebar",
data: { numberOfAnnotations: annotations.length },
},
});
} }
hide() { hide() {
@ -672,14 +692,18 @@ class CommentDialog {
#isLTR; #isLTR;
#eventBus;
constructor( constructor(
{ dialog, toolbar, title, textInput, cancelButton, saveButton }, { dialog, toolbar, title, textInput, cancelButton, saveButton },
overlayManager, overlayManager,
eventBus,
ltr ltr
) { ) {
this.#dialog = dialog; this.#dialog = dialog;
this.#textInput = textInput; this.#textInput = textInput;
this.#overlayManager = overlayManager; this.#overlayManager = overlayManager;
this.#eventBus = eventBus;
this.#saveButton = saveButton; this.#saveButton = saveButton;
this.#title = title; this.#title = title;
this.#isLTR = ltr; this.#isLTR = ltr;
@ -863,6 +887,20 @@ class CommentDialog {
} }
#finish() { #finish() {
if (!this.#editor) {
return;
}
const edited = this.#textInput.value !== this.#commentText;
this.#eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "comment",
data: {
edited,
},
},
});
this.#editor?.focusCommentButton(); this.#editor?.focusCommentButton();
this.#editor = null; this.#editor = null;
this.#textInput.value = this.#previousText = this.#commentText = ""; this.#textInput.value = this.#previousText = this.#commentText = "";
@ -882,6 +920,8 @@ class CommentDialog {
class CommentPopup { class CommentPopup {
#buttonsContainer = null; #buttonsContainer = null;
#eventBus;
#commentDialog; #commentDialog;
#dateFormat; #dateFormat;
@ -910,7 +950,8 @@ class CommentPopup {
#visible = false; #visible = false;
constructor(dateFormat, ltr, commentDialog) { constructor(eventBus, dateFormat, ltr, commentDialog) {
this.#eventBus = eventBus;
this.#dateFormat = dateFormat; this.#dateFormat = dateFormat;
this.#isLTR = ltr; this.#isLTR = ltr;
this.#commentDialog = commentDialog; this.#commentDialog = commentDialog;
@ -994,6 +1035,15 @@ class CommentPopup {
); );
del.append(delLabel); del.append(delLabel);
del.addEventListener("click", () => { del.addEventListener("click", () => {
this.#eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "comment",
data: {
deleted: true,
},
},
});
this.#editor.comment = null; this.#editor.comment = null;
this.destroy(); this.destroy();
}); });