Skip to content

Commit

Permalink
[Privacy Guide] Add metrics to record the Privacy Guide flow length
Browse files Browse the repository at this point in the history
Privacy Guide flow consists of multiple cards and varies from user to
user. Create a histogram with the flow length distribution of those generated Privacy Guide flows.

Change-Id: I9d130d7e1cc29d2b341a0229b092263055619550
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4183481
Reviewed-by: Sean Harrison <harrisonsean@chromium.org>
Commit-Queue: Aisulu Rakhmetullina <aisulu@google.com>
Auto-Submit: Aisulu Rakhmetullina <aisulu@google.com>
Reviewed-by: Rainhard Findling <rainhard@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1097511}
  • Loading branch information
Aisulu Rakhmetullina authored and Chromium LUCI CQ committed Jan 26, 2023
1 parent e50c462 commit 7b5bda3
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 1 deletion.
13 changes: 13 additions & 0 deletions chrome/browser/resources/settings/metrics_browser_proxy.ts
Expand Up @@ -280,6 +280,12 @@ export interface MetricsBrowserProxy {
*/
recordPrivacyGuideSettingsStatesHistogram(state: PrivacyGuideSettingsStates):
void;

/**
* Helper function that calls recordHistogram for the
* Settings.PrivacyGuide.FlowLength histogram
*/
recordPrivacyGuideFlowLengthHistogram(steps: number): void;
}

export class MetricsBrowserProxyImpl implements MetricsBrowserProxy {
Expand Down Expand Up @@ -388,6 +394,13 @@ export class MetricsBrowserProxyImpl implements MetricsBrowserProxy {
]);
}

recordPrivacyGuideFlowLengthHistogram(steps: number) {
chrome.send('metricsHandler:recordInHistogram', [
'Settings.PrivacyGuide.FlowLength', steps,
5, /*max number of the settings related steps in privacy guide is 4*/
]);
}

static getInstance(): MetricsBrowserProxy {
return instance || (instance = new MetricsBrowserProxyImpl());
}
Expand Down
Expand Up @@ -191,6 +191,8 @@ export class SettingsPrivacyGuidePageElement extends PrivacyGuideBase {
PrivacyGuideInteractions.WELCOME_NEXT_BUTTON);
this.metricsBrowserProxy_.recordAction(
'Settings.PrivacyGuide.NextClickWelcome');
this.metricsBrowserProxy_.recordPrivacyGuideFlowLengthHistogram(
this.computeStepIndicatorModel().total);
},
},
],
Expand Down
135 changes: 134 additions & 1 deletion chrome/test/data/webui/settings/privacy_guide_page_test.ts
Expand Up @@ -321,7 +321,12 @@ suite('PrivacyGuidePageTests', function() {
testMetricsBrowserProxy = new TestMetricsBrowserProxy();
MetricsBrowserProxyImpl.setInstance(testMetricsBrowserProxy);
syncBrowserProxy = new TestSyncBrowserProxy();
syncBrowserProxy.testSyncStatus = null;
setupSync({
syncBrowserProxy: syncBrowserProxy,
syncOn: true,
syncAllDataTypes: true,
typedUrlsSynced: true,
});
SyncBrowserProxyImpl.setInstance(syncBrowserProxy);

page = createPrivacyGuidePageForTest(settingsPrefs);
Expand Down Expand Up @@ -509,6 +514,134 @@ suite('PrivacyGuidePageTests', function() {
dispatchArrowLeftEvent();
assertWelcomeCardVisible(page);
});

test('settingsRelatedStepsShownInFlow_1_MSBB', async function() {
Router.getInstance().navigateTo(routes.PRIVACY_GUIDE);
await flushTasks();

setupSync({
syncBrowserProxy: syncBrowserProxy,
syncOn: false,
syncAllDataTypes: false,
typedUrlsSynced: false,
});
assertFalse(shouldShowHistorySyncCard(syncBrowserProxy));

page.setPrefValue('generated.safe_browsing', SafeBrowsingSetting.DISABLED);
assertFalse(shouldShowSafeBrowsingCard(page));

page.setPrefValue(
'generated.cookie_primary_setting', CookiePrimarySetting.ALLOW_ALL);
assertFalse(shouldShowCookiesCard(page));

// Clicking the welcome card 'Next' button fires a |start-button-click|
// event.
const welcomeFragment = page.shadowRoot!.querySelector<HTMLElement>(
'#' + PrivacyGuideStep.WELCOME);
assertTrue(!!welcomeFragment);
welcomeFragment.dispatchEvent(
new CustomEvent('start-button-click', {bubbles: true, composed: true}));
flush();

const result = await testMetricsBrowserProxy.whenCalled(
'recordPrivacyGuideFlowLengthHistogram');
assertEquals(1, result);
});

test('settingsRelatedStepsShownInFlow_2_MSBB_HistorySync', async function() {
Router.getInstance().navigateTo(routes.PRIVACY_GUIDE);
await flushTasks();

assertTrue(shouldShowHistorySyncCard(syncBrowserProxy));

page.setPrefValue('generated.safe_browsing', SafeBrowsingSetting.DISABLED);
assertFalse(shouldShowSafeBrowsingCard(page));

page.setPrefValue(
'generated.cookie_primary_setting', CookiePrimarySetting.ALLOW_ALL);
assertFalse(shouldShowCookiesCard(page));

// Clicking the welcome card 'Next' button fires a |start-button-click|
// event.
const welcomeFragment = page.shadowRoot!.querySelector<HTMLElement>(
'#' + PrivacyGuideStep.WELCOME);
assertTrue(!!welcomeFragment);
welcomeFragment.dispatchEvent(
new CustomEvent('start-button-click', {bubbles: true, composed: true}));
flush();

const result = await testMetricsBrowserProxy.whenCalled(
'recordPrivacyGuideFlowLengthHistogram');
assertEquals(2, result);
});

test(
'settingsRelatedStepsShownInFlow_3_MSBB_SafeBrowsing_Cookies',
async function() {
Router.getInstance().navigateTo(routes.PRIVACY_GUIDE);
await flushTasks();

setupSync({
syncBrowserProxy: syncBrowserProxy,
syncOn: false,
syncAllDataTypes: false,
typedUrlsSynced: false,
});
assertFalse(shouldShowHistorySyncCard(syncBrowserProxy));

page.setPrefValue(
'generated.safe_browsing', SafeBrowsingSetting.STANDARD);
assertTrue(shouldShowSafeBrowsingCard(page));

page.setPrefValue(
'generated.cookie_primary_setting',
CookiePrimarySetting.BLOCK_THIRD_PARTY_INCOGNITO);
assertTrue(shouldShowCookiesCard(page));

// Clicking the welcome card 'Next' button fires a |start-button-click|
// event.
const welcomeFragment = page.shadowRoot!.querySelector<HTMLElement>(
'#' + PrivacyGuideStep.WELCOME);
assertTrue(!!welcomeFragment);
welcomeFragment.dispatchEvent(new CustomEvent(
'start-button-click', {bubbles: true, composed: true}));
flush();

const result = await testMetricsBrowserProxy.whenCalled(
'recordPrivacyGuideFlowLengthHistogram');
assertEquals(3, result);
});

test(
'settingsRelatedStepsShownInFlow_4_MSBB_HistorySync_SafeBrowsing_Cookies',
async function() {
Router.getInstance().navigateTo(routes.PRIVACY_GUIDE);
await flushTasks();

assertTrue(shouldShowHistorySyncCard(syncBrowserProxy));

page.setPrefValue(
'generated.safe_browsing', SafeBrowsingSetting.ENHANCED);
assertTrue(shouldShowSafeBrowsingCard(page));

page.setPrefValue(
'generated.cookie_primary_setting',
CookiePrimarySetting.BLOCK_THIRD_PARTY);
assertTrue(shouldShowCookiesCard(page));

// Clicking the welcome card 'Next' button fires a |start-button-click|
// event.
const welcomeFragment = page.shadowRoot!.querySelector<HTMLElement>(
'#' + PrivacyGuideStep.WELCOME);
assertTrue(!!welcomeFragment);
welcomeFragment.dispatchEvent(new CustomEvent(
'start-button-click', {bubbles: true, composed: true}));
flush();

const result = await testMetricsBrowserProxy.whenCalled(
'recordPrivacyGuideFlowLengthHistogram');
assertEquals(4, result);
});
});

suite('MsbbCardNavigations', function() {
Expand Down
5 changes: 5 additions & 0 deletions chrome/test/data/webui/settings/test_metrics_browser_proxy.ts
Expand Up @@ -18,6 +18,7 @@ export class TestMetricsBrowserProxy extends TestBrowserProxy implements
'recordSafetyCheckUnusedSitePermissionsModuleInteractionsHistogram',
'recordSafetyCheckUnusedSitePermissionsModuleEntryPointShown',
'recordSettingsPageHistogram',
'recordPrivacyGuideFlowLengthHistogram',
'recordSafeBrowsingInteractionHistogram',
'recordPrivacyGuideNextNavigationHistogram',
'recordPrivacyGuideEntryExitHistogram',
Expand Down Expand Up @@ -91,4 +92,8 @@ export class TestMetricsBrowserProxy extends TestBrowserProxy implements
recordPrivacyGuideSettingsStatesHistogram(state: PrivacyGuideSettingsStates) {
this.methodCalled('recordPrivacyGuideSettingsStatesHistogram', state);
}

recordPrivacyGuideFlowLengthHistogram(steps: number) {
this.methodCalled('recordPrivacyGuideFlowLengthHistogram', steps);
}
}
12 changes: 12 additions & 0 deletions tools/metrics/histograms/metadata/settings/histograms.xml
Expand Up @@ -305,6 +305,18 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Settings.PrivacyGuide.FlowLength" units="steps"
expires_after="2023-07-26">
<owner>rainhard@chromium.org</owner>
<owner>msramek@chromium.org</owner>
<owner>chrome-friendly-settings@google.com</owner>
<summary>
The number of settings steps that can be shown in the Privacy Guide flow.
This number varies based on the users' setting states. Recorded when the
user clicks 'Next' in the Privacy Guide welcome card.
</summary>
</histogram>

<histogram name="Settings.PrivacyGuide.NextNavigation"
enum="SettingsPrivacyGuideInteractions" expires_after="2023-06-04">
<owner>harrisonsean@chromium.org</owner>
Expand Down

0 comments on commit 7b5bda3

Please sign in to comment.