1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273

ash / webui / demo_mode_app_ui / resources / demo_mode_metrics_service.js [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * The page/pillar name for the pages in the Highlights app.
 * @enum {string}
 */
export const Page = {
  HOME: 'Home',
  EASY: 'Easy',
  FAST: 'Fast',
  POWERFUL: 'Powerful',
  SECURE: 'Secure',
  DISPLAY: 'Display',
  KEYBOARD: 'Keyboard',
  GRAPHICS: 'Graphics',
  GAME: 'Game',
  PERIPHERALS: 'Peripherals',
  PERFORMANCE: 'Performance',
  APPS: 'Apps',
  CHROMEOS: 'ChromeOS',

  // New in 2024 Cycle 1 refresh
  // CBX:
  GOOGLE_AI: 'GoogleAI',
  EASY_TO_USE: 'EasyToUse',
  // CB (Shared with CBX: Performance, Apps):
  GOOGLE_BUILT_IN: 'GoogleBuiltIn',
};

/**
 * The name for the details pages in the Highlights app.
 * @enum {string}
 */
export const DetailsPage = {
  // 2023 CBX first released:
  ADOBE: 'Adobe',
  BATTERY: 'Battery',
  COMPARISON: 'Comparison',
  DISPLAY_ENTERTAINMENT: 'DisplayEntertainment',
  DISPLAY_PERFORMANCE: 'DisplayPerformance',
  ENTERTAINMENT_APPS: 'EntertainmentApps',
  GOOGLE_APPS: 'GoogleApps',
  LUMAFUSION: 'LumaFusion',
  MESSAGING: 'Messaging',
  MOBILE_GAMING: 'MobileGaming',
  MS_365_APPS: 'MS365Apps',
  MS_OFFICE: 'MSOffice',
  NEARBY_SHARE: 'NearbyShare',
  OFFLINE_MODE: 'OfflineMode',
  PC_CONSOLE_GAMING: 'PCConsoleGaming',
  PHOTOS: 'Photos',
  PROCESSOR: 'Processor',
  STORAGE: 'Storage',
  SWITCHING: 'Switching',
  VIDEO_CALL: 'VideoCall',

  // New in 2024 Cycle 1 refresh
  // CBX:
  BUILT_IN_SECURITY:'BuiltInSecurity',
  WEBCAM: 'Webcam',
  GAME_DASH_BOARD: 'GameDashboard',
  GEMINI_FOR_ALL:'GeminiForAll',
  HELP_ME_WRITE: 'HelpMeWrite',
  GEMINI_FOR_WORK_SPACE: 'GeminiForWorkSpace',
  AI_BACKGROUND: 'AIBackground',
  AI_PREMIUM_PLAN: 'AIPremiumPlan',

  // CB, note that detail page for generic was not recorded before 2024 C1:
  FAST_BOOT: 'FastBoot',
  AUTO_UPDATE: 'AutoUpdate',
  EASY_SETUP:'EasySetup',
  LAUNCHER_SEARCH:'LauncherSearch',
  GOOGLE_TOOLS_BUILT_IN:'GoogleToolsBuiltIn',
  TITAN_C2:'TitanC2',
  CREATIVITY:'Creativity',
  ENTERTAINMENT:'Entertainment',
  PRODUCTIVITY:'Productivity',
  PLAY_STORE:'PlayStore',

  // Enum shared between CB & CBX are: BATTERY, GOOGLE_APPS, NEARBY_SHARE,
  // MESSAGING, BUILT_IN_SECURITY,MS_365_APPS, SWITCHING, COMPARISON

  // New in 2024 Cycle 2 refresh
  // CBX:
  HELP_ME_READ: 'HelpMeRead',
  LIVE_TRANSLATE: 'LiveTranslate',
};

/**
 * The buttons in each pillar page of the Highlights app.
 * @enum {string}
 */
export const PillarButton = {
  NEXT: 'Next',
  PREVIOUS: 'Previous',
};

/**
 * Errors in the Highlights app.
 *
 * This is used by histogram: DemoMode.Highlights.Error
 *
 * These values are persisted to logs, so entries should not be renumbered and
 * numeric values should never be reused.
 *
 * @enum {number}
 */
const DemoModeHighlightsError = {
  ATTRACTION_LOOP_TIMESTAMP_INVALID: 0,
  PAGE_VIEW_DURATION_INVALID: 1,
  DETAILS_PAGE_VIEW_DURATION_INVALID: 2,
};

/**
 * A map between the Page in this js file and DemoModeHighlightsAction enum in
 * the UMA enums.xml.
 */
const FirstInteractionActionMap = new Map([
  [Page.HOME, 0],
  [Page.EASY, 1],
  [Page.FAST, 2],
  [Page.POWERFUL, 3],
  [Page.SECURE, 4],
  [Page.DISPLAY, 5],
  [Page.KEYBOARD, 6],
  [Page.GRAPHICS, 7],
  [Page.GAME, 8],
  [Page.PERIPHERALS, 9],
  [Page.PERFORMANCE, 10],
  [Page.APPS, 11],
  [Page.CHROMEOS, 12],
  [Page.GOOGLE_AI, 13],
  [Page.EASY_TO_USE, 14],
  [Page.GOOGLE_BUILT_IN, 15],

  ['MAX_VALUE', 15],
]);

/**
 * Provides interfaces for emitting metrics from demo mode apps to UMA.
 *
 * Note: DemoMode.Highlights.* metrics and actions are recorded via
 * runtime-downloaded content that is not checked into Chromium. Please do not
 * delete this code, even if it looks like there's no production references in
 * Chromium, without first consulting the Demo Mode team.
 */
class DemoMetricsService {
  constructor() {
    this.firstInteractionRecorded = false;
  }

  // Record the action that the user breaks the current Attract Loop.
  recordAttractLoopBreak() {
    chrome.metricsPrivateIndividualApis.recordUserAction(
        'DemoMode_AttractLoop_Break');
  }

  /**
   * Record the timestamp (i.e. milliseconds from the beginning of the Attract
   * Loop video) at which the user broke the Attract Loop.
   * @param timestampInMilliseconds
   */
  recordAttractLoopBreakTimestamp(timestampInMilliseconds) {
    if (isNaN(timestampInMilliseconds)) {
      this.recordError_(
          DemoModeHighlightsError.ATTRACTION_LOOP_TIMESTAMP_INVALID);
      return;
    }
    chrome.metricsPrivateIndividualApis.recordMediumTime(
        'DemoMode.AttractLoop.Timestamp',
        timestampInMilliseconds,
    );
  }

  /**
   * Record the first action of current user.
   * @param {Page} action
   */
  recordFirstInteraction(action) {
    if (!this.firstInteractionRecorded) {
      chrome.metricsPrivateIndividualApis.recordEnumerationValue(
          'DemoMode.Highlights.FirstInteraction',
          FirstInteractionActionMap.get(action),
          FirstInteractionActionMap.get('MAX_VALUE'));
      this.firstInteractionRecorded = true;
    }
  }

  /**
   * Record the button clicks in home page of the current user.
   * @param {Page} page
   */
  recordHomePageButtonClick(page) {
    chrome.metricsPrivateIndividualApis.recordUserAction(
        'DemoMode_Highlights_HomePage_Click_' + page + 'Button');
    this.recordFirstInteraction(page);
  }

  /**
   * Record the button clicks in home page of the current user.
   * @param {Page} page
   */
  recordNavbarButtonClick(page) {
    chrome.metricsPrivateIndividualApis.recordUserAction(
        'DemoMode_Highlights_Navbar_Click_' + page + 'Button');
    this.recordFirstInteraction(page);
  }

  /**
   * Record the button click in pillar pages of the current user.
   * @param {PillarButton} pillarButton
   */
  recordPillarPageButtonClick(pillarButton) {
    chrome.metricsPrivateIndividualApis.recordUserAction(
        'DemoMode_Highlights_PillarPage_Click_' + pillarButton + 'Button');
  }

  /**
   * Record the duration of the user staying on the page.
   * @param {Page} page
   * @param {number} durationInMilliseconds
   */
  recordPageViewDuration(page, durationInMilliseconds) {
    if (!durationInMilliseconds) {
      this.recordError_(DemoModeHighlightsError.PAGE_VIEW_DURATION_INVALID);
      return;
    }
    chrome.metricsPrivateIndividualApis.recordMediumTime(
        'DemoMode.Highlights.PageStayDuration.' + page + 'Page',
        durationInMilliseconds);
  }

  /**
   * Record the details page clicked by the current user
   * @param {DetailsPage} detailsPage
   */
  recordDetailsPageClicked(detailsPage) {
    chrome.metricsPrivateIndividualApis.recordUserAction(
        'DemoMode_Highlights_DetailsPage_Clicked_' + detailsPage + 'Button');
  }

  /**
   * Record the duration of the user staying on a details page
   * @param {DetailsPage} detailsPage
   */
  recordDetailsPageViewDuration(detailsPage, durationInMilliseconds) {
    if (!durationInMilliseconds) {
      this.recordError_(
          DemoModeHighlightsError.DETAILS_PAGE_VIEW_DURATION_INVALID);
      return;
    }
    chrome.metricsPrivateIndividualApis.recordMediumTime(
        'DemoMode.Highlights.DetailsPageStayDuration.' + detailsPage + 'Page',
        durationInMilliseconds);
  }

  /**
   * Record error in highlight app.
   * @param {DemoModeHighlightsError} error
   * @private
   */
  recordError_(error) {
    const maxValue = Object.keys(DemoModeHighlightsError).length;
    chrome.metricsPrivateIndividualApis.recordEnumerationValue(
        'DemoMode.Highlights.Error', error, maxValue);
  }
}



export const metricsService = new DemoMetricsService();