From 9750ce63774002b7bee048beafae25ea2755623c Mon Sep 17 00:00:00 2001 From: Perry McManis Date: Tue, 12 Dec 2023 20:01:09 +0000 Subject: [PATCH] Bug 1869413 - New event for clicking the opt out button r=TravisLong,shopping-reviewers,Gijs Differential Revision: https://phabricator.services.mozilla.com/D196111 --- .../components/shopping/content/settings.mjs | 1 + browser/components/shopping/metrics.yaml | 17 +++++++ .../browser/browser_settings_telemetry.js | 48 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/browser/components/shopping/content/settings.mjs b/browser/components/shopping/content/settings.mjs index d57590e04d2bc..2f86492354bb3 100644 --- a/browser/components/shopping/content/settings.mjs +++ b/browser/components/shopping/content/settings.mjs @@ -44,6 +44,7 @@ class ShoppingSettings extends MozLitElement { // is never flipped, leaving the toolbar button in the active state. RPMSetPref("browser.shopping.experience2023.active", false); RPMSetPref("browser.shopping.experience2023.optedIn", 2); + Glean.shopping.surfaceOptOutButtonClicked.record(); } fakespotLinkClicked(e) { diff --git a/browser/components/shopping/metrics.yaml b/browser/components/shopping/metrics.yaml index 6109ba5ff0715..854bc0408f243 100644 --- a/browser/components/shopping/metrics.yaml +++ b/browser/components/shopping/metrics.yaml @@ -622,3 +622,20 @@ shopping: Whether the toggle was used to enable or disable ads. Possible values are `enabled` and `disabled`. type: string + + surface_opt_out_button_clicked: + type: event + description: | + The user clicked the button in the settings panel to turn off the shopping experience. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1869413 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1869413 + data_sensitivity: + - interaction + expires: 134 + notification_emails: + - betling@mozilla.com + - fx-desktop-shopping-eng@mozilla.com + send_in_pings: + - events diff --git a/browser/components/shopping/tests/browser/browser_settings_telemetry.js b/browser/components/shopping/tests/browser/browser_settings_telemetry.js index 452bd74ee05ae..803630f73dd60 100644 --- a/browser/components/shopping/tests/browser/browser_settings_telemetry.js +++ b/browser/components/shopping/tests/browser/browser_settings_telemetry.js @@ -52,3 +52,51 @@ add_task(async function test_shopping_setting_update() { await SpecialPowers.popPrefEnv(); }); + +add_task(async function test_shopping_settings_ads_enabled() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.shopping.experience2023.optedIn", 1]], + }); + await Services.fog.testFlushAllChildren(); + Services.fog.testResetFOG(); + + await BrowserTestUtils.withNewTab( + { + url: "about:shoppingsidebar", + gBrowser, + }, + async browser => { + await SpecialPowers.spawn( + browser, + [MOCK_ANALYZED_PRODUCT_RESPONSE], + async mockData => { + let shoppingContainer = + content.document.querySelector( + "shopping-container" + ).wrappedJSObject; + + shoppingContainer.data = Cu.cloneInto(mockData, content); + shoppingContainer.adsEnabled = true; + await shoppingContainer.updateComplete; + + let shoppingSettings = shoppingContainer.settingsEl; + ok(shoppingSettings, "Got the shopping-settings element"); + + let optOutButton = shoppingSettings.optOutButtonEl; + ok(optOutButton, "There should be an opt-out button"); + + optOutButton.click(); + } + ); + } + ); + + await Services.fog.testFlushAllChildren(); + var optOutClickedEvents = + Glean.shopping.surfaceOptOutButtonClicked.testGetValue(); + + Assert.equal(optOutClickedEvents.length, 1); + Assert.equal(optOutClickedEvents[0].category, "shopping"); + Assert.equal(optOutClickedEvents[0].name, "surface_opt_out_button_clicked"); + await SpecialPowers.popPrefEnv(); +});