Also update METRICS.md to add the `'amazon_smile_link'` value for the `element` extra key for the `open_nonproduct_page` event, since that was part of the string change request as well.
Update METRICS.md to accurately reflect the current state of event telemetry in Firefox and in the extension:
* Firefox 62 added a new 'event' ping, so events are no longer appended to the 'main' ping.
* 'addonsManager' events are only available in Firefox 64+.
* Extension event telemetry is disabled with certain cookie settings.
This patch:
* Reverts "Collapse privacy extra keys into a single key" (commit 32fcfc4f924e2d53fb47dd615a090bda15e51e7c) while preserving the Common Extra Keys and Event-Specific Extra Keys subsections and updating the Sample Ping section in the METRICS.md document.
* Breaks out 'open_external_page' event (11 extra keys) into two events: 'open_nonproduct_page' (5 extra keys) and 'open_product_page' (10 extra keys).
Break up Extra Keys section into Common Extra Keys and Event-specific Extra Keys subsections. Update Sample Ping section to include additional common keys added from Issue #185.
Event Telemetry [limits the max number of extra keys](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html#limits) for an event to 10. In the fix for Issue #185, where three new privacy-related extra keys were added to every telemetry event, the number of extra keys for the 'open_external_page' event went to 11, which causes event telemetry to fail at the registration step.
This patch collapses these 3 privacy keys into a single key that points to a stringified JSON object.
* Update 'method' extra key for 'complete_extraction' event to have values of 'fathom', 'css_selectors', 'open_graph' or 'none' to distinguish between the two fallback extraction methods to Fathom: CSS Selectors or Open Graph attributes.
* Note: Since none of our five supported sites use Open Graph attributes currently for product information, we should not expect to see any successful extraction using that method for the MVP.
* Important caveats for making conclusions using these probes as-is:
* The coverage values that these probes will suggest will not be very accurate initially until we ensure we are extracting on only **product pages** for a supported site, rather than any page on the site (see Issues #225 and #181).
* Successful extraction does not mean that the information extracted for the product is correct. It only means that _a_ value was extracted for each product feature (i.e. title, image and price) on the page.
Add badge_toolbar_button and send_notification probes:
* Add an additional extra key, 'price_last_high' to 'send_notification' and 'open_external_page' (with 'element' value of 'system_notification') and update METRICS.md.
* Add a 'sendTelemetry' flag for the 'sendProductToBackground' function to also be removed when the 'resend' code is removed in './src/extraction/index.js'.
* Due to the fix for Issue #192, I was seeing some extra 'badge_toolbar_button' events (with 'badge_type' of 'add') as we are resending extracted product information 5 and 10 seconds after the product page loads.
* Update METRICS.md to clarify when 'badge_toolbar_button' with a 'badge_type' of 'price_alert' fires, since it will continue to fire for the same price alert until that alert is dismissed which is not obvious.
Add 'detect_price_change' probe
* Add `price_prev` extra key for `detect_price_change` event. This will be the same value as `price_orig` if there is only one price entry for the product when updating prices. This will help us answer questions around how much prices change in addition to how frequently.
Additionally:
* Update the name of the extension in METRICS.md to Price Wise.
* Add Appendix B to METRICS.md which explains how to view recorded telemetry events in about:telemetry.
* Add `visit_supported_site` and `hide_toolbar_button` probes.
* `hide_toolbar_button` required adding a new experimental API, `customizeUI`, which allows the extension to be notified when the Firefox CustomizeUI module detects the `onWidgetRemoved` event. This event fires any time a widget is removed from the chrome, including browserAction buttons. The widget is identified by a widgetId.
* Update METRICS.md to move `uninstall` probe to Appendix, since it is handled by the Addons Manager's event telemetry already.
* Create a new ./src/telemetry/content.js file to handle sending messages to the background telemetry script to record events from content scripts.
* Add `open_popup`, `open_external_page`, `add_product`, `delete_product` and `undo_delete_product` probes (See ./docs/METRICS.md for their specifications).
* Update `badge_type` `extra_key` description in METRICS.md to add a new enum value of 'unknown' in the case that the badge text is unrecognized, and a badge type cannot be determined.
* Update `addProductFromExtracted` action creator to return a thunk, which returns a random UUID (v4) for use as a product key in telemetry. This allows us to differentiate one product from another for a particular user. This is NOT a universal product id across all users.
* Add `tabId` URL searchParam to browserAction popup URL when an extracted product is found on the current page in order to obtain the `badge_type` `extra_key` value for the `open_popup` event.
Incorporate more feedback on the metrics used for the extension.
METRICS.md
* For the `open_external_page` probe, moved the ‘objects’ enums to their own ‘extra_key’, ‘element’. This is so that the schema doesn’t have to change if the content of these UI elements changes down the road (feedback from Osmose).
* Arrange list items in Definitions section in alphabetical order and add Price Alert definition.
* Move questions under ‘Does it affect user behavior in Firefox?’ in the Analysis section to the ‘Questions to answer in future experiments’ subsection.
* Fixed probe name typos.
* Ensured consistent whitespace and use of markdown symbols.
telemetry.js
* Instead of exporting a single object, export the methods from the module directly.
* Update probes based on changes to METRICS.md
config.js
* Unrelated to the telemetry issue here; fixed a typo I noticed.
METRICS.md
* Reorganized the questions in the Analysis section to fall under broad categories of questions.
* Added a scalar 'supported_sites' to keep track of the number of times the user visits one of the five supported websites.
* Added an 'extra_keys' section that explains up front what each key represents.
* Made data types for all scalar and event telemetry values more explicit.
* Added a 'detect_price_change' event.
* Updated and added new keys to provide more context around certain events and ensure data collection is Category 1 or 2 at most.
telemetry.js
* Updated registered events and scalars to match METRICS.md
Note: While this patch does not record any events or scalars itself, recording can be tested with the following after 'telemetry.recordProbes()' in './src/background/index.js':
```javascript
await telemetry.scalarAdd('supported_sites', 1);
await telemetry.recordEvent(
'badge_toolbar_button',
'toolbar_button',
null,
{
badge_type: 'add',
tracked_prods: '5',
},
);
```
* Adds METRICS.md document in a new 'docs' subfolder.
* Adds 'telemetry.js' background script which registers all events and provides a wrapper method to record events.
* The event 'send_system_notice' was originally 'send_system_notification', however, that exceeded the [string length limit](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html#limits) imposed by Event Telemetry.
* There is no need to unregister the events, as the events are only registered for the duration of the [current Firefox session](https://dxr.mozilla.org/mozilla-central/source/toolkit/components/telemetry/core/nsITelemetry.idl#484).
Note: This PR does not actually record any events. That will happen in subsequent PRs. For the setup here, I did confirm that I can successfully records events in 'about:telemetry#events-tab' once 'browser.telemetry.recordEvent' is called. This can be confirmed by adding `telemetry.recordEvent('badge_toolbar_button', 'toolbar_button', null, {badge_type: 'add'});` after `telemetry.init()` in './src/background/index.js'.