Bug 1848870 - Instrument Shopping ReAnalysis Click r=TravisLong,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D186559
This commit is contained in:
Perry McManis
2023-08-28 18:47:09 +00:00
parent 76ee016c23
commit 1b54f3e87f
6 changed files with 97 additions and 0 deletions

View File

@@ -766,6 +766,7 @@ let JSWINDOWACTORS = {
// This is added so the actor instantiates immediately and makes
// methods available to the page js on load.
DOMDocElementInserted: {},
ShoppingTelemetryEvent: { wantUntrusted: true },
},
},
matches: ["about:shoppingsidebar"],

View File

@@ -76,6 +76,9 @@ export class ShoppingSidebarChild extends RemotePageChild {
case "PolledRequestMade":
this.updateContent({ isPolledRequest: true });
break;
case "ShoppingTelemetryEvent":
this.submitShoppingEvent(event.detail);
break;
}
}
@@ -222,4 +225,23 @@ export class ShoppingSidebarChild extends RemotePageChild {
});
win.document.dispatchEvent(evt);
}
/**
* Helper to handle telemetry events.
*
* @param {string} message
* Which Glean event to record too.
*/
submitShoppingEvent(message) {
// We are currently working through an actor to record Glean events and
// this function is where we will direct a custom actor event into the
// correct Glean event. However, this is an unpleasant solution and one
// that should not be replicated. Please reference bug 1848708 for more
// detail about why.
switch (message) {
case "reanalyzeClicked":
Glean.shopping.surfaceReanalyzeClicked.record();
break;
}
}
}

View File

@@ -39,6 +39,13 @@ class ShoppingMessageBar extends MozLitElement {
composed: true,
})
);
this.dispatchEvent(
new CustomEvent("ShoppingTelemetryEvent", {
bubbles: true,
composed: true,
detail: "reanalyzeClicked",
})
);
}
onClickProductAvailable() {

View File

@@ -70,3 +70,25 @@ shopping.settings:
send_in_pings:
- metrics
telemetry_mirror: SHOPPING_HAS_ONBOARDED
shopping:
surface_reanalyze_clicked:
type: event
description: |
The user clicked to REanalyze reviews in the shopping side bar. This
metric does not contain any information about the product the user is
viewing or any displayed trusted deals.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848870
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848870
data_sensitivity:
- interaction
expires: 122
send_in_pings:
- events
notification_emails:
- betling@mozilla.com
- fx-desktop-shopping-eng@mozilla.com
no_lint:
- COMMON_PREFIX

View File

@@ -21,5 +21,6 @@ prefs =
[browser_shopping_settings.js]
[browser_shopping_urlbar.js]
[browser_stale_product.js]
[browser_ui_telemetry.js]
[browser_unanalyzed_product.js]
[browser_unavailable_product.js]

View File

@@ -0,0 +1,44 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_shopping_reanalysis_event() {
// testFlushAllChildren() is necessary to deal with the event being
// recorded in content, but calling testGetValue() in parent.
await Services.fog.testFlushAllChildren();
Services.fog.testResetFOG();
await BrowserTestUtils.withNewTab(
{
url: "about:shoppingsidebar",
gBrowser,
},
async browser => {
await clickReAnalyzeLink(browser, MOCK_STALE_PRODUCT_RESPONSE);
}
);
await Services.fog.testFlushAllChildren();
var events = Glean.shopping.surfaceReanalyzeClicked.testGetValue();
Assert.greater(events.length, 0);
Assert.equal(events[0].category, "shopping");
Assert.equal(events[0].name, "surface_reanalyze_clicked");
});
function clickReAnalyzeLink(browser, data) {
return SpecialPowers.spawn(browser, [data], async mockData => {
let shoppingContainer =
content.document.querySelector("shopping-container").wrappedJSObject;
shoppingContainer.data = Cu.cloneInto(mockData, content);
await shoppingContainer.updateComplete;
let shoppingMessageBar = shoppingContainer.shoppingMessageBarEl;
await shoppingMessageBar.updateComplete;
await shoppingMessageBar.onClickAnalysisLink();
return "clicked";
});
}