Commit 3e2a6acc authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Record metric when toolbar button is shown

BUG=859563

Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Ibc3cefb18aa81a7a9c1a1a2bf25e6c533b527389
Reviewed-on: https://chromium-review.googlesource.com/1123057Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572227}
parent 139c3db1
...@@ -73,6 +73,7 @@ class ContextualSuggestionsMediator ...@@ -73,6 +73,7 @@ class ContextualSuggestionsMediator
private boolean mDidSuggestionsShowForTab; private boolean mDidSuggestionsShowForTab;
private boolean mHasRecordedPeekEventForTab; private boolean mHasRecordedPeekEventForTab;
private boolean mHasRecordedButtonShownForTab;
private boolean mHasReachedTargetScrollPercentage; private boolean mHasReachedTargetScrollPercentage;
private boolean mHasPeekDelayPassed; private boolean mHasPeekDelayPassed;
...@@ -140,24 +141,28 @@ class ContextualSuggestionsMediator ...@@ -140,24 +141,28 @@ class ContextualSuggestionsMediator
} }
} }
}; };
}
fullscreenManager.addListener(new FullscreenListener() { fullscreenManager.addListener(new FullscreenListener() {
@Override @Override
public void onContentOffsetChanged(float offset) {} public void onContentOffsetChanged(float offset) {}
@Override @Override
public void onControlsOffsetChanged( public void onControlsOffsetChanged(
float topOffset, float bottomOffset, boolean needsAnimate) { float topOffset, float bottomOffset, boolean needsAnimate) {
if (!mToolbarButtonEnabled) {
maybeShowContentInSheet(); maybeShowContentInSheet();
} else {
reportToolbarButtonShown();
} }
}
@Override @Override
public void onToggleOverlayVideoMode(boolean enabled) {} public void onToggleOverlayVideoMode(boolean enabled) {}
@Override @Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {} public void onBottomControlsHeightChanged(int bottomControlsHeight) {}
}); });
}
} }
/** Destroys the mediator. */ /** Destroys the mediator. */
...@@ -261,6 +266,7 @@ class ContextualSuggestionsMediator ...@@ -261,6 +266,7 @@ class ContextualSuggestionsMediator
mCoordinator.showSuggestions(mSuggestionsSource); mCoordinator.showSuggestions(mSuggestionsSource);
mCoordinator.expandBottomSheet(); mCoordinator.expandBottomSheet();
}, R.drawable.btn_star_filled, R.string.contextual_suggestions_button_description); }, R.drawable.btn_star_filled, R.string.contextual_suggestions_button_description);
reportToolbarButtonShown();
} else { } else {
setPeekConditions(suggestionsResult); setPeekConditions(suggestionsResult);
// If the controls are already off-screen, show the suggestions immediately so they // If the controls are already off-screen, show the suggestions immediately so they
...@@ -301,6 +307,20 @@ class ContextualSuggestionsMediator ...@@ -301,6 +307,20 @@ class ContextualSuggestionsMediator
} }
} }
private void reportToolbarButtonShown() {
assert mToolbarButtonEnabled;
if (mHasRecordedButtonShownForTab || areBrowserControlsHidden()
|| mSuggestionsSource == null || !mModel.hasSuggestions()) {
return;
}
mHasRecordedButtonShownForTab = true;
reportEvent(ContextualSuggestionsEvent.UI_BUTTON_SHOWN);
TrackerFactory.getTrackerForProfile(mProfile).notifyEvent(
EventConstants.CONTEXTUAL_SUGGESTIONS_BUTTON_SHOWN);
}
@Override @Override
public void clearState() { public void clearState() {
clearSuggestions(); clearSuggestions();
...@@ -356,6 +376,7 @@ class ContextualSuggestionsMediator ...@@ -356,6 +376,7 @@ class ContextualSuggestionsMediator
mDidSuggestionsShowForTab = false; mDidSuggestionsShowForTab = false;
mHasRecordedPeekEventForTab = false; mHasRecordedPeekEventForTab = false;
mHasRecordedButtonShownForTab = false;
mHasSheetBeenOpened = false; mHasSheetBeenOpened = false;
mHandler.removeCallbacksAndMessages(null); mHandler.removeCallbacksAndMessages(null);
mHasReachedTargetScrollPercentage = false; mHasReachedTargetScrollPercentage = false;
......
...@@ -55,6 +55,10 @@ found in the LICENSE file. ...@@ -55,6 +55,10 @@ found in the LICENSE file.
<td>Was sheet peeked</td> <td>Was sheet peeked</td>
<td id="sheet-peeked"></td> <td id="sheet-peeked"></td>
</tr> </tr>
<tr>
<td>Was button shown</td>
<td id="button-shown"></td>
</tr>
<tr> <tr>
<td>Was sheet opened</td> <td>Was sheet opened</td>
<td id="sheet-opened"></td> <td id="sheet-opened"></td>
......
...@@ -49,6 +49,8 @@ function addCachedMetricEventsToPage(metrics) { ...@@ -49,6 +49,8 @@ function addCachedMetricEventsToPage(metrics) {
metricEventClone.querySelector('#url').textContent = metricEvent.url; metricEventClone.querySelector('#url').textContent = metricEvent.url;
metricEventClone.querySelector('#sheet-peeked').textContent = metricEventClone.querySelector('#sheet-peeked').textContent =
metricEvent.sheetPeeked; metricEvent.sheetPeeked;
metricEventClone.querySelector('#button-shown').textContent =
metricEvent.buttonShown;
metricEventClone.querySelector('#sheet-opened').textContent = metricEventClone.querySelector('#sheet-opened').textContent =
metricEvent.sheetOpened; metricEvent.sheetOpened;
metricEventClone.querySelector('#sheet-closed').textContent = metricEventClone.querySelector('#sheet-closed').textContent =
......
...@@ -63,6 +63,9 @@ struct MetricEvent { ...@@ -63,6 +63,9 @@ struct MetricEvent {
// Did the sheet peek show. // Did the sheet peek show.
bool sheet_peeked; bool sheet_peeked;
// Was the toolbar button shown.
bool button_shown;
// If the peek was closed without being opened. // If the peek was closed without being opened.
bool sheet_opened; bool sheet_opened;
......
...@@ -77,6 +77,7 @@ void EocInternalsPageHandler::GetCachedMetricEvents( ...@@ -77,6 +77,7 @@ void EocInternalsPageHandler::GetCachedMetricEvents(
auto metric_event = eoc_internals::mojom::MetricEvent::New(); auto metric_event = eoc_internals::mojom::MetricEvent::New();
metric_event->url = debug_event.url; metric_event->url = debug_event.url;
metric_event->sheet_peeked = debug_event.sheet_peeked; metric_event->sheet_peeked = debug_event.sheet_peeked;
metric_event->button_shown = debug_event.button_shown;
metric_event->sheet_opened = debug_event.sheet_opened; metric_event->sheet_opened = debug_event.sheet_opened;
metric_event->sheet_closed = debug_event.sheet_closed; metric_event->sheet_closed = debug_event.sheet_closed;
metric_event->any_suggestion_taken = debug_event.any_suggestion_taken; metric_event->any_suggestion_taken = debug_event.any_suggestion_taken;
......
...@@ -34,6 +34,10 @@ public final class EventConstants { ...@@ -34,6 +34,10 @@ public final class EventConstants {
*/ */
public static final String PULL_TO_REFRESH = "pull_to_refresh"; public static final String PULL_TO_REFRESH = "pull_to_refresh";
/** The contextual suggestions button was shown to the user. */
public static final String CONTEXTUAL_SUGGESTIONS_BUTTON_SHOWN =
"contextual_suggestions_button_shown";
/** /**
* The contextual suggestions bottom sheet was explicitly dismissed via a tap on its close * The contextual suggestions bottom sheet was explicitly dismissed via a tap on its close
* button. * button.
......
...@@ -48,6 +48,9 @@ void ContextualSuggestionsDebuggingReporter::RecordEvent( ...@@ -48,6 +48,9 @@ void ContextualSuggestionsDebuggingReporter::RecordEvent(
case UI_PEEK_REVERSE_SCROLL: case UI_PEEK_REVERSE_SCROLL:
current_event_.sheet_peeked = true; current_event_.sheet_peeked = true;
return; return;
case UI_BUTTON_SHOWN:
current_event_.button_shown = true;
return;
case UI_OPENED: case UI_OPENED:
current_event_.sheet_opened = true; current_event_.sheet_opened = true;
return; return;
......
...@@ -35,6 +35,9 @@ struct ContextualSuggestionsDebuggingEvent { ...@@ -35,6 +35,9 @@ struct ContextualSuggestionsDebuggingEvent {
// Whether the sheet ever peeked. // Whether the sheet ever peeked.
bool sheet_peeked = false; bool sheet_peeked = false;
// Whether the button has even been shown.
bool button_shown = false;
}; };
// Reporter specialized for caching information for debugging purposes. // Reporter specialized for caching information for debugging purposes.
......
...@@ -14,6 +14,7 @@ namespace contextual_suggestions { ...@@ -14,6 +14,7 @@ namespace contextual_suggestions {
ContextualSuggestionsMetricsReporter::ContextualSuggestionsMetricsReporter() ContextualSuggestionsMetricsReporter::ContextualSuggestionsMetricsReporter()
: sheet_peeked_(false), : sheet_peeked_(false),
button_shown_(false),
sheet_opened_(false), sheet_opened_(false),
sheet_closed_(false), sheet_closed_(false),
any_suggestion_downloaded_(false), any_suggestion_downloaded_(false),
...@@ -64,6 +65,11 @@ void ContextualSuggestionsMetricsReporter::RecordUmaMetrics( ...@@ -64,6 +65,11 @@ void ContextualSuggestionsMetricsReporter::RecordUmaMetrics(
return; return;
sheet_peeked_ = true; sheet_peeked_ = true;
break; break;
case UI_BUTTON_SHOWN:
if (button_shown_)
return;
button_shown_ = true;
break;
case UI_OPENED: case UI_OPENED:
if (sheet_opened_) if (sheet_opened_)
return; return;
...@@ -97,6 +103,7 @@ void ContextualSuggestionsMetricsReporter::RecordUmaMetrics( ...@@ -97,6 +103,7 @@ void ContextualSuggestionsMetricsReporter::RecordUmaMetrics(
void ContextualSuggestionsMetricsReporter::ResetUma() { void ContextualSuggestionsMetricsReporter::ResetUma() {
sheet_peeked_ = false; sheet_peeked_ = false;
button_shown_ = false;
sheet_opened_ = false; sheet_opened_ = false;
sheet_closed_ = false; sheet_closed_ = false;
any_suggestion_downloaded_ = false; any_suggestion_downloaded_ = false;
......
...@@ -43,6 +43,8 @@ class ContextualSuggestionsMetricsReporter ...@@ -43,6 +43,8 @@ class ContextualSuggestionsMetricsReporter
// Internal UMA state data. // Internal UMA state data.
// Whether the sheet ever peeked. // Whether the sheet ever peeked.
bool sheet_peeked_; bool sheet_peeked_;
// Whether the button was ever shown.
bool button_shown_;
// Whether the sheet was ever opened. // Whether the sheet was ever opened.
bool sheet_opened_; bool sheet_opened_;
// Whether the sheet was closed. // Whether the sheet was closed.
......
...@@ -36,6 +36,7 @@ const int kSuggestionDownloaded = 11; ...@@ -36,6 +36,7 @@ const int kSuggestionDownloaded = 11;
const int kSuggestionClicked = 12; const int kSuggestionClicked = 12;
const int kUiDismissedWithoutOpen = 13; const int kUiDismissedWithoutOpen = 13;
const int kUiDismissedAfterOpen = 14; const int kUiDismissedAfterOpen = 14;
const int kUiButtonShown = 15;
} // namespace } // namespace
class ContextualSuggestionsMetricsReporterTest : public ::testing::Test { class ContextualSuggestionsMetricsReporterTest : public ::testing::Test {
...@@ -197,4 +198,51 @@ TEST_F(ContextualSuggestionsMetricsReporterTest, EnumNotReorderedTest) { ...@@ -197,4 +198,51 @@ TEST_F(ContextualSuggestionsMetricsReporterTest, EnumNotReorderedTest) {
GetReporter().Flush(); GetReporter().Flush();
} }
TEST_F(ContextualSuggestionsMetricsReporterTest, ButtonTest) {
base::HistogramTester histogram_tester;
GetReporter().SetupForPage(kTestNavigationUrl, GetSourceId());
GetReporter().RecordEvent(FETCH_REQUESTED);
GetReporter().RecordEvent(FETCH_COMPLETED);
GetReporter().RecordEvent(UI_BUTTON_SHOWN);
GetReporter().RecordEvent(UI_OPENED);
GetReporter().RecordEvent(SUGGESTION_DOWNLOADED);
GetReporter().RecordEvent(SUGGESTION_CLICKED);
// Flush data to write to UKM.
GetReporter().Flush();
// Check that we wrote something to UKM. Details of UKM reporting are tested
// in a different test suite.
TestUkmRecorder* test_ukm_recorder = GetTestUkmRecorder();
std::vector<const ukm::mojom::UkmEntry*> entry_vector =
test_ukm_recorder->GetEntriesByName(ContextualSuggestions::kEntryName);
EXPECT_EQ(1U, entry_vector.size());
const ukm::mojom::UkmEntry* first_entry = entry_vector[0];
EXPECT_TRUE(test_ukm_recorder->EntryHasMetric(
first_entry, ContextualSuggestions::kFetchStateName));
EXPECT_EQ(static_cast<int64_t>(FetchState::COMPLETED),
*(test_ukm_recorder->GetEntryMetric(
first_entry, ContextualSuggestions::kFetchStateName)));
// Test that the expected histogram events were written.
histogram_tester.ExpectBucketCount(kEventsHistogramName, kUninitialized, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchDelayed, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchRequested, 1);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchError, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchServerBusy, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchBelowThreshold,
0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchEmpty, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kFetchCompleted, 1);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kUiButtonShown, 1);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kUiOpened, 1);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kUiClosedObsolete,
0);
histogram_tester.ExpectBucketCount(kEventsHistogramName,
kSuggestionDownloaded, 1);
histogram_tester.ExpectBucketCount(kEventsHistogramName, kSuggestionClicked,
1);
histogram_tester.ExpectBucketCount(kEventsHistogramName,
kUiDismissedWithoutOpen, 0);
histogram_tester.ExpectBucketCount(kEventsHistogramName,
kUiDismissedAfterOpen, 0);
}
} // namespace contextual_suggestions } // namespace contextual_suggestions
...@@ -86,9 +86,11 @@ enum ContextualSuggestionsEvent { ...@@ -86,9 +86,11 @@ enum ContextualSuggestionsEvent {
// The UI was dismissed after having been opened. This means the sheet was // The UI was dismissed after having been opened. This means the sheet was
// closed from any position after it was expanded at least once. // closed from any position after it was expanded at least once.
UI_DISMISSED_AFTER_OPEN = 14, UI_DISMISSED_AFTER_OPEN = 14,
// The UI button was shown to the user.
UI_BUTTON_SHOWN = 15,
// Special name that marks the maximum value in an Enum used for UMA. // Special name that marks the maximum value in an Enum used for UMA.
// https://cs.chromium.org/chromium/src/tools/metrics/histograms/README.md. // https://cs.chromium.org/chromium/src/tools/metrics/histograms/README.md.
kMaxValue = UI_DISMISSED_AFTER_OPEN, kMaxValue = UI_BUTTON_SHOWN,
}; };
// Tracks various metrics based on reports of events that take place // Tracks various metrics based on reports of events that take place
......
...@@ -66,6 +66,10 @@ void ContextualSuggestionsUkmEntry::RecordEventMetrics( ...@@ -66,6 +66,10 @@ void ContextualSuggestionsUkmEntry::RecordEventMetrics(
trigger_event_ = TriggerEvent::REVERSE_SCROLL; trigger_event_ = TriggerEvent::REVERSE_SCROLL;
StartTimerIfNeeded(); StartTimerIfNeeded();
break; break;
case UI_BUTTON_SHOWN:
trigger_event_ = TriggerEvent::TOOLBAR_BUTTON;
StartTimerIfNeeded();
break;
case UI_OPENED: case UI_OPENED:
was_sheet_opened_ = true; was_sheet_opened_ = true;
StartTimerIfNeeded(); StartTimerIfNeeded();
......
...@@ -35,6 +35,7 @@ enum class FetchState { ...@@ -35,6 +35,7 @@ enum class FetchState {
enum class TriggerEvent { enum class TriggerEvent {
NEVER_SHOWN, NEVER_SHOWN,
REVERSE_SCROLL, REVERSE_SCROLL,
TOOLBAR_BUTTON,
}; };
// Writes a single UKM entry that describes the latest state of the event stream // Writes a single UKM entry that describes the latest state of the event stream
......
...@@ -104,4 +104,25 @@ TEST_F(ContextualSuggestionsUkmEntryTest, ExpectedOperationTest) { ...@@ -104,4 +104,25 @@ TEST_F(ContextualSuggestionsUkmEntryTest, ExpectedOperationTest) {
EXPECT_EQ(1, GetEntryMetric(ContextualSuggestions::kTriggerEventName)); EXPECT_EQ(1, GetEntryMetric(ContextualSuggestions::kTriggerEventName));
} }
TEST_F(ContextualSuggestionsUkmEntryTest, ExpectedOperationButtonTest) {
ukm_entry_->RecordEventMetrics(FETCH_DELAYED);
ukm_entry_->RecordEventMetrics(FETCH_REQUESTED);
ukm_entry_->RecordEventMetrics(FETCH_COMPLETED);
ukm_entry_->RecordEventMetrics(UI_BUTTON_SHOWN);
ukm_entry_->RecordEventMetrics(UI_OPENED);
ukm_entry_->RecordEventMetrics(SUGGESTION_DOWNLOADED);
ukm_entry_->RecordEventMetrics(SUGGESTION_DOWNLOADED);
ukm_entry_->RecordEventMetrics(SUGGESTION_CLICKED);
ukm_entry_->Flush();
EXPECT_EQ(1, GetEntryMetric(ContextualSuggestions::kAnyDownloadedName));
EXPECT_EQ(1, GetEntryMetric(ContextualSuggestions::kAnySuggestionTakenName));
EXPECT_EQ(0, GetEntryMetric(ContextualSuggestions::kClosedFromPeekName));
EXPECT_EQ(1, GetEntryMetric(ContextualSuggestions::kEverOpenedName));
EXPECT_EQ(static_cast<int64_t>(FetchState::COMPLETED),
GetEntryMetric(ContextualSuggestions::kFetchStateName));
EXPECT_LT(0,
GetEntryMetric(ContextualSuggestions::kShowDurationBucketMinName));
EXPECT_EQ(2, GetEntryMetric(ContextualSuggestions::kTriggerEventName));
}
} // namespace contextual_suggestions } // namespace contextual_suggestions
...@@ -7642,6 +7642,7 @@ Called by update_net_error_codes.py.--> ...@@ -7642,6 +7642,7 @@ Called by update_net_error_codes.py.-->
<int value="12" label="Suggestion clicked"/> <int value="12" label="Suggestion clicked"/>
<int value="13" label="UI dismissed without open"/> <int value="13" label="UI dismissed without open"/>
<int value="14" label="UI dismissed after open"/> <int value="14" label="UI dismissed after open"/>
<int value="15" label="UI button shown"/>
</enum> </enum>
<enum name="CookieCommitProblem"> <enum name="CookieCommitProblem">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment