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

ash / game_dashboard / game_dashboard_metrics.cc [blame]

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

#include "ash/game_dashboard/game_dashboard_metrics.h"

#include <cstdint>

#include "ash/game_dashboard/game_dashboard_controller.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"

namespace ash {

namespace {

constexpr char kGameDashboardHistogramNameRoot[] = "Ash.GameDashboard";
constexpr char kGameDashboardHistogramUkmNameRoot[] = "GameDashboard";

}  // namespace

ASH_EXPORT std::string BuildGameDashboardHistogramName(
    const std::string& name) {
  return base::JoinString(
      std::vector<std::string>{kGameDashboardHistogramNameRoot, name},
      kGameDashboardHistogramSeparator);
}

ASH_EXPORT std::string BuildGameDashboardUkmEventName(const std::string& name) {
  return base::JoinString(
      std::vector<std::string>{kGameDashboardHistogramUkmNameRoot, name},
      kGameDashboardHistogramSeparator);
}

void RecordGameDashboardToggleMainMenu(
    const std::string& app_id,
    GameDashboardMainMenuToggleMethod toggled_method,
    bool toggled_on) {
  base::UmaHistogramEnumeration(
      BuildGameDashboardHistogramName(kGameDashboardToggleMainMenuHistogram)
          .append(kGameDashboardHistogramSeparator)
          .append(toggled_on ? kGameDashboardHistogramOn
                             : kGameDashboardHistogramOff),
      toggled_method);
  ukm::builders::GameDashboard_ToggleMainMenu(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetToggleOn(toggled_on)
      .SetToggleMethod(static_cast<int64_t>(toggled_method))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardToolbarToggleState(const std::string& app_id,
                                           bool toggled_on) {
  base::UmaHistogramBoolean(BuildGameDashboardHistogramName(
                                kGameDashboardToolbarToggleStateHistogram),
                            toggled_on);
  ukm::builders::GameDashboard_ToolbarToggleState(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetToggleOn(toggled_on)
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardRecordingStartSource(const std::string& app_id,
                                             GameDashboardMenu menu) {
  base::UmaHistogramEnumeration(
      BuildGameDashboardHistogramName(
          kGameDashboardRecordingStartSourceHistogram),
      menu);
  ukm::builders::GameDashboard_RecordingStartSource(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetSource(static_cast<int64_t>(menu))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardScreenshotTakeSource(const std::string& app_id,
                                             GameDashboardMenu menu) {
  base::UmaHistogramEnumeration(
      BuildGameDashboardHistogramName(
          kGameDashboardScreenshotTakeSourceHistogram),
      menu);
  ukm::builders::GameDashboard_ScreenshotTakeSource(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetSource(static_cast<int64_t>(menu))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardEditControlsWithEmptyState(const std::string& app_id,
                                                   bool is_setup) {
  base::UmaHistogramBoolean(
      BuildGameDashboardHistogramName(
          kGameDashboardEditControlsWithEmptyStateHistogram),
      is_setup);
  ukm::builders::GameDashboard_EditControlsWithEmptyState(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetEmpty(is_setup)
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardToolbarClickToExpandState(const std::string& app_id,
                                                  bool is_expanded) {
  base::UmaHistogramBoolean(
      BuildGameDashboardHistogramName(
          kGameDashboardToolbarClickToExpandStateHistogram),
      is_expanded);
  ukm::builders::GameDashboard_ToolbarClickToExpandState(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetExpanded(is_expanded)
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardToolbarNewLocation(
    const std::string& app_id,
    GameDashboardToolbarSnapLocation location) {
  base::UmaHistogramEnumeration(BuildGameDashboardHistogramName(
                                    kGameDashboardToolbarNewLocationHistogram),
                                location);
  ukm::builders::GameDashboard_ToolbarNewLocation(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetLocation(static_cast<int64_t>(location))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardFunctionTriggered(const std::string& app_id,
                                          GameDashboardFunction function) {
  base::UmaHistogramEnumeration(
      BuildGameDashboardHistogramName(kGameDashboardFunctionTriggeredHistogram),
      function);
  ukm::builders::GameDashboard_FunctionTriggered(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetFunction(static_cast<int64_t>(function))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardWelcomeDialogNotificationToggleState(
    const std::string& app_id,
    bool toggled_on) {
  base::UmaHistogramBoolean(
      BuildGameDashboardHistogramName(
          kGameDashboardWelcomeDialogNotificationToggleStateHistogram),
      toggled_on);
  ukm::builders::GameDashboard_WelcomeDialogNotificationToggleState(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetToggleOn(toggled_on)
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardControlsHintToggleSource(const std::string& app_id,
                                                 GameDashboardMenu menu,
                                                 bool toggled_on) {
  base::UmaHistogramEnumeration(
      BuildGameDashboardHistogramName(
          kGameDashboardControlsHintToggleSourceHistogram)
          .append(kGameDashboardHistogramSeparator)
          .append(toggled_on ? kGameDashboardHistogramOn
                             : kGameDashboardHistogramOff),
      menu);
  ukm::builders::GameDashboard_ControlsHintToggleSource(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetToggleOn(toggled_on)
      .SetSource(static_cast<int64_t>(menu))
      .Record(ukm::UkmRecorder::Get());
}

void RecordGameDashboardControlsFeatureToggleState(const std::string& app_id,
                                                   bool toggled_on) {
  base::UmaHistogramBoolean(
      BuildGameDashboardHistogramName(
          kGameDashboardControlsFeatureToggleStateHistogram),
      toggled_on);
  ukm::builders::GameDashboard_ControlsFeatureToggleState(
      GameDashboardController::Get()->GetUkmSourceId(app_id))
      .SetToggleOn(toggled_on)
      .Record(ukm::UkmRecorder::Get());
}

}  // namespace ash