File: bnpl_metrics.cc

package info (click to toggle)
chromium 140.0.7339.80-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,193,064 kB
  • sloc: cpp: 35,092,386; ansic: 7,161,671; javascript: 4,199,703; python: 1,441,797; asm: 949,904; xml: 747,409; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (165 lines) | stat: -rw-r--r-- 5,499 bytes parent folder | download | duplicates (4)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/metrics/payments/bnpl_metrics.h"

#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "components/autofill/core/browser/data_model/payments/bnpl_issuer.h"
#include "components/autofill/core/browser/payments/constants.h"
#include "services/metrics/public/cpp/ukm_builders.h"

namespace autofill::autofill_metrics {

using IssuerId = autofill::BnplIssuer::IssuerId;

std::string GetHistogramSuffixFromIssuerId(IssuerId issuer_id) {
  switch (issuer_id) {
    case IssuerId::kBnplAffirm:
      return "Affirm";
    case IssuerId::kBnplZip:
      return "Zip";
    case IssuerId::kBnplAfterpay:
      return "Afterpay";
    case IssuerId::kBnplKlarna:
      return "Klarna";
  }
  NOTREACHED();
}

std::string ConvertBnplFlowResultToString(BnplFlowResult result) {
  switch (result) {
    case BnplFlowResult::kSuccess:
      return "Success";
    case BnplFlowResult::kFailure:
      return "Failure";
    case BnplFlowResult::kUserClosed:
      return "UserClosed";
  }
  NOTREACHED();
}

void LogBnplPrefToggled(bool enabled) {
  base::UmaHistogramBoolean("Autofill.SettingsPage.BnplToggled", enabled);
}

void LogBnplIssuersSyncedCountAtStartup(int count) {
  base::UmaHistogramCounts100("Autofill.Bnpl.IssuersSyncedCount.Startup",
                              count);
}

void LogBnplTosDialogShown(IssuerId issuer_id) {
  std::string histogram_name =
      base::StrCat({"Autofill.Bnpl.TosDialogShown.",
                    GetHistogramSuffixFromIssuerId(issuer_id)});
  base::UmaHistogramBoolean(histogram_name, /*sample=*/true);
}

void LogBnplTosDialogResult(BnplTosDialogResult result, IssuerId issuer_id) {
  std::string histogram_name =
      base::StrCat({"Autofill.Bnpl.TosDialogResult.",
                    GetHistogramSuffixFromIssuerId(issuer_id)});
  base::UmaHistogramEnumeration(histogram_name, result);
}

void LogSelectBnplIssuerDialogResult(SelectBnplIssuerDialogResult result) {
  base::UmaHistogramEnumeration("Autofill.Bnpl.SelectionDialogResult", result);
}

void LogBnplIssuerSelection(IssuerId issuer_id) {
  base::UmaHistogramEnumeration("Autofill.Bnpl.SelectionDialogIssuerSelected",
                                issuer_id);
}

void LogBnplSuggestionNotShownReason(BnplSuggestionNotShownReason reason) {
  base::UmaHistogramEnumeration("Autofill.Bnpl.SuggestionNotShownReason",
                                reason);
}

void LogBnplPopupWindowShown(IssuerId issuer_id) {
  std::string histogram_name =
      base::StrCat({"Autofill.Bnpl.PopupWindowShown.",
                    GetHistogramSuffixFromIssuerId(issuer_id)});
  base::UmaHistogramBoolean(histogram_name, /*sample=*/true);
}

void LogBnplPopupWindowResult(IssuerId issuer_id, BnplFlowResult result) {
  std::string histogram_name =
      base::StrCat({"Autofill.Bnpl.PopupWindowResult.",
                    GetHistogramSuffixFromIssuerId(issuer_id)});
  base::UmaHistogramEnumeration(histogram_name, result);
}

void LogBnplPopupWindowLatency(base::TimeDelta duration,
                               IssuerId issuer_id,
                               BnplFlowResult result) {
  std::string histogram_name =
      base::StrCat({"Autofill.Bnpl.PopupWindowLatency.",
                    GetHistogramSuffixFromIssuerId(issuer_id), ".",
                    ConvertBnplFlowResultToString(result)});

  base::UmaHistogramLongTimes(histogram_name, duration);
}

void LogBnplFormEvent(BnplFormEvent event) {
  base::UmaHistogramEnumeration("Autofill.FormEvents.CreditCard.Bnpl", event);
}

void LogBnplSuggestionShown(ukm::SourceId ukm_source_id) {
  LogBnplFormEvent(BnplFormEvent::kBnplSuggestionShown);
  ukm::builders::Autofill_BnplSuggestionShown(ukm_source_id)
      .SetShown(true)
      .Record(ukm::UkmRecorder::Get());
}

void LogBnplSuggestionAccepted(ukm::SourceId ukm_source_id) {
  LogBnplFormEvent(BnplFormEvent::kBnplSuggestionAccepted);
  ukm::builders::Autofill_BnplSuggestionAccepted(ukm_source_id)
      .SetAccepted(true)
      .Record(ukm::UkmRecorder::Get());
}

void LogFormFilledWithBnplVcn(IssuerId issuer_id) {
  switch (issuer_id) {
    case IssuerId::kBnplAffirm:
      LogBnplFormEvent(BnplFormEvent::kFormFilledWithAffirm);
      return;
    case IssuerId::kBnplZip:
      LogBnplFormEvent(BnplFormEvent::kFormFilledWithZip);
      return;
    case IssuerId::kBnplAfterpay:
      LogBnplFormEvent(BnplFormEvent::kFormFilledWithAfterpay);
      return;
    case IssuerId::kBnplKlarna:
      LogBnplFormEvent(BnplFormEvent::kFormFilledWithKlarna);
      return;
  }
  NOTREACHED();
}

void LogFormSubmittedWithBnplVcn(IssuerId issuer_id) {
  switch (issuer_id) {
    case IssuerId::kBnplAffirm:
      LogBnplFormEvent(BnplFormEvent::kFormSubmittedWithAffirm);
      return;
    case IssuerId::kBnplZip:
      LogBnplFormEvent(BnplFormEvent::kFormSubmittedWithZip);
      return;
    case IssuerId::kBnplAfterpay:
      LogBnplFormEvent(BnplFormEvent::kFormSubmittedWithAfterpay);
      return;
    case IssuerId::kBnplKlarna:
      LogBnplFormEvent(BnplFormEvent::kFormSubmittedWithKlarna);
      return;
  }
  NOTREACHED();
}

void LogBnplSelectionDialogShown() {
  base::UmaHistogramBoolean("Autofill.Bnpl.SelectionDialogShown",
                            /*sample=*/true);
}

}  // namespace autofill::autofill_metrics