[go: up one dir, main page]

cros: Add WindowFocused user action to the applist.

PM and outside teams want to be able to understand launcher usage. One
key metric is the 'click through rate' (CTR) of the launcher. To
accurately calculate this, we need to know how many times the launcher
is shown to the user.

The most dependable way to measure this is to record when the applist
window gains focus.

(cherry picked from commit 61e72dff7876db8c338084f80792e0584006154f)

Bug: 962725
Change-Id: If06fb022c2bf43cd3af9901353bf3bdcc438d197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635361
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: Mark Pearson <mpearson@chromium.org>
Reviewed-by: Kevin Strohbehn <ginko@google.com>
Auto-Submit: Alex Newcomer <newcomer@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#667821}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659229
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#297}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/ash/app_list/presenter/app_list_presenter_impl.cc b/ash/app_list/presenter/app_list_presenter_impl.cc
index f124092d..c1a6071 100644
--- a/ash/app_list/presenter/app_list_presenter_impl.cc
+++ b/ash/app_list/presenter/app_list_presenter_impl.cc
@@ -413,17 +413,20 @@
                                            aura::Window* lost_focus) {
   if (view_ && is_visible_) {
     aura::Window* applist_window = view_->GetWidget()->GetNativeView();
-
+    const bool applist_gained_focus = applist_window->Contains(gained_focus);
     if (delegate_->IsTabletMode()) {
       if (applist_window->Contains(lost_focus)) {
         home_launcher_shown_ = false;
         HandleCloseOpenSearchBox();
-      } else if (applist_window->Contains(gained_focus)) {
+      } else if (applist_gained_focus) {
         home_launcher_shown_ = true;
         view_->ResetForShow();
       }
     }
 
+    if (applist_gained_focus)
+      base::RecordAction(base::UserMetricsAction("AppList_WindowFocused"));
+
     aura::Window* applist_container = applist_window->parent();
     if (applist_container->Contains(lost_focus) &&
         (!gained_focus || !applist_container->Contains(gained_focus)) &&
diff --git a/tools/metrics/actions/actions.xml b/tools/metrics/actions/actions.xml
index b2637a9..892cb10 100644
--- a/tools/metrics/actions/actions.xml
+++ b/tools/metrics/actions/actions.xml
@@ -2270,6 +2270,17 @@
   <description>Please enter the description of this user action.</description>
 </action>
 
+<action name="AppList_WindowFocused">
+  <owner>newcomer@chromium.org</owner>
+  <description>
+    Emitted when the AppList has gained focus. The AppList gains focus every
+    time it is shown to the user, so this is equivalent to being emitted when
+    the AppList is shown to the user. This can be used in combination with
+    launch/activation metrics to calculate the click through rate in the
+    AppList.
+  </description>
+</action>
+
 <action name="AppList_ZeroStateOpenInstalledApp">
   <owner>jennyz@chromium.org</owner>
   <owner>newcomer@chromium.org</owner>
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 12104265..9e2588a 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -4458,11 +4458,15 @@
   </summary>
 </histogram>
 
-<histogram name="Apps.AppListShowSource" enum="AppListShowSource">
+<histogram name="Apps.AppListShowSource" enum="AppListShowSource"
+    expires_after="2020-01-01">
   <owner>newcomer@chromium.org</owner>
   <summary>
     The number of times the different sources for showing the app list are used.
-    This is logged when the app list is shown.
+    This is logged when the app list is shown. Does not count the app list shown
+    when the last window is closed in tablet mode. This is not the total number
+    of times the app list is shown to the user; for that consult the user action
+    AppList_WindowFocused.
   </summary>
 </histogram>