Skip to content

Commit

Permalink
Refactor offer notification metrics
Browse files Browse the repository at this point in the history
Move all offer related metrics into offer_metrics.*

Update all refs accordingly

Bug: 1346665
Change-Id: I41b81cd1846da2a9169aa28654552518b694742f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3775093
Reviewed-by: Maxim Kolosovskiy <kolos@chromium.org>
Commit-Queue: Shikai Jin <shikaijin@google.com>
Reviewed-by: Jared Saul <jsaul@google.com>
Reviewed-by: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1030721}
  • Loading branch information
Shikai Jin authored and Chromium LUCI CQ committed Aug 2, 2022
1 parent eb470de commit 27b58f3
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/offers_metrics.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
Expand Down Expand Up @@ -125,36 +126,36 @@ void OfferNotificationBubbleControllerImpl::OnBubbleClosed(
UpdatePageActionIcon();

// Log bubble result according to the closed reason.
AutofillMetrics::OfferNotificationBubbleResultMetric metric;
autofill_metrics::OfferNotificationBubbleResultMetric metric;
switch (closed_reason) {
case PaymentsBubbleClosedReason::kAccepted:
metric = AutofillMetrics::OfferNotificationBubbleResultMetric::
metric = autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_ACKNOWLEDGED;
break;
case PaymentsBubbleClosedReason::kClosed:
metric = AutofillMetrics::OfferNotificationBubbleResultMetric::
metric = autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_CLOSED;
break;
case PaymentsBubbleClosedReason::kNotInteracted:
metric = AutofillMetrics::OfferNotificationBubbleResultMetric::
metric = autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_NOT_INTERACTED;
break;
case PaymentsBubbleClosedReason::kLostFocus:
metric = AutofillMetrics::OfferNotificationBubbleResultMetric::
metric = autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_LOST_FOCUS;
break;
default:
NOTREACHED();
return;
}
AutofillMetrics::LogOfferNotificationBubbleResultMetric(
autofill_metrics::LogOfferNotificationBubbleResultMetric(
offer_->GetOfferType(), metric, is_user_gesture_);
}

void OfferNotificationBubbleControllerImpl::OnPromoCodeButtonClicked() {
promo_code_button_clicked_ = true;

AutofillMetrics::LogOfferNotificationBubblePromoCodeButtonClicked(
autofill_metrics::LogOfferNotificationBubblePromoCodeButtonClicked(
offer_->GetOfferType());
}

Expand Down Expand Up @@ -190,7 +191,7 @@ void OfferNotificationBubbleControllerImpl::ShowOfferNotificationIfApplicable(
commerce::kCouponDisplayInterval.Get()) {
bubble_state_ = BubbleState::kShowingIcon;
UpdatePageActionIcon();
AutofillMetrics::LogOfferNotificationBubbleSuppressed(
autofill_metrics::LogOfferNotificationBubbleSuppressed(
AutofillOfferData::OfferType::FREE_LISTING_COUPON_OFFER);
return;
}
Expand Down Expand Up @@ -268,8 +269,8 @@ void OfferNotificationBubbleControllerImpl::DoShowBubble() {
if (observer_for_testing_)
observer_for_testing_->OnBubbleShown();

AutofillMetrics::LogOfferNotificationBubbleOfferMetric(offer_->GetOfferType(),
is_user_gesture_);
autofill_metrics::LogOfferNotificationBubbleOfferMetric(
offer_->GetOfferType(), is_user_gesture_);
}

bool OfferNotificationBubbleControllerImpl::IsWebContentsActive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/metrics/payments/offers_metrics.h"
#include "components/autofill/core/browser/payments/autofill_offer_manager.h"
#include "components/autofill/core/browser/payments/autofill_offer_notification_infobar_delegate_mobile.h"
#include "components/autofill/core/browser/personal_data_manager.h"
Expand Down Expand Up @@ -172,7 +173,7 @@ class OfferNotificationControllerAndroidBrowserTestForInfobar
}

void VerifyInfoBarResultMetric(
AutofillMetrics::OfferNotificationInfoBarResultMetric metric,
autofill_metrics::OfferNotificationInfoBarResultMetric metric,
int count) {
histogram_tester_.ExpectBucketCount(
"Autofill.OfferNotificationInfoBarResult.CardLinkedOffer", metric,
Expand All @@ -196,7 +197,7 @@ IN_PROC_BROWSER_TEST_F(OfferNotificationControllerAndroidBrowserTestForInfobar,

// Verify histogram counts.
VerifyInfoBarResultMetric(
AutofillMetrics::OfferNotificationInfoBarResultMetric::
autofill_metrics::OfferNotificationInfoBarResultMetric::
OFFER_NOTIFICATION_INFOBAR_ACKNOWLEDGED,
1);
}
Expand All @@ -217,7 +218,7 @@ IN_PROC_BROWSER_TEST_F(OfferNotificationControllerAndroidBrowserTestForInfobar,

// Verify histogram counts.
VerifyInfoBarResultMetric(
AutofillMetrics::OfferNotificationInfoBarResultMetric::
autofill_metrics::OfferNotificationInfoBarResultMetric::
OFFER_NOTIFICATION_INFOBAR_CLOSED,
1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/offers_metrics.h"
#include "components/autofill/core/browser/payments/offer_notification_handler.h"
#include "components/autofill/core/browser/ui/payments/payments_bubble_closed_reasons.h"
#include "components/autofill/core/common/autofill_payments_features.h"
Expand Down Expand Up @@ -357,7 +358,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".FirstShow",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_ACKNOWLEDGED,
1);

Expand All @@ -370,7 +371,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".Reshows",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_ACKNOWLEDGED,
1);
}
Expand All @@ -386,7 +387,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".FirstShow",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_CLOSED,
1);

Expand All @@ -399,7 +400,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".Reshows",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_CLOSED,
1);
}
Expand All @@ -418,7 +419,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".FirstShow",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_NOT_INTERACTED,
1);
}
Expand All @@ -434,7 +435,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".FirstShow",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_LOST_FOCUS,
1);

Expand All @@ -447,7 +448,7 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
histogram_tester.ExpectUniqueSample(
"Autofill.OfferNotificationBubbleResult." +
GetSubhistogramNameForOfferType() + ".Reshows",
AutofillMetrics::OfferNotificationBubbleResultMetric::
autofill_metrics::OfferNotificationBubbleResultMetric::
OFFER_NOTIFICATION_BUBBLE_LOST_FOCUS,
1);
}
Expand Down
117 changes: 0 additions & 117 deletions components/autofill/core/browser/metrics/autofill_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1196,118 +1196,6 @@ void AutofillMetrics::LogLocalCardMigrationPromptMetric(
NUM_LOCAL_CARD_MIGRATION_PROMPT_METRICS);
}

// static
void AutofillMetrics::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::FREE_LISTING_COUPON_OFFER:
histogram_name += "FreeListingCouponOffer";
break;
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
return;
}
base::UmaHistogramBoolean(histogram_name, is_reshow);
}

// static
void AutofillMetrics::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::FREE_LISTING_COUPON_OFFER:
histogram_name += "FreeListingCouponOffer.";
break;
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
return;
}
// Add subhistogram for |is_reshow| decision.
histogram_name += is_reshow ? "Reshows" : "FirstShow";
base::UmaHistogramEnumeration(histogram_name, metric);
}

// static
void AutofillMetrics::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::FREE_LISTING_COUPON_OFFER:
histogram_name += "FreeListingCouponOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
return;
}
base::UmaHistogramBoolean(histogram_name, true);
}

// static
void AutofillMetrics::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::FREE_LISTING_COUPON_OFFER:
histogram_name += "FreeListingCouponOffer";
break;
case AutofillOfferData::OfferType::GPAY_CARD_LINKED_OFFER:
case AutofillOfferData::OfferType::UNKNOWN:
NOTREACHED();
return;
}
base::UmaHistogramBoolean(histogram_name, true);
}

// static
void AutofillMetrics::LogOfferNotificationInfoBarDeepLinkClicked() {
base::RecordAction(base::UserMetricsAction(
"Autofill_OfferNotificationInfoBar_DeepLinkClicked"));
}

// static
void AutofillMetrics::LogOfferNotificationInfoBarResultMetric(
OfferNotificationInfoBarResultMetric metric) {
DCHECK_LE(metric, OfferNotificationInfoBarResultMetric::kMaxValue);
base::UmaHistogramEnumeration(
"Autofill.OfferNotificationInfoBarResult.CardLinkedOffer", metric);
}

void AutofillMetrics::LogOfferNotificationInfoBarShown() {
base::UmaHistogramBoolean(
"Autofill.OfferNotificationInfoBarOffer.CardLinkedOffer", true);
}

void AutofillMetrics::LogProgressDialogResultMetric(
bool is_canceled_by_user,
AutofillProgressDialogType autofill_progress_dialog_type) {
Expand Down Expand Up @@ -2238,11 +2126,6 @@ void AutofillMetrics::LogStoredCreditCardMetrics(
server_card_count_with_card_art_image);
}

// static
void AutofillMetrics::LogSyncedOfferDataBeingValid(bool valid) {
base::UmaHistogramBoolean("Autofill.Offer.SyncedOfferDataBeingValid", valid);
}

// static
void AutofillMetrics::LogNumberOfCreditCardsSuppressedForDisuse(
size_t num_cards) {
Expand Down
50 changes: 0 additions & 50 deletions components/autofill/core/browser/metrics/autofill_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_profile_import_process.h"
#include "components/autofill/core/browser/autofill_progress_dialog_type.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_types.h"
Expand All @@ -45,7 +44,6 @@ class Autofill_CreditCardFill;
namespace autofill {

class AutofillField;
class AutofillOfferData;
class CreditCard;
class FormEventLoggerBase;

Expand Down Expand Up @@ -295,36 +293,6 @@ class AutofillMetrics {
NUM_SAVE_CARD_PROMPT_RESULT_METRICS,
};

// Metrics to track event when the offer notification bubble is closed.
enum class OfferNotificationBubbleResultMetric {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.

// The user explicitly acknowledged the bubble by clicking the ok button.
OFFER_NOTIFICATION_BUBBLE_ACKNOWLEDGED = 0,
// The user explicitly closed the prompt with the close button or ESC.
OFFER_NOTIFICATION_BUBBLE_CLOSED = 1,
// The user did not interact with the prompt.
OFFER_NOTIFICATION_BUBBLE_NOT_INTERACTED = 2,
// The prompt lost focus and was deactivated.
OFFER_NOTIFICATION_BUBBLE_LOST_FOCUS = 3,
kMaxValue = OFFER_NOTIFICATION_BUBBLE_LOST_FOCUS,
};

// Metrics to track event when the offer notification infobar is closed.
enum class OfferNotificationInfoBarResultMetric {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.

// User acknowledged the infobar by clicking the ok button.
OFFER_NOTIFICATION_INFOBAR_ACKNOWLEDGED = 0,
// User explicitly closed the infobar with the close button.
OFFER_NOTIFICATION_INFOBAR_CLOSED = 1,
// InfoBar was shown but user did not interact with the it.
OFFER_NOTIFICATION_INFOBAR_IGNORED = 2,
kMaxValue = OFFER_NOTIFICATION_INFOBAR_IGNORED,
};

// Metrics to track events in CardUnmaskAuthenticationSelectionDialog.
enum class CardUnmaskAuthenticationSelectionDialogResultMetric {
// These values are persisted to logs. Entries should not be renumbered and
Expand Down Expand Up @@ -1460,21 +1428,6 @@ class AutofillMetrics {
static void LogLocalCardMigrationPromptMetric(
LocalCardMigrationOrigin local_card_migration_origin,
LocalCardMigrationPromptMetric metric);
static void LogOfferNotificationBubbleOfferMetric(
AutofillOfferData::OfferType offer_type,
bool is_reshow);
static void LogOfferNotificationBubbleResultMetric(
AutofillOfferData::OfferType offer_type,
OfferNotificationBubbleResultMetric metric,
bool is_reshow);
static void LogOfferNotificationBubblePromoCodeButtonClicked(
AutofillOfferData::OfferType offer_type);
static void LogOfferNotificationBubbleSuppressed(
AutofillOfferData::OfferType offer_type);
static void LogOfferNotificationInfoBarDeepLinkClicked();
static void LogOfferNotificationInfoBarResultMetric(
OfferNotificationInfoBarResultMetric metric);
static void LogOfferNotificationInfoBarShown();
static void LogProgressDialogResultMetric(
bool is_canceled_by_user,
AutofillProgressDialogType autofill_progress_dialog_type);
Expand Down Expand Up @@ -1735,9 +1688,6 @@ class AutofillMetrics {
size_t server_card_count_with_card_art_image,
base::TimeDelta disused_data_threshold);

// Logs whether the synced autofill offer data is valid.
static void LogSyncedOfferDataBeingValid(bool invalid);

// Log the number of autofill credit card suggestions suppressed because they
// have not been used for a long time and are expired. Note that these cards
// are only suppressed when the user has not typed any data into the field
Expand Down

0 comments on commit 27b58f3

Please sign in to comment.