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
|
// 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.
#include "components/autofill/core/browser/metrics/payments/offers_metrics.h"
#include <unordered_map>
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "components/autofill/core/browser/data_model/payments/autofill_offer_data.h"
namespace autofill::autofill_metrics {
void LogOfferNotificationBubbleOfferMetric(
AutofillOfferData::OfferType offer_type,
bool is_reshow) {
std::string histogram_name = "Autofill.OfferNotificationBubbleOffer.";
// Switch to different sub-histogram depending on offer type being displayed.
switch (offer_type) {
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
histogram_name += "CardLinkedOffer";
break;
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
histogram_name += "GPayPromoCodeOffer";
break;
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
base::UmaHistogramBoolean(histogram_name, is_reshow);
}
void LogOfferNotificationBubblePromoCodeButtonClicked(
AutofillOfferData::OfferType offer_type) {
std::string histogram_name =
"Autofill.OfferNotificationBubblePromoCodeButtonClicked.";
// Switch to different sub-histogram depending on offer type being displayed.
// Card-linked offers do not have a promo code button.
switch (offer_type) {
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
histogram_name += "GPayPromoCodeOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
base::UmaHistogramBoolean(histogram_name, true);
}
void LogOfferNotificationBubbleResultMetric(
AutofillOfferData::OfferType offer_type,
OfferNotificationBubbleResultMetric metric,
bool is_reshow) {
DCHECK_LE(metric, OfferNotificationBubbleResultMetric::kMaxValue);
std::string histogram_name = "Autofill.OfferNotificationBubbleResult.";
// Switch to different sub-histogram depending on offer type being displayed.
switch (offer_type) {
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
histogram_name += "CardLinkedOffer.";
break;
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
histogram_name += "GPayPromoCodeOffer.";
break;
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
// Add subhistogram for |is_reshow| decision.
histogram_name += is_reshow ? "Reshows" : "FirstShow";
base::UmaHistogramEnumeration(histogram_name, metric);
}
void LogOfferNotificationBubbleSuppressed(
AutofillOfferData::OfferType offer_type) {
std::string histogram_name = "Autofill.OfferNotificationBubbleSuppressed.";
// Switch to different sub-histogram depending on offer type being suppressed.
// Card-linked offers will not be suppressed.
switch (offer_type) {
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
histogram_name += "GPayPromoCodeOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
base::UmaHistogramBoolean(histogram_name, true);
}
void LogStoredOfferMetrics(
const std::vector<std::unique_ptr<AutofillOfferData>>& offers) {
std::unordered_map<AutofillOfferData::OfferType, int> offer_count;
for (const std::unique_ptr<AutofillOfferData>& offer : offers) {
offer_count[offer->GetOfferType()]++;
std::string related_merchant_count_histogram_name =
"Autofill.Offer.StoredOfferRelatedMerchantCount";
// Switch to different sub-histogram depending on offer type being
// displayed.
switch (offer->GetOfferType()) {
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
related_merchant_count_histogram_name += ".GPayPromoCodeOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
related_merchant_count_histogram_name += ".CardLinkedOffer";
break;
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
base::UmaHistogramCounts1000(related_merchant_count_histogram_name,
offer->GetMerchantOrigins().size());
if (offer->GetOfferType() ==
AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER) {
base::UmaHistogramCounts1000("Autofill.Offer.StoredOfferRelatedCardCount",
offer->GetEligibleInstrumentIds().size());
}
}
base::UmaHistogramCounts1000(
"Autofill.Offer.StoredOfferCount2.GPayPromoCodeOffer",
offer_count[AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER]);
base::UmaHistogramCounts1000(
"Autofill.Offer.StoredOfferCount2.CardLinkedOffer",
offer_count[AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER]);
}
void LogOffersSuggestionsPopupShown(bool first_time_being_logged) {
if (first_time_being_logged) {
// We log that the offers suggestions popup was shown once for this field
// while autofilling if it is the first time being logged.
base::UmaHistogramEnumeration(
"Autofill.Offer.SuggestionsPopupShown2",
OffersSuggestionsPopupEvent::kOffersSuggestionsPopupShownOnce);
}
// We log every time the offers suggestions popup is shown, regardless if the
// user is repeatedly clicking the same field.
base::UmaHistogramEnumeration(
"Autofill.Offer.SuggestionsPopupShown2",
OffersSuggestionsPopupEvent::kOffersSuggestionsPopupShown);
}
void LogIndividualOfferSuggestionEvent(
OffersSuggestionsEvent event,
AutofillOfferData::OfferType offer_type) {
std::string histogram_name = "Autofill.Offer.Suggestion2";
// Switch to different sub-histogram depending on offer type being displayed.
switch (offer_type) {
case AutofillOfferData::OfferType::GPAY_PROMO_CODE_OFFER:
histogram_name += ".GPayPromoCodeOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
}
base::UmaHistogramEnumeration(histogram_name, event);
}
// static
void LogSyncedOfferDataBeingValid(bool valid) {
base::UmaHistogramBoolean("Autofill.Offer.SyncedOfferDataBeingValid", valid);
}
} // namespace autofill::autofill_metrics
|