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

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

Issue 2808513002: [Payments] Add PaymentRequest checkout funnel UKMs. (Closed)
Patch Set: 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..b39d2fc6a0c215fa9d5d00ad6d42faf3a2fb80d3 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.
Mathieu 2017/04/10 01:03:01 remove
sebsg 2017/04/10 15:30:28 Done.
+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),
+ current_step_(STEP_INITIATED),
+ url_(url),
+ ukm_service_(ukm_service) {}
JourneyLogger::~JourneyLogger() {}
@@ -92,6 +108,10 @@ void JourneyLogger::SetShowCalled() {
was_show_called_ = true;
}
+void JourneyLogger::SetCurrentStep(CompletionStep step) {
+ current_step_ = step;
Mathieu 2017/04/10 01:03:01 Should we dcheck that step > current_step_?
sebsg 2017/04/10 15:30:28 Changed to bitfield as per you other suggestion
+}
+
void JourneyLogger::RecordJourneyStatsHistograms(
CompletionStatus completion_status) {
RecordSectionSpecificStats(completion_status);
@@ -99,6 +119,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);
+
+ RecordUkms(completion_status);
}
void JourneyLogger::RecordSectionSpecificStats(
@@ -199,4 +221,18 @@ void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
COMPLETION_STATUS_MAX);
}
+void JourneyLogger::RecordUkms(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, current_step_);
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698