Skip to content

Commit

Permalink
[Metric] Add impression count for the offer notification icon
Browse files Browse the repository at this point in the history
Bug: 1345485
Change-Id: I2143705dacaa2652da00d533ca000dbc80f9d0cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3778341
Reviewed-by: Jared Saul <jsaul@google.com>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Siyu An <siyua@chromium.org>
Commit-Queue: Mei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1032181}
  • Loading branch information
Mei Liang authored and Chromium LUCI CQ committed Aug 6, 2022
1 parent ba8b65e commit d9624d2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
Expand Up @@ -6,6 +6,7 @@

#include <string>

#include "base/metrics/histogram_functions.h"
#include "chrome/browser/commerce/coupons/coupon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/autofill/autofill_bubble_base.h"
Expand Down Expand Up @@ -179,6 +180,9 @@ void OfferNotificationBubbleControllerImpl::ShowOfferNotificationIfApplicable(
// going to show another bubble anyway.
HideBubbleAndClearTimestamp(/*should_show_icon=*/true);

DCHECK(IsIconVisible());
autofill_metrics::LogPageLoadsWithOfferIconShown(offer->GetOfferType());

if (card)
card_ = *card;

Expand All @@ -189,8 +193,6 @@ void OfferNotificationBubbleControllerImpl::ShowOfferNotificationIfApplicable(
if (!last_display_time.is_null() &&
(base::Time::Now() - last_display_time) <
commerce::kCouponDisplayInterval.Get()) {
bubble_state_ = BubbleState::kShowingIcon;
UpdatePageActionIcon();
autofill_metrics::LogOfferNotificationBubbleSuppressed(
AutofillOfferData::OfferType::FREE_LISTING_COUPON_OFFER);
return;
Expand Down
Expand Up @@ -20,6 +20,7 @@
#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/test_autofill_clock.h"
#include "components/autofill/core/browser/ui/payments/payments_bubble_closed_reasons.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/strings/grit/components_strings.h"
Expand Down Expand Up @@ -148,6 +149,7 @@ class OfferNotificationBubbleViewsInteractiveUiTest
->notification_handler_.ClearShownNotificationIdForTesting();
}

TestAutofillClock test_clock_;
const AutofillOfferData::OfferType test_offer_type_;
};

Expand Down Expand Up @@ -547,4 +549,39 @@ IN_PROC_BROWSER_TEST_P(OfferNotificationBubbleViewsInteractiveUiTest,
GURL(GetDefaultTestDetailsUrlString()));
}

IN_PROC_BROWSER_TEST_P(
OfferNotificationBubbleViewsInteractiveUiTest,
RecordPageLoadsWithPromoOfferIconShowingMetricForFreeListingOffer) {
// Applies to free listing coupons offers only, as we don't log this metric
// for other offers.
if (test_offer_type_ !=
AutofillOfferData::OfferType::FREE_LISTING_COUPON_OFFER) {
return;
}

base::HistogramTester histogram_tester;

ShowBubbleForOfferAndVerify();
ASSERT_TRUE(GetOfferNotificationBubbleViews());
ASSERT_TRUE(IsIconVisible());
histogram_tester.ExpectBucketCount(
"Autofill.PageLoadsWithOfferIconShowing.FreeListingCouponOffer", true, 1);

test_clock_.Advance(kAutofillBubbleSurviveNavigationTime);

// Navigates to another valid domain will not reshow the bubble.
NavigateTo("https://www.merchantsite1.com/second");
EXPECT_FALSE(GetOfferNotificationBubbleViews());
EXPECT_TRUE(IsIconVisible());
histogram_tester.ExpectBucketCount(
"Autofill.PageLoadsWithOfferIconShowing.FreeListingCouponOffer", true, 2);

// Navigates to an invalid domain will dismiss the icon.
NavigateTo("https://www.about.com/");
EXPECT_FALSE(GetOfferNotificationBubbleViews());
EXPECT_FALSE(IsIconVisible());
histogram_tester.ExpectBucketCount(
"Autofill.PageLoadsWithOfferIconShowing.FreeListingCouponOffer", true, 2);
}

} // namespace autofill
Expand Up @@ -210,4 +210,24 @@ void LogSyncedOfferDataBeingValid(bool valid) {
base::UmaHistogramBoolean("Autofill.Offer.SyncedOfferDataBeingValid", valid);
}

void LogPageLoadsWithOfferIconShown(AutofillOfferData::OfferType offer_type) {
std::string histogram_name = "Autofill.PageLoadsWithOfferIconShowing";
// Switch to different sub-histogram depending on offer type being displayed.
switch (offer_type) {
case AutofillOfferData::OfferType::FREE_LISTING_COUPON_OFFER:
histogram_name += ".FreeListingCouponOffer";
break;
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();
return;
}
base::UmaHistogramBoolean(histogram_name, true);
}

} // namespace autofill::autofill_metrics
Expand Up @@ -126,6 +126,10 @@ void LogStoredOfferMetrics(
// Logs whether the synced autofill offer data is valid.
void LogSyncedOfferDataBeingValid(bool invalid);

// Log the presence of the offer notification icon shows on navigation event
// for |offer_type|.
void LogPageLoadsWithOfferIconShown(AutofillOfferData::OfferType offer_type);

} // namespace autofill::autofill_metrics

#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_METRICS_PAYMENTS_OFFERS_METRICS_H_
12 changes: 12 additions & 0 deletions tools/metrics/histograms/metadata/autofill/histograms.xml
Expand Up @@ -2485,6 +2485,18 @@ chromium-metrics-reviews@google.com.
<token key="OtpAuthType" variants="Autofill.OtpAuth.Type"/>
</histogram>

<histogram name="Autofill.PageLoadsWithOfferIconShowing.{OfferType}"
enum="BooleanShown" expires_after="2023-07-01">
<owner>meiliang@chromium.org</owner>
<owner>chrome-shopping@google.com</owner>
<summary>
Emits true if the offer notification icon is currently being shown in the
omnibox after a page navigation for {OfferType}. Doesn't emit any other
value.
</summary>
<token key="OfferType" variants="Autofill.OfferNotification.Type"/>
</histogram>

<histogram name="Autofill.PageTranslationStatus" enum="Boolean"
expires_after="2022-12-12">
<owner>koerber@google.com</owner>
Expand Down

0 comments on commit d9624d2

Please sign in to comment.