diff --git a/addon/background.js b/addon/background.js index fa43155..2ece215 100644 --- a/addon/background.js +++ b/addon/background.js @@ -57,6 +57,43 @@ sendEvent({ ni: true, }); +browser.contextMenus.create({ + id: "email-tab", + title: "Email Tab", + contexts: ["page", "tab"], + documentUrlPatterns: [""], +}); + +browser.contextMenus.onClicked.addListener(async (info, tab) => { + let mailProvider = (await browser.storage.local.get("mailProvider")).mailProvider; + if (!mailProvider) { + browser.notifications.create("error-no-preference", { + type: "basic", + title: "Email Tabs", + message: "You must first set your mail provider using the toolbar button", + }); + sendEvent({ + ec: "interface", + ea: "context-menu-failed-pref", + ni: true, + }); + return; + } + let customDimensions = { + cd1: await browser.tabs.query({currentWindow: true}).length, + cd2: 1, + cd3: tab.active, + cd6: false, + cd7: mailProvider, + }; + sendEvent(Object.assign({ + ec: "interface", + ea: "context-menu", + el: "email-tabs", + }, customDimensions)); + sendEmail([tab.id], mailProvider, customDimensions); +}); + function pause(time) { return new Promise((resolve) => { setTimeout(resolve, time); diff --git a/addon/manifest.json.tmpl b/addon/manifest.json.tmpl index 810683a..a563e6c 100644 --- a/addon/manifest.json.tmpl +++ b/addon/manifest.json.tmpl @@ -48,6 +48,7 @@ "clipboardWrite", "notifications", "storage", + "contextMenus", "" ] } diff --git a/docs/metrics.md b/docs/metrics.md index 9dbc8ee..7840575 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -147,6 +147,27 @@ cd6, cd7 ``` +###### When the user uses the context menu to email tabs + +``` +ec: interface +ea: context-menu, +el: email-tabs, +cd1, +cd2, +cd3, +cd6, +cd7 +``` + +####### If the context menu failed because no mail provider was selected + +``` +ec: interface, +ea: context-menu-failed-pref, +ni: true +``` + ###### When the user is not logged in, or encounters a compose window error `el` will be `account` if we believe the user encountered a login form, or `error` if there's some other problem encountered.