From d1f54414fd0e5c1cc831ce7780e8446e70dbfd19 Mon Sep 17 00:00:00 2001 From: Nan Jiang Date: Fri, 4 May 2018 17:33:57 -0400 Subject: [PATCH] Fix Bug 1459318 - Enable telemetry for AS Router --- docs/v2-system-addon/data_dictionary.md | 18 +++++++- docs/v2-system-addon/data_events.md | 41 ++++++++++++++++++- system-addon/lib/TelemetryFeed.jsm | 8 ++-- system-addon/test/schemas/pings.js | 11 +++++ .../test/unit/lib/TelemetryFeed.test.js | 12 ++++-- 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/docs/v2-system-addon/data_dictionary.md b/docs/v2-system-addon/data_dictionary.md index a97306808..3648e475c 100644 --- a/docs/v2-system-addon/data_dictionary.md +++ b/docs/v2-system-addon/data_dictionary.md @@ -140,6 +140,21 @@ Schema definitions/validations that can be used for tests can be found in `syste } ``` +# Example Activity Stream `Router` Pings + +```js +{ + "client_id": "n/a", + "action": ["snippets_user_event" | "onboarding_user_event"], + "impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}", + "source": "pocket", + "addon_version": "1.0.12", + "locale": "en-US", + "source": "NEWTAB_FOOTER_BAR", + "message_id": "some_snippet_id", + "event": "IMPRESSION" +} +``` | KEY | DESCRIPTION |   | |-----|-------------|:-----:| @@ -195,8 +210,9 @@ and losing focus. | :one: | `is_prerendered` | [Required] A boolean to signify whether the page is prerendered or not | :one: | `is_preloaded` | [Required] A boolean to signify whether the page is preloaded or not | :one: | `icon_type` | [Optional] ("tippytop", "rich_icon", "screenshot_with_icon", "screenshot", "no_image") | :one: -| `region` | [Optional] An string maps to pref "browser.search.region", which is essentially the two letter ISO 3166-1 country code populated by the Firefox search service. Note that: 1). it reports "OTHER" for those regions with smaller Firefox user base (less than 10000) so that users cannot be uniquely identified; 2). it reports "UNSET" if this pref is missing; 3). it reports "EMPTY" if the value of this pref is an empty string. | :one: +| `region` | [Optional] A string maps to pref "browser.search.region", which is essentially the two letter ISO 3166-1 country code populated by the Firefox search service. Note that: 1). it reports "OTHER" for those regions with smaller Firefox user base (less than 10000) so that users cannot be uniquely identified; 2). it reports "UNSET" if this pref is missing; 3). it reports "EMPTY" if the value of this pref is an empty string. | :one: | `profile_creation_date` | [Optional] An integer to record the age of the Firefox profile as the total number of days since the UNIX epoch. | :one: +|`message_id` | [required] A string identifier of the message in Activity Stream Router. | :one: **Where:** diff --git a/docs/v2-system-addon/data_events.md b/docs/v2-system-addon/data_events.md index 4fee41f4c..8d13cf0d2 100644 --- a/docs/v2-system-addon/data_events.md +++ b/docs/v2-system-addon/data_events.md @@ -462,7 +462,7 @@ This reports the duration of the domain affinity calculation in milliseconds. ## Undesired event pings -There pings record the undesired events happen in the addon for further investigation. +These pings record the undesired events happen in the addon for further investigation. ### Addon initialization failure @@ -479,3 +479,42 @@ This reports when the addon fails to initialize "value": -1 } ``` +## Activity Stream Router pings + +These pings record the impression and user interactions within Activity Stream Router. + +### Impression ping + +This reports the impression of Activity Stream Router. + +```js +{ + "client_id": "n/a", + "action": ["snippets_user_event" | "onboarding_user_event"], + "impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}", + "source": "pocket", + "addon_version": "1.0.12", + "locale": "en-US", + "source": "NEWTAB_FOOTER_BAR", + "message_id": "some_snippet_id", + "event": "IMPRESSION" +} +``` + + +### User interaction pings + +This reports the user's interaction with Activity Stream Router. + +```js +{ + "client_id": "n/a", + "action": ["snippets_user_event" | "onboarding_user_event"], + "addon_version": "1.0.12", + "impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}", + "locale": "en-US", + "source": "NEWTAB_FOOTER_BAR", + "message_id": "some_snippet_id", + "event": ["CLICK_BUTTION" | "BLOCK"] +} +``` diff --git a/system-addon/lib/TelemetryFeed.jsm b/system-addon/lib/TelemetryFeed.jsm index 2a74e9fd7..61e4ed717 100644 --- a/system-addon/lib/TelemetryFeed.jsm +++ b/system-addon/lib/TelemetryFeed.jsm @@ -368,8 +368,10 @@ this.TelemetryFeed = class TelemetryFeed { createASRouterEvent(action) { const appInfo = this.store.getState().App; const ping = { + client_id: "n/a", addon_version: appInfo.version, - locale: Services.locale.getAppLocaleAsLangTag() + locale: Services.locale.getAppLocaleAsLangTag(), + impression_id: this._impressionId }; return Object.assign(ping, action.data); } @@ -406,9 +408,7 @@ this.TelemetryFeed = class TelemetryFeed { handleASRouterUserEvent(action) { let event = this.createASRouterEvent(action); - // TODO call this.sendASRouterEvent(event) once the ping gets finalized - // and data reviewed - console.log(event); // eslint-disable-line + this.sendASRouterEvent(event); } handleUndesiredEvent(action) { diff --git a/system-addon/test/schemas/pings.js b/system-addon/test/schemas/pings.js index 5de2d4bbb..d48f1c749 100644 --- a/system-addon/test/schemas/pings.js +++ b/system-addon/test/schemas/pings.js @@ -202,6 +202,17 @@ export const SessionPing = Joi.object().keys(Object.assign({}, baseKeys, { }).required() })); +export const ASRouterEventPing = Joi.object().keys({ + client_id: Joi.string().required(), + action: Joi.string().required(), + impression_id: Joi.string().required(), + source: Joi.string().required(), + addon_version: Joi.string().required(), + locale: Joi.string().required(), + message_id: Joi.string().required(), + event: Joi.string().required() +}); + export const UTSessionPing = Joi.array().items( Joi.string().required().valid("activity_stream"), Joi.string().required().valid("end"), diff --git a/system-addon/test/unit/lib/TelemetryFeed.test.js b/system-addon/test/unit/lib/TelemetryFeed.test.js index 317f7b24a..7a1bf6ac5 100644 --- a/system-addon/test/unit/lib/TelemetryFeed.test.js +++ b/system-addon/test/unit/lib/TelemetryFeed.test.js @@ -1,6 +1,7 @@ /* global Services */ import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm"; import { + ASRouterEventPing, BasePing, ImpressionStatsPing, PerfPing, @@ -474,12 +475,17 @@ describe("TelemetryFeed", () => { }); describe("#createASRouterEvent", () => { it("should create a valid AS Router event", async () => { - const data = {source: "SNIPPETS", event: "CLICK"}; + const data = { + action: "snippet_user_event", + source: "SNIPPETS", + event: "CLICK", + message_id: "snippets_message_01" + }; const action = ac.ASRouterUserEvent(data); const ping = await instance.createASRouterEvent(action); - // TODO check the payload with the Joi schema - + assert.validate(ping, ASRouterEventPing); + assert.propertyVal(ping, "client_id", "n/a"); assert.propertyVal(ping, "source", "SNIPPETS"); assert.propertyVal(ping, "event", "CLICK"); });