Commit f35d6bba authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Add page change interaction metrics to tab grid.

This CL adds a histogram to track which of three possible interactions were used to change the current page in the tab grid.

Bug: 879487
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I35d6cb289b4c9fb8418e8d40f356bf914ae5d302
Reviewed-on: https://chromium-review.googlesource.com/1193948
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587974}
parent ee0ee3d4
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -39,6 +40,37 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -39,6 +40,37 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
TabGridConfigurationFloatingButton, TabGridConfigurationFloatingButton,
}; };
// User interaction that triggered a page change, if any.
typedef NS_ENUM(NSUInteger, PageChangeInteraction) {
// There has been no interaction since the last page change.
PageChangeInteractionNone = 0,
// The user dragged in the scroll view to change pages.
PageChangeInteractionScrollDrag,
// The user tapped a segment of the page control to change pages.
PageChangeInteractionPageControlTap,
// The user dragged the page control slider to change pages.
PageChangeInteractionPageControlDrag,
};
// Key of the UMA IOS.TabSwitcher.PageChangeInteraction histogram.
const char kUMATabSwitcherPageChangeInteractionHistogram[] =
"IOS.TabSwitcher.PageChangeInteraction";
// Values of the UMA IOS.TabSwitcher.PageChangeInteraction histogram.
enum class TabSwitcherPageChangeInteraction {
kNone = 0,
kScrollDrag = 1,
kControlTap = 2,
kControlDrag = 3,
kMaxValue = kControlDrag,
};
// Convenience function to record a page change interaction.
void RecordPageChangeInteraction(TabSwitcherPageChangeInteraction interaction) {
UMA_HISTOGRAM_ENUMERATION(kUMATabSwitcherPageChangeInteractionHistogram,
interaction);
}
// Computes the page from the offset and width of |scrollView|. // Computes the page from the offset and width of |scrollView|.
TabGridPage GetPageFromScrollView(UIScrollView* scrollView) { TabGridPage GetPageFromScrollView(UIScrollView* scrollView) {
CGFloat pageWidth = scrollView.frame.size.width; CGFloat pageWidth = scrollView.frame.size.width;
...@@ -97,6 +129,8 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -97,6 +129,8 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
// Whether the scroll view is animating its content offset to the current page. // Whether the scroll view is animating its content offset to the current page.
@property(nonatomic, assign, getter=isScrollViewAnimatingContentOffset) @property(nonatomic, assign, getter=isScrollViewAnimatingContentOffset)
BOOL scrollViewAnimatingContentOffset; BOOL scrollViewAnimatingContentOffset;
@property(nonatomic, assign) PageChangeInteraction pageChangeInteraction;
@end @end
@implementation TabGridViewController @implementation TabGridViewController
...@@ -129,6 +163,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -129,6 +163,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
@synthesize initialFrame = _initialFrame; @synthesize initialFrame = _initialFrame;
@synthesize scrollViewAnimatingContentOffset = @synthesize scrollViewAnimatingContentOffset =
_scrollViewAnimatingContentOffset; _scrollViewAnimatingContentOffset;
@synthesize pageChangeInteraction = _pageChangeInteraction;
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
...@@ -272,6 +307,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -272,6 +307,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
// tapping on the page control during scrolling can result in erratic // tapping on the page control during scrolling can result in erratic
// scrolling. // scrolling.
self.topToolbar.pageControl.userInteractionEnabled = NO; self.topToolbar.pageControl.userInteractionEnabled = NO;
self.pageChangeInteraction = PageChangeInteractionScrollDrag;
[self updatePageViewAccessibilityVisibility]; [self updatePageViewAccessibilityVisibility];
} }
...@@ -283,6 +319,9 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -283,6 +319,9 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { - (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView {
// Mark the interaction as ended, so that scrolls that don't change page don't
// cause other interactions to be mislabeled.
self.pageChangeInteraction = PageChangeInteractionNone;
[self updatePageViewAccessibilityVisibility]; [self updatePageViewAccessibilityVisibility];
} }
...@@ -1028,6 +1067,26 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -1028,6 +1067,26 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
"MobileTabSwitcherHeaderViewSelectDistantSessionPanel")); "MobileTabSwitcherHeaderViewSelectDistantSessionPanel"));
break; break;
} }
switch (self.pageChangeInteraction) {
case PageChangeInteractionNone:
// This shouldn't happen, but in case it does happen in release, track it.
NOTREACHED() << "Recorded a page change with no interaction.";
RecordPageChangeInteraction(TabSwitcherPageChangeInteraction::kNone);
break;
case PageChangeInteractionScrollDrag:
RecordPageChangeInteraction(
TabSwitcherPageChangeInteraction::kScrollDrag);
break;
case PageChangeInteractionPageControlTap:
RecordPageChangeInteraction(
TabSwitcherPageChangeInteraction::kControlTap);
break;
case PageChangeInteractionPageControlDrag:
RecordPageChangeInteraction(
TabSwitcherPageChangeInteraction::kControlDrag);
break;
}
self.pageChangeInteraction = PageChangeInteractionNone;
} }
// Tells the appropriate delegate to create a new item, and then tells the // Tells the appropriate delegate to create a new item, and then tells the
...@@ -1224,6 +1283,8 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -1224,6 +1283,8 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
if (UseRTLLayout()) if (UseRTLLayout())
offset = 1.0 - offset; offset = 1.0 - offset;
self.pageChangeInteraction = PageChangeInteractionPageControlDrag;
// Total space available for the scroll view to scroll (horizontally). // Total space available for the scroll view to scroll (horizontally).
CGFloat offsetWidth = CGFloat offsetWidth =
self.scrollView.contentSize.width - self.scrollView.frame.size.width; self.scrollView.contentSize.width - self.scrollView.frame.size.width;
...@@ -1236,9 +1297,19 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -1236,9 +1297,19 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
- (void)pageControlChangedPage:(id)sender { - (void)pageControlChangedPage:(id)sender {
TabGridPage newPage = self.topToolbar.pageControl.selectedPage; TabGridPage newPage = self.topToolbar.pageControl.selectedPage;
// If the user has dragged the page control, -pageControlChangedPage: will be
// called after the calls to -pageControlChangedValue:, so only set the
// interaction here if one hasn't already been set.
if (self.pageChangeInteraction == PageChangeInteractionNone)
self.pageChangeInteraction = PageChangeInteractionPageControlTap;
TabGridPage currentPage = self.currentPage;
[self setCurrentPage:newPage animated:YES]; [self setCurrentPage:newPage animated:YES];
// Records when the user taps on the pageControl to switch pages. // Records when the user uses the pageControl to switch pages.
[self recordActionSwitchingToPage:newPage]; if (currentPage != newPage)
[self recordActionSwitchingToPage:newPage];
// Regardless of whether the page changed, mark the interaction as done.
self.pageChangeInteraction = PageChangeInteractionNone;
} }
#pragma mark - UIResponder #pragma mark - UIResponder
......
...@@ -26083,6 +26083,13 @@ Called by update_gpu_driver_bug_workaround_entries.py.--> ...@@ -26083,6 +26083,13 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="3" label="Actions"/> <int value="3" label="Actions"/>
</enum> </enum>
<enum name="IOSTabSwitcherPageChangeInteraction">
<int value="0" label="Unknown Interaction"/>
<int value="1" label="Scroll View Drag"/>
<int value="2" label="Page Control Tap"/>
<int value="3" label="Page Control Drag"/>
</enum>
<enum name="IPCAttachmentBrokerPrivilegedBrokerAttachmentError"> <enum name="IPCAttachmentBrokerPrivilegedBrokerAttachmentError">
<int value="0" label="DESTINATION_FOUND"> <int value="0" label="DESTINATION_FOUND">
The brokerable attachment had a valid destination. This is the success case. The brokerable attachment had a valid destination. This is the success case.
...@@ -38457,6 +38457,15 @@ uploading your change for review. ...@@ -38457,6 +38457,15 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="IOS.TabSwitcher.PageChangeInteraction"
enum="IOSTabSwitcherPageChangeInteraction">
<owner>marq@chromium.org</owner>
<summary>
The UI interaction by which the user changed the visible page in the tab
switcher.
</summary>
</histogram>
<histogram name="IOS.WKWebViewFinishBeforeCommit" enum="Boolean"> <histogram name="IOS.WKWebViewFinishBeforeCommit" enum="Boolean">
<owner>danyao@chromium.org</owner> <owner>danyao@chromium.org</owner>
<summary> <summary>
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