Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #3713, Send Telemetry pings from the WebExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhirsch committed Aug 21, 2018
1 parent db2f33f commit d08961b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
9 changes: 0 additions & 9 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,5 @@ function handleMessage(msg, sender, sendReply) {
} else if (msg.funcName === "isHistoryEnabled") {
const historyEnabled = getBoolPref(HISTORY_ENABLED_PREF);
sendReply({type: "success", value: historyEnabled});
} else if (msg.funcName === "incrementCount") {
const allowedScalars = ["download", "upload", "copy"];
const scalar = msg.args && msg.args[0] && msg.args[0].scalar;
if (!allowedScalars.includes(scalar)) {
sendReply({type: "error", name: `incrementCount passed an unrecognized scalar ${scalar}`});
} else {
Services.telemetry.scalarAdd(`screenshots.${scalar}`, 1);
sendReply({type: "success", value: true});
}
}
}
12 changes: 12 additions & 0 deletions addon/webextension/background/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ this.analytics = (function() {
return Promise.resolve();
};

exports.incrementCount = function(scalar) {
const allowedScalars = ["download", "upload", "copy"];
if (!allowedScalars.includes(scalar)) {
const err = `incrementCount passed an unrecognized scalar ${scalar}`;
log.warn(err);
return Promise.resolve();
}
return browser.telemetry.scalarAdd(`screenshots.${scalar}`, 1).catch(err => {
log.warn(`incrementCount failed with error: ${err}`);
});
};

exports.refreshTelemetryPref = function() {
return browser.telemetry.canUpload().then((result) => {
telemetryPrefKnown = true;
Expand Down
6 changes: 3 additions & 3 deletions addon/webextension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ this.main = (function() {
const exports = {};

const pasteSymbol = (window.navigator.platform.match(/Mac/i)) ? "\u2318" : "Ctrl";
const { sendEvent } = analytics;
const { sendEvent, incrementCount } = analytics;

const manifest = browser.runtime.getManifest();
let backend;
Expand Down Expand Up @@ -229,7 +229,7 @@ this.main = (function() {
return blobConverters.blobToArray(blob).then(buffer => {
return browser.clipboard.setImageData(
buffer, blob.type.split("/", 2)[1]).then(() => {
catcher.watchPromise(communication.sendToBootstrap("incrementCount", {scalar: "copy"}));
catcher.watchPromise(incrementCount("copy"));
return browser.notifications.create({
type: "basic",
iconUrl: "../icons/copied-notification.svg",
Expand All @@ -256,7 +256,7 @@ this.main = (function() {
}
});
browser.downloads.onChanged.addListener(onChangedCallback);
catcher.watchPromise(communication.sendToBootstrap("incrementCount", {scalar: "download"}));
catcher.watchPromise(incrementCount("download"));
return browser.windows.getLastFocused().then(windowInfo => {
return browser.downloads.download({
url,
Expand Down
4 changes: 2 additions & 2 deletions addon/webextension/background/takeshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
this.takeshot = (function() {
const exports = {};
const Shot = shot.AbstractShot;
const { sendEvent } = analytics;
const { sendEvent, incrementCount } = analytics;

communication.register("takeShot", catcher.watchFunction((sender, options) => {
const { captureType, captureText, scroll, selectedPos, shotId } = options;
Expand Down Expand Up @@ -76,7 +76,7 @@ this.takeshot = (function() {
}
);
}).then(() => {
catcher.watchPromise(communication.sendToBootstrap("incrementCount", {scalar: "upload"}));
catcher.watchPromise(incrementCount("upload"));
return shot.viewUrl;
}).catch((error) => {
browser.tabs.remove(openedTab.id);
Expand Down

0 comments on commit d08961b

Please sign in to comment.