Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Unified Diff: components/payments/core/journey_logger.cc

Issue 2808513002: [Payments] Add PaymentRequest checkout funnel UKMs. (Closed)
Patch Set: Addressed Mathp's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/payments/core/journey_logger.cc
diff --git a/components/payments/core/journey_logger.cc b/components/payments/core/journey_logger.cc
index d8731c053ff7c1f2bb6bc300ac731deef71cf744..eb1f62892d24d232f8dd24a6cd43c646137a68c6 100644
--- a/components/payments/core/journey_logger.cc
+++ b/components/payments/core/journey_logger.cc
@@ -8,6 +8,17 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
+#include "components/autofill/core/browser/autofill_experiments.h"
+#include "components/ukm/ukm_entry_builder.h"
+#include "components/ukm/ukm_service.h"
+
+namespace internal {
+// Name constants are exposed here so they can be referenced from tests.
+extern const char kUKMCheckoutFunnelEntryName[] =
+ "PaymentRequest.CheckoutFunnel";
+extern const char kUKMCompletionStatusMetricName[] = "CompletionStatus";
+extern const char kUKMLastStepMetricName[] = "LastStep";
+} // namespace internal
namespace payments {
@@ -54,11 +65,16 @@ std::string GetHistogramNameSuffix(
} // namespace
-JourneyLogger::JourneyLogger(bool is_incognito)
+JourneyLogger::JourneyLogger(bool is_incognito,
+ GURL url,
+ ukm::UkmService* ukm_service)
: was_can_make_payments_used_(false),
could_make_payment_(false),
was_show_called_(false),
- is_incognito_(is_incognito) {}
+ is_incognito_(is_incognito),
+ events_(EVENT_NOT_SHOWN),
Mathieu 2017/04/10 15:56:18 I liked initiated
sebsg 2017/04/10 17:27:56 Done.
+ url_(url),
+ ukm_service_(ukm_service) {}
JourneyLogger::~JourneyLogger() {}
@@ -92,6 +108,11 @@ void JourneyLogger::SetShowCalled() {
was_show_called_ = true;
}
+void JourneyLogger::SetEventOccured(int event) {
+ DCHECK(event < EVENT_MAX);
+ events_ |= event;
+}
+
void JourneyLogger::RecordJourneyStatsHistograms(
CompletionStatus completion_status) {
RecordSectionSpecificStats(completion_status);
@@ -99,6 +120,8 @@ void JourneyLogger::RecordJourneyStatsHistograms(
// Record the CanMakePayment metrics based on whether the transaction was
// completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
RecordCanMakePaymentStats(completion_status);
+
+ RecordUrlKeyedMetrics(completion_status);
}
void JourneyLogger::RecordSectionSpecificStats(
@@ -199,4 +222,18 @@ void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
COMPLETION_STATUS_MAX);
}
+void JourneyLogger::RecordUrlKeyedMetrics(CompletionStatus completion_status) {
+ if (!autofill::IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid())
+ return;
+
+ // Record the Checkout Funnel UKM.
+ int32_t source_id = ukm_service_->GetNewSourceID();
+ ukm_service_->UpdateSourceURL(source_id, url_);
+ std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
+ source_id, internal::kUKMCheckoutFunnelEntryName);
+ builder->AddMetric(internal::kUKMCompletionStatusMetricName,
+ completion_status);
+ builder->AddMetric(internal::kUKMLastStepMetricName, events_);
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698