Skip to content

Commit e070f91

Browse files
committed
Bug 1857324 - Add new "pocket-button" ping r=thecount
Depends on D190857 Differential Revision: https://phabricator.services.mozilla.com/D190858
1 parent ed5d9eb commit e070f91

File tree

6 files changed

+279
-0
lines changed

6 files changed

+279
-0
lines changed

browser/components/pocket/content/pktTelemetry.sys.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,38 @@ export var pktTelemetry = {
108108
STRUCTURED_INGESTION_NAMESPACE_AS
109109
);
110110
},
111+
112+
/**
113+
* Records the provided data and common pocket-button data to Glean,
114+
* then submits it all in a pocket-button ping.
115+
*
116+
* @param eventAction - A string like "click"
117+
* @param eventSource - A string like "save_button"
118+
* @param eventPosition - (optional) A 0-based index.
119+
* If falsey and not 0, is coalesced to undefined.
120+
* @param model - (optional) An identifier for the machine learning model
121+
* used to generate the recommendations like "vec-bestarticle"
122+
*/
123+
submitPocketButtonPing(
124+
eventAction,
125+
eventSource,
126+
eventPosition = undefined,
127+
model = undefined
128+
) {
129+
eventPosition = eventPosition || eventPosition === 0 ? 0 : undefined;
130+
Glean.pocketButton.impressionId.set(this.impressionId);
131+
Glean.pocketButton.pocketLoggedInStatus.set(lazy.pktApi.isUserLoggedIn());
132+
Glean.pocketButton.profileCreationDate.set(this._profileCreationDate());
133+
134+
Glean.pocketButton.eventAction.set(eventAction);
135+
Glean.pocketButton.eventSource.set(eventSource);
136+
if (eventPosition !== undefined) {
137+
Glean.pocketButton.eventPosition.set(eventPosition);
138+
}
139+
if (model !== undefined) {
140+
Glean.pocketButton.model.set(model);
141+
}
142+
143+
GleanPings.pocketButton.submit();
144+
},
111145
};

browser/components/pocket/content/pktUI.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ var pktUI = (function () {
226226
function onShowSignup() {
227227
// Ensure opening the signup panel clears the icon state from any previous sessions.
228228
SaveToPocket.itemDeleted();
229+
pktTelemetry.submitPocketButtonPing("click", "save_button");
229230
// A successful button click, for logged out users.
230231
pktTelemetry.sendStructuredIngestionEvent(
231232
pktTelemetry.createPingPayload({
@@ -240,6 +241,7 @@ var pktUI = (function () {
240241
}
241242

242243
async function onShowHome() {
244+
pktTelemetry.submitPocketButtonPing("click", "home_button");
243245
// A successful home button click.
244246
pktTelemetry.sendStructuredIngestionEvent(
245247
pktTelemetry.createPingPayload({
@@ -300,6 +302,7 @@ var pktUI = (function () {
300302
return;
301303
}
302304

305+
pktTelemetry.submitPocketButtonPing("click", "save_button");
303306
// A successful button click, for logged in users.
304307
pktTelemetry.sendStructuredIngestionEvent(
305308
pktTelemetry.createPingPayload({
@@ -451,6 +454,7 @@ var pktUI = (function () {
451454
// We don't track every click, only clicks with a known source.
452455
if (data.source) {
453456
const { position, source, model } = data;
457+
pktTelemetry.submitPocketButtonPing("click", source, position, model);
454458
const payload = pktTelemetry.createPingPayload({
455459
...(model ? { model } : {}),
456460
events: [
@@ -485,6 +489,12 @@ var pktUI = (function () {
485489
const { url, position, model } = data;
486490
// Check to see if we need to and can fire valid telemetry.
487491
if (model && (position || position === 0)) {
492+
pktTelemetry.submitPocketButtonPing(
493+
"click",
494+
"on_save_recs",
495+
position,
496+
model
497+
);
488498
const payload = pktTelemetry.createPingPayload({
489499
model,
490500
events: [
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
# Adding a new metric? We have docs for that!
6+
# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
7+
8+
---
9+
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
10+
$tags:
11+
- 'Firefox :: Pocket'
12+
13+
pocket.button:
14+
impression_id:
15+
type: uuid
16+
description: >
17+
A UUID representing this profile.
18+
This isn't client_id, nor can it be used to link to a client_id.
19+
This also means it should never be sent in a ping with a client_id.
20+
bugs:
21+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
22+
data_reviews:
23+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
24+
data_sensitivity:
25+
- technical
26+
notification_emails:
27+
- chutten@mozilla.com
28+
- kdemtchouk@mozilla.com
29+
- sdowne@mozilla.com
30+
expires: never
31+
send_in_pings: [ pocket-button ]
32+
33+
pocket_logged_in_status:
34+
type: boolean
35+
description: >
36+
Whether there was a logged-in Pocket account in the Pocket-Firefox
37+
integration at the point in time this action occurred.
38+
bugs:
39+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
40+
data_reviews:
41+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
42+
data_sensitivity:
43+
- technical
44+
notification_emails:
45+
- chutten@mozilla.com
46+
- kdemtchouk@mozilla.com
47+
- sdowne@mozilla.com
48+
expires: never
49+
send_in_pings: [ pocket-button ]
50+
51+
profile_creation_date:
52+
type: quantity
53+
unit: days_since_jan_1_1970
54+
description: >
55+
The days since Jan 1, 1970 that the oldest file in the profile dir was
56+
modified. Or created. Or just the day and time of the first thing to ask
57+
for the profile age called in. Or something earlier or later than that.
58+
59+
You may not want to use this.
60+
bugs:
61+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
62+
data_reviews:
63+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
64+
data_sensitivity:
65+
- technical
66+
notification_emails:
67+
- chutten@mozilla.com
68+
- kdemtchouk@mozilla.com
69+
- sdowne@mozilla.com
70+
expires: never
71+
send_in_pings: [ pocket-button ]
72+
73+
event_action:
74+
type: string
75+
description: >
76+
The action that was taken, like "click" or... actually, it might only
77+
ever be "click".
78+
bugs:
79+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
80+
data_reviews:
81+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
82+
data_sensitivity:
83+
- interaction
84+
notification_emails:
85+
- chutten@mozilla.com
86+
- kdemtchouk@mozilla.com
87+
- sdowne@mozilla.com
88+
expires: never
89+
send_in_pings: [ pocket-button ]
90+
91+
event_source:
92+
type: string
93+
description: >
94+
The source of the taken action, like "save_button", "home_button",
95+
"on_save_recs", or the like.
96+
bugs:
97+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
98+
data_reviews:
99+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
100+
data_sensitivity:
101+
- interaction
102+
notification_emails:
103+
- chutten@mozilla.com
104+
- kdemtchouk@mozilla.com
105+
- sdowne@mozilla.com
106+
expires: never
107+
send_in_pings: [ pocket-button ]
108+
109+
event_position:
110+
type: quantity
111+
unit: index
112+
description: >
113+
0-based index of the item on which the action was performed.
114+
Not always provided.
115+
bugs:
116+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
117+
data_reviews:
118+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
119+
data_sensitivity:
120+
- interaction
121+
notification_emails:
122+
- chutten@mozilla.com
123+
- kdemtchouk@mozilla.com
124+
- sdowne@mozilla.com
125+
expires: never
126+
send_in_pings: [ pocket-button ]
127+
128+
model:
129+
type: string
130+
description: >
131+
A string that identifies the ML model (if any) used to generate on-save
132+
recommendations. Like "doc2vec-incremental-best-article-pubspread".
133+
bugs:
134+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
135+
data_reviews:
136+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
137+
data_sensitivity:
138+
- interaction
139+
notification_emails:
140+
- chutten@mozilla.com
141+
- kdemtchouk@mozilla.com
142+
- sdowne@mozilla.com
143+
expires: never
144+
send_in_pings: [ pocket-button ]

browser/components/pocket/pings.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
---
6+
$schema: moz://mozilla.org/schemas/glean/pings/2-0-0
7+
8+
pocket-button:
9+
description: |
10+
Reinstrumentation of the Activity Stream "pocket-button" ping.
11+
Submitted when actions are taken around the pocket button.
12+
Does not contain any `client_id`.
13+
Instead uses an `impression_id`.
14+
include_client_id: false
15+
bugs:
16+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
17+
data_reviews:
18+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1857324
19+
notification_emails:
20+
- chutten@mozilla.com
21+
- kdemtchouk@mozilla.com
22+
- sdowne@mozilla.com

browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,70 @@ test_runner(async function test_generateStructuredIngestionEndpoint({
5252
"https://incoming.telemetry.mozilla.org/submit/activity-stream/pocket-button/1/7fd5a1ac-6089-4212-91a7-fcdec1d2f533"
5353
);
5454
});
55+
56+
test_runner(async function test_submitPocketButtonPing({ sandbox }) {
57+
const creationDate = "19640";
58+
const impressionId = "{422e3da9-c694-4fd2-b676-8ae070156128}";
59+
sandbox.stub(pktTelemetry, "impressionId").value(impressionId);
60+
sandbox.stub(pktTelemetry, "_profileCreationDate").returns(creationDate);
61+
62+
const eventAction = "some action like 'click'";
63+
const eventSource = "some source like 'save_button'";
64+
65+
const assertConstantStuff = () => {
66+
Assert.equal(
67+
"{" + Glean.pocketButton.impressionId.testGetValue() + "}",
68+
impressionId
69+
);
70+
Assert.equal(Glean.pocketButton.pocketLoggedInStatus.testGetValue(), false);
71+
Assert.equal(
72+
Glean.pocketButton.profileCreationDate.testGetValue(),
73+
creationDate
74+
);
75+
76+
Assert.equal(Glean.pocketButton.eventAction.testGetValue(), eventAction);
77+
Assert.equal(Glean.pocketButton.eventSource.testGetValue(), eventSource);
78+
};
79+
80+
let submitted = false;
81+
GleanPings.pocketButton.testBeforeNextSubmit(() => {
82+
submitted = true;
83+
assertConstantStuff();
84+
Assert.equal(Glean.pocketButton.eventPosition.testGetValue(), null);
85+
Assert.equal(Glean.pocketButton.model.testGetValue(), null);
86+
});
87+
88+
pktTelemetry.submitPocketButtonPing(eventAction, eventSource);
89+
Assert.ok(submitted, "Ping submitted successfully");
90+
91+
submitted = false;
92+
GleanPings.pocketButton.testBeforeNextSubmit(() => {
93+
submitted = true;
94+
assertConstantStuff();
95+
Assert.equal(Glean.pocketButton.eventPosition.testGetValue(), 0);
96+
Assert.equal(Glean.pocketButton.model.testGetValue(), null);
97+
});
98+
99+
pktTelemetry.submitPocketButtonPing(eventAction, eventSource, 0, null);
100+
Assert.ok(submitted, "Ping submitted successfully");
101+
102+
submitted = false;
103+
GleanPings.pocketButton.testBeforeNextSubmit(() => {
104+
submitted = true;
105+
assertConstantStuff();
106+
// falsey but not undefined positions will be omitted.
107+
Assert.equal(Glean.pocketButton.eventPosition.testGetValue(), null);
108+
Assert.equal(
109+
Glean.pocketButton.model.testGetValue(),
110+
"some-really-groovy-model"
111+
);
112+
});
113+
114+
pktTelemetry.submitPocketButtonPing(
115+
eventAction,
116+
eventSource,
117+
false,
118+
"some-really-groovy-model"
119+
);
120+
Assert.ok(submitted, "Ping submitted successfully");
121+
});

toolkit/components/glean/metrics_index.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"browser/components/metrics.yaml",
4444
"browser/components/migration/metrics.yaml",
4545
"browser/components/newtab/metrics.yaml",
46+
"browser/components/pocket/metrics.yaml",
4647
"browser/components/preferences/metrics.yaml",
4748
"browser/components/privatebrowsing/metrics.yaml",
4849
"browser/components/search/metrics.yaml",
@@ -106,6 +107,7 @@
106107
# Order is lexicographical, enforced by t/c/glean/tests/pytest/test_yaml_indices.py
107108
firefox_desktop_pings = [
108109
"browser/components/newtab/pings.yaml",
110+
"browser/components/pocket/pings.yaml",
109111
"browser/components/urlbar/pings.yaml",
110112
"toolkit/components/crashes/pings.yaml",
111113
"toolkit/components/telemetry/pings.yaml",

0 commit comments

Comments
 (0)