Skip to content

Commit

Permalink
[Editor] Add some telemetry to know how often the editing features ar…
Browse files Browse the repository at this point in the history
…e used (bug 1782254)
  • Loading branch information
calixteman committed Aug 3, 2022
1 parent 803e7af commit 94f57e5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AnnotationStorage {
// can have undesirable effects.
this.onSetModified = null;
this.onResetModified = null;
this.onAnnotationEditor = null;
}

/**
Expand Down Expand Up @@ -100,6 +101,13 @@ class AnnotationStorage {
if (modified) {
this.#setModified();
}

if (
value instanceof AnnotationEditor &&
typeof this.onAnnotationEditor === "function"
) {
this.onAnnotationEditor(value.constructor._type);
}
}

/**
Expand Down Expand Up @@ -164,6 +172,15 @@ class AnnotationStorage {
return clone;
}

get hasAnnotationEditors() {
for (const value of this._storage.values()) {
if (value instanceof AnnotationEditor) {
return true;
}
}
return false;
}

/**
* PLEASE NOTE: Only intended for usage within the API itself.
* @ignore
Expand Down
2 changes: 2 additions & 0 deletions src/display/editor/freetext.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class FreeTextEditor extends AnnotationEditor {
],
]);

static _type = "freetext";

constructor(params) {
super({ ...params, name: "freeTextEditor" });
this.#color =
Expand Down
2 changes: 2 additions & 0 deletions src/display/editor/ink.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class InkEditor extends AnnotationEditor {

static _l10nPromise;

static _type = "ink";

constructor(params) {
super({ ...params, name: "inkEditor" });
this.color = params.color || null;
Expand Down
24 changes: 24 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,15 @@ const PDFViewerApplication = {
await this.pdfScriptingManager.dispatchDidSave();
this._saveInProgress = false;
}

if (this.pdfDocument?.annotationStorage.hasAnnotationEditors) {
this.externalServices.reportTelemetry({
type: "editing",
data: {
type: "save",
},
});
}
},

downloadOrSave() {
Expand Down Expand Up @@ -1734,6 +1743,12 @@ const PDFViewerApplication = {
delete this._annotationStorageModified;
}
};
annotationStorage.onAnnotationEditor = typeStr => {
this.externalServices.reportTelemetry({
type: "editing",
data: { type: typeStr },
});
};
},

setInitialView(
Expand Down Expand Up @@ -1872,6 +1887,15 @@ const PDFViewerApplication = {
this.externalServices.reportTelemetry({
type: "print",
});

if (this.pdfDocument?.annotationStorage.hasAnnotationEditors) {
this.externalServices.reportTelemetry({
type: "editing",
data: {
type: "print",
},
});
}
},

afterPrint() {
Expand Down

0 comments on commit 94f57e5

Please sign in to comment.