Replace 'supported_sites' scalar with 'visit_supported_site' event

Event telemetry is easier from the analysis perspective to answer questions around frequency of visits.
This commit is contained in:
Bianca Danforth 2018-10-11 10:11:11 -07:00
Родитель d70ffd5d0e
Коммит 61a55bc39d
3 изменённых файлов: 37 добавлений и 42 удалений

Просмотреть файл

@ -82,15 +82,13 @@ While some of these questions may be partially answerable by this extension, ans
## Sample Pings
We will be sending pings using [Scalar](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/scalars.html) and [Event Telemetry](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html) via the [WebExtensions Telemetry API](https://bugzilla.mozilla.org/show_bug.cgi?id=1280234).
Each scalar will exist as part of the `main` ping under `payload.processes.dynamic.scalars` as a key-value pair in the `scalars` object. The data types for values are one of the scalar types (number, string or boolean).
We will be sending pings using [Event Telemetry](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html) via the [WebExtensions Telemetry API](https://bugzilla.mozilla.org/show_bug.cgi?id=1280234).
Each event will exist as part of the `main` ping under `payload.processes.dynamic.events` as an array in the `events` array. The data types of individual fields for each event follow the Event Telemetry [serialization format](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html#serialization-format).
The telemetry category for both scalars and events is `'extension.pricealerts'`. Note: Scalar telemetry category names [do not allow underscores](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/scalars.html#scalar-limitations).
The telemetry category for events is `'extension.price_alerts'`.
Below is a sample ping for the `supported_sites` scalar and `badge_toolbar_button` event.
Below is a sample ping for the `badge_toolbar_button` and `visit_supported_site` events.
```javascript
{
@ -101,13 +99,11 @@ Below is a sample ping for the `supported_sites` scalar and `badge_toolbar_butto
"processes": {
// ...
"dynamic": {
"scalars": {
"extension.pricealerts.supported_sites": 5
},
// ...
"events": [
[
1634,
"extension.pricealerts",
2079,
"extension.price_alerts",
"badge_toolbar_button",
"toolbar_button",
null,
@ -115,6 +111,16 @@ Below is a sample ping for the `supported_sites` scalar and `badge_toolbar_butto
"badge_type": "add",
"tracked_prods": "5"
}
],
[
2081,
"extension.price_alerts",
"visit_supported_site",
"supported_site",
null,
{
"tracked_prods": "5"
}
]
]
}
@ -154,17 +160,19 @@ Below is a sample ping for the `supported_sites` scalar and `badge_toolbar_butto
- `'walmart_link'`: Sends the user to Walmart.
## Collection (Scalars)
## Collection (User Events)
### `supported_sites`
### `visit_supported_site`
Increments when the user navigates to a Supported Site.
Fired when the user navigates to a Supported Site.
#### Payload properties
Note: The key below is the scalar name prepended with the telemetry category, separated by a `'.'`.
- `'extension.pricealerts.supported_sites'`: Number; the current count for the number of times the user has visited a Supported Site during the session.
## Collection (User Events)
- `methods`: String
- `'visit_supported_site'`
- `objects`: String
- `'supported_site'`
- `extra_keys`: Object
- `'tracked_prods'`
### `open_popup`

Просмотреть файл

@ -18,10 +18,10 @@ import {handleWebRequest, updatePrices} from 'commerce/background/price_updates'
import store from 'commerce/state';
import {checkMigrations} from 'commerce/state/migrations';
import {loadStateFromStorage} from 'commerce/state/sync';
import {registerProbes} from 'commerce/background/telemetry';
import {registerEvents} from 'commerce/background/telemetry';
(async function main() {
registerProbes();
registerEvents();
// Set browser action default badge color, which can't be set via manifest
browser.browserAction.setBadgeBackgroundColor({

Просмотреть файл

@ -3,23 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Registers and records telemetry scalars and events throughout the extension.
* Registers and records telemetry events throughout the extension.
* @module
*/
// Scalar category names can't have underscores
const CATEGORY = 'extension.pricealerts';
const SCALARS = {
// Incremented when the user navigates to a supported site (e.g. Amazon)
supported_sites: {
kind: 'count',
record_on_release: true,
},
};
const CATEGORY = 'extension.price_alerts';
const EVENTS = {
// User Events
// User visits a supported site
visit_supported_site: {
methods: ['visit_supported_site'],
objects: ['supported_site'],
extra_keys: ['tracked_prods'],
},
// User clicks toolbar button to open the popup
open_popup: {
methods: ['open_popup'],
@ -153,8 +151,7 @@ const EVENTS = {
},
};
export async function registerProbes() {
await browser.telemetry.registerScalars(CATEGORY, SCALARS);
export async function registerEvents() {
await browser.telemetry.registerEvents(CATEGORY, EVENTS);
}
@ -170,13 +167,3 @@ export async function recordEvent(method, object, value, extra) {
extra,
);
}
export async function scalarAdd(scalarName, value) {
if (!browser.telemetry.canUpload()) {
return;
}
await browser.telemetry.scalarAdd(
`${CATEGORY}.${scalarName}`,
value,
);
}