OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.ntp; |
| 6 |
| 7 import org.chromium.base.metrics.RecordHistogram; |
| 8 import org.chromium.base.metrics.RecordUserAction; |
| 9 import org.chromium.chrome.browser.UrlUtilities; |
| 10 import org.chromium.ui.base.PageTransition; |
| 11 |
| 12 /** |
| 13 * Records UMA stats for which actions the user takes on the NTP in the |
| 14 * "NewTabPage.ActionAndroid" histogram. |
| 15 */ |
| 16 public class NewTabPageUma { |
| 17 // Possible actions taken by the user on the NTP. These values are also defi
ned in |
| 18 // histograms.xml. WARNING: these values must stay in sync with histograms.x
ml. |
| 19 |
| 20 // User performed a search using the omnibox |
| 21 private static final int ACTION_SEARCHED_USING_OMNIBOX = 0; |
| 22 // User navigated to Google search homepage using the omnibox |
| 23 private static final int ACTION_NAVIGATED_TO_GOOGLE_HOMEPAGE = 1; |
| 24 // User navigated to any other page using the omnibox |
| 25 private static final int ACTION_NAVIGATED_USING_OMNIBOX = 2; |
| 26 // User opened a most visited page |
| 27 public static final int ACTION_OPENED_MOST_VISITED_ENTRY = 3; |
| 28 // User opened a recently closed tab |
| 29 public static final int ACTION_OPENED_RECENTLY_CLOSED_ENTRY = 4; |
| 30 // User opened a bookmark |
| 31 public static final int ACTION_OPENED_BOOKMARK = 5; |
| 32 // User opened a foreign session (from recent tabs section) |
| 33 public static final int ACTION_OPENED_FOREIGN_SESSION = 6; |
| 34 // The number of possible actions |
| 35 private static final int NUM_ACTIONS = 7; |
| 36 |
| 37 /** |
| 38 * Records an action taken by the user on the NTP. |
| 39 * @param action One of the ACTION_* values defined in this class. |
| 40 */ |
| 41 public static void recordAction(int action) { |
| 42 assert action >= 0; |
| 43 assert action < NUM_ACTIONS; |
| 44 switch (action) { |
| 45 case ACTION_OPENED_MOST_VISITED_ENTRY: |
| 46 RecordUserAction.record("MobileNTPMostVisited"); |
| 47 break; |
| 48 case ACTION_OPENED_RECENTLY_CLOSED_ENTRY: |
| 49 RecordUserAction.record("MobileNTPRecentlyClosed"); |
| 50 break; |
| 51 case ACTION_OPENED_BOOKMARK: |
| 52 RecordUserAction.record("MobileNTPBookmark"); |
| 53 break; |
| 54 case ACTION_OPENED_FOREIGN_SESSION: |
| 55 RecordUserAction.record("MobileNTPForeignSession"); |
| 56 break; |
| 57 default: |
| 58 // No UMA action associated with this type. |
| 59 break; |
| 60 } |
| 61 RecordHistogram.recordEnumeratedHistogram("NewTabPage.ActionAndroid", ac
tion, NUM_ACTIONS); |
| 62 } |
| 63 |
| 64 /** |
| 65 * Record that the user has navigated away from the NTP using the omnibox. |
| 66 * @param destinationUrl The URL to which the user navigated. |
| 67 * @param transitionType The transition type of the navigation, from PageTra
nsition.java. |
| 68 */ |
| 69 public static void recordOmniboxNavigation(String destinationUrl, int transi
tionType) { |
| 70 if ((transitionType & PageTransition.CORE_MASK) == PageTransition.GENERA
TED) { |
| 71 recordAction(ACTION_SEARCHED_USING_OMNIBOX); |
| 72 } else if (UrlUtilities.nativeIsGoogleHomePageUrl(destinationUrl)) { |
| 73 recordAction(ACTION_NAVIGATED_TO_GOOGLE_HOMEPAGE); |
| 74 } else { |
| 75 recordAction(ACTION_NAVIGATED_USING_OMNIBOX); |
| 76 } |
| 77 } |
| 78 } |
OLD | NEW |