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
|
// 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"
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";
}
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 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;
}
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;
}
NOTREACHED();
}
void LogBnplSelectionDialogShown() {
base::UmaHistogramBoolean("Autofill.Bnpl.SelectionDialogShown",
/*sample=*/true);
}
} // namespace autofill::autofill_metrics
|