Bug 1858540 - Implement telemetry events for enabling/disabling ads in review checker. r=TravisLong

Differential Revision: https://phabricator.services.mozilla.com/D190981
This commit is contained in:
Jared Hirsch
2023-11-29 23:19:52 +00:00
parent 5396f6ace6
commit 68ca411eac
5 changed files with 188 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ const LAST_AUTO_ACTIVATE_PREF =
"browser.shopping.experience2023.lastAutoActivate";
const AUTO_ACTIVATE_COUNT_PREF =
"browser.shopping.experience2023.autoActivateCount";
const ADS_USER_ENABLED_PREF = "browser.shopping.experience2023.ads.userEnabled";
const CFR_FEATURES_PREF =
"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features";
@@ -77,6 +78,7 @@ export const ShoppingUtils = {
// or adjusting onboarding-related prefs once per session.
this.setOnUpdate(undefined, undefined, this.optedIn);
this.recordUserAdsPreference();
this.initialized = true;
},
@@ -153,6 +155,10 @@ export const ShoppingUtils = {
Glean.shoppingSettings.hasOnboarded.set(current > 0);
},
recordUserAdsPreference() {
Glean.shoppingSettings.disabledAds.set(!ShoppingUtils.adsUserEnabled);
},
/**
* If the user has not opted in, automatically set the sidebar to `active` if:
* 1. The sidebar has not already been automatically set to `active` twice.
@@ -223,3 +229,11 @@ XPCOMUtils.defineLazyPreferenceGetter(
CFR_FEATURES_PREF,
true
);
XPCOMUtils.defineLazyPreferenceGetter(
ShoppingUtils,
"adsUserEnabled",
ADS_USER_ENABLED_PREF,
false,
ShoppingUtils.recordUserAdsPreference
);

View File

@@ -30,6 +30,8 @@ class ShoppingSettings extends MozLitElement {
onToggleRecommendations() {
this.adsEnabledByUser = this.recommendationsToggleEl.pressed;
let action = this.adsEnabledByUser ? "enabled" : "disabled";
Glean.shopping.surfaceAdsSettingToggled.record({ action });
RPMSetPref(
"browser.shopping.experience2023.ads.userEnabled",
this.adsEnabledByUser

View File

@@ -71,6 +71,26 @@ shopping.settings:
- metrics
telemetry_mirror: SHOPPING_HAS_ONBOARDED
disabled_ads:
type: boolean
lifetime: application
description: |
Indicates if the user has manually disabled ads. Set during shopping
component init and updated when changed in browser.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1858540
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1858540
data_sensitivity:
- interaction
expires: 134
notification_emails:
- betling@mozilla.com
- fx-desktop-shopping-eng@mozilla.com
send_in_pings:
- metrics
telemetry_mirror: SHOPPING_DISABLED_ADS
shopping:
surface_displayed:
type: event
@@ -578,3 +598,27 @@ shopping:
- fx-desktop-shopping-eng@mozilla.com
send_in_pings:
- events
surface_ads_setting_toggled:
type: event
description: |
The user clicked the settings toggle to enable or disable ads in the
sidebar settings component.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1858540
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1858540
data_sensitivity:
- interaction
expires: 134
notification_emails:
- betling@mozilla.com
- fx-desktop-shopping-eng@mozilla.com
send_in_pings:
- events
extra_keys:
action:
description: >
Whether the toggle was used to enable or disable ads. Possible values
are `enabled` and `disabled`.
type: string

View File

@@ -315,6 +315,119 @@ add_task(async function test_review_quality_explainer_link() {
});
});
// Start with ads user enabled, then disable them, and verify telemetry.
add_task(async function test_ads_disable_button_click() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.adsEnabled", true],
["browser.shopping.experience2023.ads.userEnabled", true],
],
});
await Services.fog.testFlushAllChildren();
Services.fog.testResetFOG();
await BrowserTestUtils.withNewTab(
{
url: "about:shoppingsidebar",
gBrowser,
},
async browser => {
let mockArgs = {
mockData: MOCK_ANALYZED_PRODUCT_RESPONSE,
mockRecommendationData: MOCK_RECOMMENDED_ADS_RESPONSE,
};
await clickAdsToggle(browser, mockArgs);
await Services.fog.testFlushAllChildren();
// Verify the ads state was changed to disabled.
let toggledEvents =
Glean.shopping.surfaceAdsSettingToggled.testGetValue();
assertEventMatches(toggledEvents[0], {
category: "shopping",
name: "surface_ads_setting_toggled",
extra: { action: "disabled" },
});
// Verify the ads disabled state is set to true.
Assert.equal(
Glean.shoppingSettings.disabledAds.testGetValue(),
true,
"Ads should be marked as disabled"
);
}
);
});
// Start with ads user disabled, then enable them, and verify telemetry.
add_task(async function test_ads_enable_button_click() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.adsEnabled", true],
["browser.shopping.experience2023.ads.userEnabled", false],
],
});
await Services.fog.testFlushAllChildren();
Services.fog.testResetFOG();
await BrowserTestUtils.withNewTab(
{
url: "about:shoppingsidebar",
gBrowser,
},
async browser => {
let mockArgs = {
mockData: MOCK_ANALYZED_PRODUCT_RESPONSE,
mockRecommendationData: MOCK_RECOMMENDED_ADS_RESPONSE,
};
await clickAdsToggle(browser, mockArgs);
await Services.fog.testFlushAllChildren();
// Verify the ads state was changed to enabled.
let toggledEvents =
Glean.shopping.surfaceAdsSettingToggled.testGetValue();
assertEventMatches(toggledEvents[0], {
category: "shopping",
name: "surface_ads_setting_toggled",
extra: { action: "enabled" },
});
// Verify the ads disabled state is set to false.
Assert.equal(
Glean.shoppingSettings.disabledAds.testGetValue(),
false,
"Ads should be marked as enabled"
);
}
);
});
function clickAdsToggle(browser, data) {
return SpecialPowers.spawn(browser, [data], async args => {
const { mockData, mockRecommendationData } = args;
let shoppingContainer =
content.document.querySelector("shopping-container").wrappedJSObject;
shoppingContainer.data = Cu.cloneInto(mockData, content);
shoppingContainer.recommendationData = Cu.cloneInto(
mockRecommendationData,
content
);
await shoppingContainer.updateComplete;
let shoppingSettings = shoppingContainer.settingsEl;
let toggle = shoppingSettings.recommendationsToggleEl;
toggle.click();
await shoppingContainer.updateComplete;
});
}
function clickReAnalyzeLink(browser, data) {
return SpecialPowers.spawn(browser, [data], async mockData => {
let shoppingContainer =

View File

@@ -8946,6 +8946,21 @@ shopping:
- 'firefox'
record_in_processes:
- main
disabled_ads:
bug_numbers:
- 1858540
description: >
Indicates if the user has manually disabled ads. Set during shopping
component init and updated when changed in browser.
expires: "134"
kind: boolean
notification_emails:
- betling@mozilla.com
- fx-desktop-shopping-eng@mozilla.com
products:
- 'firefox'
record_in_processes:
- main
power:
cpu_time_bogus_values: