Skip to content

Commit

Permalink
Feedback: Metrics to record user's preSubmitAction
Browse files Browse the repository at this point in the history
* Record user's pre submit action including: viewImage, viewMetrics and
viewSystemAndAppInfo.
* This is true-only boolean histogram, can fire 0 or more times.

Bug: b:185624798
Test: browser_tests --gtest_filter=OSFeedbackBrowserTest.*;
Change-Id: Id414487b2166742f0f610b85ee657d3bb1c7db3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3821710
Reviewed-by: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: Xiangdong Kong <xiangdongkong@google.com>
Commit-Queue: Longbo Wei <longbowei@google.com>
Cr-Commit-Position: refs/heads/main@{#1035155}
  • Loading branch information
Longbo Wei authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent f584c7e commit e013a0e
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 11 deletions.
19 changes: 17 additions & 2 deletions ash/webui/os_feedback_ui/backend/histogram_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@ void EmitFeedbackAppPostSubmitAction(
}

void EmitFeedbackAppPreSubmitAction(mojom::FeedbackAppPreSubmitAction action) {
// TODO(longbowei) Add preSubmit actions and use switch case statement.
base::UmaHistogramBoolean(kFeedbackAppViewedScreenshot, true);
switch (action) {
case mojom::FeedbackAppPreSubmitAction::kViewedScreenshot:
base::UmaHistogramBoolean(kFeedbackAppViewedScreenshot, true);
break;
case mojom::FeedbackAppPreSubmitAction::kViewedImage:
base::UmaHistogramBoolean(kFeedbackAppViewedImage, true);
break;
case mojom::FeedbackAppPreSubmitAction::kViewedSystemAndAppInfo:
base::UmaHistogramBoolean(kFeedbackAppViewedSystemAndAppInfo, true);
break;
case mojom::FeedbackAppPreSubmitAction::kViewedMetrics:
base::UmaHistogramBoolean(kFeedbackAppViewedMetrics, true);
break;
// TODO(longbowei): Handle ViewedHelpContent case.
case mojom::FeedbackAppPreSubmitAction::kViewedHelpContent:
break;
}
}

void EmitFeedbackAppIncludedScreenshot(bool included_screenshot) {
Expand Down
5 changes: 5 additions & 0 deletions ash/webui/os_feedback_ui/backend/histogram_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ constexpr char kFeedbackAppIncludedScreenshot[] =
"Feedback.ChromeOSApp.IncludedScreenshot";
constexpr char kFeedbackAppViewedScreenshot[] =
"Feedback.ChromeOSApp.ViewedScreenshot";
constexpr char kFeedbackAppViewedImage[] = "Feedback.ChromeOSApp.ViewedImage";
constexpr char kFeedbackAppViewedMetrics[] =
"Feedback.ChromeOSApp.ViewedMetrics";
constexpr char kFeedbackAppViewedSystemAndAppInfo[] =
"Feedback.ChromeOSApp.ViewedSystemAndAppInfo";
constexpr char kFeedbackAppCanContactUser[] =
"Feedback.ChromeOSApp.CanContactUser";
constexpr char kFeedbackAppIncludedFile[] = "Feedback.ChromeOSApp.IncludedFile";
Expand Down
8 changes: 7 additions & 1 deletion ash/webui/os_feedback_ui/resources/file_attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {assert} from 'chrome://resources/js/assert.m.js';
import {I18nBehavior, I18nBehaviorInterface} from 'chrome://resources/js/i18n_behavior.m.js';
import {html, mixinBehaviors, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {AttachedFile} from './feedback_types.js';
import {AttachedFile, FeedbackAppPreSubmitAction, FeedbackServiceProviderInterface} from './feedback_types.js';
import {getFeedbackServiceProvider} from './mojo_interface_provider.js';

/**
* @fileoverview
Expand Down Expand Up @@ -80,6 +81,9 @@ export class FileAttachmentElement extends FileAttachmentElementBase {
* @protected {boolean}
*/
this.hasSelectedAFile_;

/** @private {!FeedbackServiceProviderInterface} */
this.feedbackServiceProvider_ = getFeedbackServiceProvider();
}

ready() {
Expand Down Expand Up @@ -155,6 +159,8 @@ export class FileAttachmentElement extends FileAttachmentElementBase {
handleSelectedImageClick_() {
this.$.selectedImageDialog.showModal();
this.$.closeDialogButton.focus();
this.feedbackServiceProvider_.recordPreSubmitAction(
FeedbackAppPreSubmitAction.kViewedImage);
}

/** @protected */
Expand Down
14 changes: 10 additions & 4 deletions ash/webui/os_feedback_ui/resources/share_data_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,19 @@ export class ShareDataPageElement extends ShareDataPageElementBase {
const sysInfoLink = this.shadowRoot.querySelector('#sysInfoLink');
// Setting href causes <a> tag to display as link.
sysInfoLink.setAttribute('href', '#');
sysInfoLink.addEventListener(
'click', (e) => void this.handleOpenSystemInfoDialog_(e));
sysInfoLink.addEventListener('click', (e) => {
this.handleOpenSystemInfoDialog_(e);
this.feedbackServiceProvider_.recordPreSubmitAction(
FeedbackAppPreSubmitAction.kViewedSystemAndAppInfo);
});

const histogramsLink = this.shadowRoot.querySelector('#histogramsLink');
histogramsLink.setAttribute('href', '#');
histogramsLink.addEventListener(
'click', (e) => void this.handleOpenMetricsDialog_(e));
histogramsLink.addEventListener('click', (e) => {
this.handleOpenMetricsDialog_(e);
this.feedbackServiceProvider_.recordPreSubmitAction(
FeedbackAppPreSubmitAction.kViewedMetrics);
});
}

/** @private */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import 'chrome://resources/mojo/mojo/public/mojom/base/big_buffer.mojom-lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/string16.mojom-lite.js';

import {FakeFeedbackServiceProvider} from 'chrome://os-feedback/fake_feedback_service_provider.js';
import {FeedbackAppPreSubmitAction} from 'chrome://os-feedback/feedback_types.js';
import {FileAttachmentElement} from 'chrome://os-feedback/file_attachment.js';
import {setFeedbackServiceProviderForTesting} from 'chrome://os-feedback/mojo_interface_provider.js';
import {mojoString16ToString} from 'chrome://resources/ash/common/mojo_utils.js';
import {getDeepActiveElement} from 'chrome://resources/js/util.m.js';

Expand All @@ -21,8 +24,13 @@ export function fileAttachmentTestSuite() {
/** @type {?FileAttachmentElement} */
let page = null;

/** @type {?FakeFeedbackServiceProvider} */
let feedbackServiceProvider;

setup(() => {
document.body.innerHTML = '';
feedbackServiceProvider = new FakeFeedbackServiceProvider();
setFeedbackServiceProviderForTesting(feedbackServiceProvider);
});

teardown(() => {
Expand Down Expand Up @@ -59,6 +67,17 @@ export function fileAttachmentTestSuite() {
return element.textContent.trim();
}

/**
* @param {number} callCounts
* @param {FeedbackAppPreSubmitAction} action
* @private
*/
function verifyRecordPreSubmitActionCallCount(callCounts, action) {
assertEquals(
callCounts,
feedbackServiceProvider.getRecordPreSubmitActionCallCount(action));
}

// Test the page is loaded with expected HTML elements.
test('elementLoaded', async () => {
await initializePage();
Expand Down Expand Up @@ -301,6 +320,8 @@ export function fileAttachmentTestSuite() {
// focus on the close dialog icon button.
test('selectedImagePreviewDialog', async () => {
await initializePage();
verifyRecordPreSubmitActionCallCount(
0, FeedbackAppPreSubmitAction.kViewedImage);
const fakeData = [12, 11, 99];

/** @type {!File} */
Expand Down Expand Up @@ -328,6 +349,9 @@ export function fileAttachmentTestSuite() {
imageButton.click();
await imageClickPromise;

verifyRecordPreSubmitActionCallCount(
1, FeedbackAppPreSubmitAction.kViewedImage);

// The preview dialog's title should be set properly.
assertEquals('fake.png', getElementContent('#modalDialogTitleText'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,31 +594,39 @@ export function shareDataPageTestSuite() {
});

/**
* Test that feedbackServiceProvider.openMetricsDialog is called
* when #histogramsLink ("metrics") link is clicked.
* Test that openMetricsDialog and recordPreSubmitAction are called when
* #histogramsLink ("metrics") link is clicked.
*/
test('openMetricsDialog', async () => {
await initializePage();

assertEquals(0, feedbackServiceProvider.getOpenMetricsDialogCallCount());
verifyRecordPreSubmitActionCallCount(
0, FeedbackAppPreSubmitAction.kViewedMetrics);

getElement('#histogramsLink').click();

assertEquals(1, feedbackServiceProvider.getOpenMetricsDialogCallCount());
verifyRecordPreSubmitActionCallCount(
1, FeedbackAppPreSubmitAction.kViewedMetrics);
});

/**
* Test that feedbackServiceProvider.openSystemInfoDialog is called
* when #sysInfoLink ("system and app info") link is clicked.
* Test that openSystemInfoDialog and recordPreSubmitAction are called when
* #sysInfoLink ("system and app info") link is clicked.
*/
test('openSystemInfoDialog', async () => {
await initializePage();

assertEquals(0, feedbackServiceProvider.getOpenSystemInfoDialogCallCount());
verifyRecordPreSubmitActionCallCount(
0, FeedbackAppPreSubmitAction.kViewedSystemAndAppInfo);

getElement('#sysInfoLink').click();

assertEquals(1, feedbackServiceProvider.getOpenSystemInfoDialogCallCount());
verifyRecordPreSubmitActionCallCount(
1, FeedbackAppPreSubmitAction.kViewedSystemAndAppInfo);
});

/**
Expand Down
33 changes: 33 additions & 0 deletions tools/metrics/histograms/metadata/others/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5880,6 +5880,28 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Feedback.ChromeOSApp.ViewedImage" units="boolean"
expires_after="2023-07-27">
<owner>longbowei@google.com</owner>
<owner>xiangdongkong@google.com</owner>
<owner>cros-feedback-app@google.com</owner>
<summary>
Record number of times the user viewed the attached image. Fires when user
clicks the thumbnail and views the larger image.
</summary>
</histogram>

<histogram name="Feedback.ChromeOSApp.ViewedMetrics" units="boolean"
expires_after="2023-07-27">
<owner>longbowei@google.com</owner>
<owner>xiangdongkong@google.com</owner>
<owner>cros-feedback-app@google.com</owner>
<summary>
Record number of times the user viewed the metrics. Fires when user clicks
metrics link and views metrics.
</summary>
</histogram>

<histogram name="Feedback.ChromeOSApp.ViewedScreenshot" units="boolean"
expires_after="2023-07-27">
<owner>longbowei@google.com</owner>
Expand All @@ -5891,6 +5913,17 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Feedback.ChromeOSApp.ViewedSystemAndAppInfo" units="boolean"
expires_after="2023-07-27">
<owner>longbowei@google.com</owner>
<owner>xiangdongkong@google.com</owner>
<owner>cros-feedback-app@google.com</owner>
<summary>
Record number of times the user viewed the system and app information. Fires
when system and app info link is clicked.
</summary>
</histogram>

<histogram name="Feedback.Duration.FetchSystemInformation" units="ms"
expires_after="2023-03-25">
<owner>xiangdongkong@google.com</owner>
Expand Down

0 comments on commit e013a0e

Please sign in to comment.