summaryrefslogtreecommitdiff
path: root/chromium/components/autofill_assistant/browser/metrics.cc
blob: 09265d8673cb08aa987b1f78202aaabff27e8e02 (plain)
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill_assistant/browser/metrics.h"

#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "components/ukm/content/source_url_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"

namespace autofill_assistant {

namespace {
const char kDropOutEnumName[] = "Android.AutofillAssistant.DropOutReason";
const char kPaymentRequestPrefilledName[] =
    "Android.AutofillAssistant.PaymentRequest.Prefilled";
const char kPaymentRequestAutofillInfoChangedName[] =
    "Android.AutofillAssistant.PaymentRequest.AutofillChanged";
const char kPaymentRequestFirstNameOnly[] =
    "Android.AutofillAssistant.PaymentRequest.FirstNameOnly";
const char kPaymentRequestMandatoryPostalCode[] =
    "Android.AutofillAssistant.PaymentRequest.MandatoryPostalCode";
static bool DROPOUT_RECORDED = false;
}  // namespace

// static
void Metrics::RecordDropOut(DropOutReason reason) {
  DCHECK_LE(reason, DropOutReason::kMaxValue);
  if (DROPOUT_RECORDED) {
    return;
  }
  DVLOG_IF(3, reason != DropOutReason::AA_START)
      << "Drop out with reason: " << reason;
  base::UmaHistogramEnumeration(kDropOutEnumName, reason);
  DROPOUT_RECORDED = true;
}

// static
void Metrics::RecordPaymentRequestPrefilledSuccess(bool initially_complete,
                                                   bool success) {
  if (initially_complete && success) {
    base::UmaHistogramEnumeration(kPaymentRequestPrefilledName,
                                  PaymentRequestPrefilled::PREFILLED_SUCCESS);
  } else if (initially_complete && !success) {
    base::UmaHistogramEnumeration(kPaymentRequestPrefilledName,
                                  PaymentRequestPrefilled::PREFILLED_FAILURE);
  } else if (!initially_complete && success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestPrefilledName,
        PaymentRequestPrefilled::NOTPREFILLED_SUCCESS);
  } else if (!initially_complete && !success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestPrefilledName,
        PaymentRequestPrefilled::NOTPREFILLED_FAILURE);
  }
}

// static
void Metrics::RecordPaymentRequestAutofillChanged(bool changed, bool success) {
  if (changed && success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestAutofillInfoChangedName,
        PaymentRequestAutofillInfoChanged::CHANGED_SUCCESS);
  } else if (changed && !success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestAutofillInfoChangedName,
        PaymentRequestAutofillInfoChanged::CHANGED_FAILURE);
  } else if (!changed && success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestAutofillInfoChangedName,
        PaymentRequestAutofillInfoChanged::NOTCHANGED_SUCCESS);
  } else if (!changed && !success) {
    base::UmaHistogramEnumeration(
        kPaymentRequestAutofillInfoChangedName,
        PaymentRequestAutofillInfoChanged::NOTCHANGED_FAILURE);
  }
}

// static
void Metrics::RecordPaymentRequestFirstNameOnly(bool first_name_only) {
  base::UmaHistogramBoolean(kPaymentRequestFirstNameOnly, first_name_only);
}

// static
void Metrics::RecordPaymentRequestMandatoryPostalCode(bool required,
                                                      bool initially_right,
                                                      bool success) {
  PaymentRequestMandatoryPostalCode mandatory_postal_code;
  if (!required) {
    mandatory_postal_code = PaymentRequestMandatoryPostalCode::NOT_REQUIRED;
  } else if (initially_right && success) {
    mandatory_postal_code =
        PaymentRequestMandatoryPostalCode::REQUIRED_INITIALLY_RIGHT_SUCCESS;
  } else if (initially_right && !success) {
    mandatory_postal_code =
        PaymentRequestMandatoryPostalCode::REQUIRED_INITIALLY_RIGHT_FAILURE;
  } else if (!initially_right && success) {
    mandatory_postal_code =
        PaymentRequestMandatoryPostalCode::REQUIRED_INITIALLY_WRONG_SUCCESS;
  } else if (!initially_right && !success) {
    mandatory_postal_code =
        PaymentRequestMandatoryPostalCode::REQUIRED_INITIALLY_WRONG_FAILURE;
  } else {
    DCHECK(false) << "Not reached";
    return;
  }

  base::UmaHistogramEnumeration(kPaymentRequestMandatoryPostalCode,
                                mandatory_postal_code);
}

// static
void Metrics::RecordLiteScriptFinished(ukm::UkmRecorder* ukm_recorder,
                                       content::WebContents* web_contents,
                                       LiteScriptFinishedState event) {
  ukm::builders::AutofillAssistant_LiteScriptFinished(
      ukm::GetSourceIdForWebContentsDocument(web_contents))
      .SetLiteScriptFinished(static_cast<int64_t>(event))
      .Record(ukm_recorder);
}

// static
void Metrics::RecordLiteScriptShownToUser(ukm::UkmRecorder* ukm_recorder,
                                          content::WebContents* web_contents,
                                          LiteScriptShownToUser event) {
  ukm::builders::AutofillAssistant_LiteScriptShownToUser(
      ukm::GetSourceIdForWebContentsDocument(web_contents))
      .SetLiteScriptShownToUser(static_cast<int64_t>(event))
      .Record(ukm_recorder);
}

// static
void Metrics::RecordLiteScriptOnboarding(ukm::UkmRecorder* ukm_recorder,
                                         content::WebContents* web_contents,
                                         LiteScriptOnboarding event) {
  ukm::builders::AutofillAssistant_LiteScriptOnboarding(
      ukm::GetSourceIdForWebContentsDocument(web_contents))
      .SetLiteScriptOnboarding(static_cast<int64_t>(event))
      .Record(ukm_recorder);
}

}  // namespace autofill_assistant