Skip to content

Commit

Permalink
[Payments] Use event to log checkout funnel metrics.
Browse files Browse the repository at this point in the history
BUG=724256

Review-Url: https://codereview.chromium.org/2892833002
Cr-Commit-Position: refs/heads/master@{#473372}
  • Loading branch information
sebsg authored and Commit bot committed May 19, 2017
1 parent 3c7f1c4 commit 6ae7018
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ public PaymentRequestImpl(RenderFrameHost renderFrameHost) {
if (sCanMakePaymentQueries == null) sCanMakePaymentQueries = new ArrayMap<>();

mCurrencyFormatterMap = new HashMap<>();

recordSuccessFunnelHistograms("Initiated");
}

@Override
Expand Down Expand Up @@ -658,7 +656,6 @@ private void triggerPaymentAppUiSkipIfApplicable() {

mDidRecordShowEvent = true;
mShouldRecordAbortReason = true;
recordSuccessFunnelHistograms("SkippedShow");
mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_SKIPPED_SHOW);
mJourneyLogger.setShowCalled();

Expand Down Expand Up @@ -1010,7 +1007,7 @@ private void providePaymentInformation() {
if (!mDidRecordShowEvent) {
mDidRecordShowEvent = true;
mShouldRecordAbortReason = true;
recordSuccessFunnelHistograms("Shown");
mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_SHOWN);
mJourneyLogger.setShowCalled();
}
}
Expand Down Expand Up @@ -1310,7 +1307,6 @@ public boolean onPayClicked(PaymentOption selectedShippingAddress,
Collections.unmodifiableMap(methodData), mRawTotal, mRawLineItems,
Collections.unmodifiableMap(modifiers), this);

recordSuccessFunnelHistograms("PayClicked");
mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_PAY_CLICKED);
return !(instrument instanceof AutofillPaymentInstrument);
}
Expand Down Expand Up @@ -1665,7 +1661,6 @@ public void onInstrumentDetailsReady(String methodName, String stringifiedDetail
// spinner shows up until the merchant notifies that payment was completed.
if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUiSkip();

recordSuccessFunnelHistograms("ReceivedInstrumentDetails");
mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_RECEIVED_INSTRUMENT_DETAILS);

mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifiedDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,26 @@ public void testSuccessCheckoutFunnel()
// Initiate a payment request.
mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRule.getReadyToPay());

// Make sure sure that the "Initiated" and "Shown" events were logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Initiated", 1));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Shown", 1));

// Click the pay button.
mPaymentRequestTestRule.clickAndWait(
R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput());

// Make sure sure that the "PayClicked" event was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.PayClicked", 1));

// Unmask the credit card,
mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait(
R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask());
mPaymentRequestTestRule.clickCardUnmaskButtonAndWait(
DialogInterface.BUTTON_POSITIVE, mPaymentRequestTestRule.getDismissed());

// Make sure sure that the "ReceivedInstrumentDetails" and "Completed" events were logged.
// Make sure all the steps were logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Initiated", 1));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Shown", 1));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.PayClicked", 1));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.ReceivedInstrumentDetails", 1));
Expand Down Expand Up @@ -338,6 +334,7 @@ public void testMetrics_SkippedShow()
mPaymentRequestTestRule.triggerUIAndWait(
"androidPaySkipUiBuy", mPaymentRequestTestRule.getResultReady());

// The "SkippedShow" step should be logged instead of "Shown".
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.SkippedShow", 1));
Expand All @@ -362,6 +359,12 @@ public void testMetrics_SkippedShow_Disabled()
mPaymentRequestTestRule.triggerUIAndWait(
"androidPaySkipUiBuy", mPaymentRequestTestRule.getReadyToPay());

// Close the payment Request.
mPaymentRequestTestRule.clickAndWait(
R.id.close_button, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Request cancelled"});

// The "Shown" step should be logged, not "SkippedShow".
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Shown", 1));
Expand All @@ -381,11 +384,6 @@ public void testShownLoggedOnlyOnce()
// Initiate a payment request.
mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRule.getReadyToPay());

// Make sure sure that the "Shown" event was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Shown", 1));

// Add a shipping address, which triggers a second "Show".
mPaymentRequestTestRule.clickInShippingSummaryAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Expand All @@ -398,7 +396,12 @@ public void testShownLoggedOnlyOnce()
mPaymentRequestTestRule.clickInEditorAndWait(
R.id.payments_edit_done_button, mPaymentRequestTestRule.getReadyToPay());

// Make sure "Shown" is still logged only once.
// Close the payment Request.
mPaymentRequestTestRule.clickAndWait(
R.id.close_button, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Request cancelled"});

// Make sure "Shown" is logged only once.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CheckoutFunnel.Shown", 1));
Expand Down
19 changes: 19 additions & 0 deletions components/payments/core/journey_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void JourneyLogger::RecordJourneyStatsHistograms(
DCHECK(!has_recorded_);
has_recorded_ = true;

RecordCheckoutFlowMetrics();

RecordSectionSpecificStats(completion_status);

// Record the CanMakePayment metrics based on whether the transaction was
Expand All @@ -124,6 +126,23 @@ void JourneyLogger::RecordJourneyStatsHistograms(
RecordUrlKeyedMetrics(completion_status);
}

void JourneyLogger::RecordCheckoutFlowMetrics() {
UMA_HISTOGRAM_BOOLEAN("PaymentRequest.CheckoutFunnel.Initiated", true);

if (events_ & EVENT_SHOWN)
UMA_HISTOGRAM_BOOLEAN("PaymentRequest.CheckoutFunnel.Shown", true);

if (events_ & EVENT_PAY_CLICKED)
UMA_HISTOGRAM_BOOLEAN("PaymentRequest.CheckoutFunnel.PayClicked", true);

if (events_ & EVENT_RECEIVED_INSTRUMENT_DETAILS)
UMA_HISTOGRAM_BOOLEAN(
"PaymentRequest.CheckoutFunnel.ReceivedInstrumentDetails", true);

if (events_ & EVENT_SKIPPED_SHOW)
UMA_HISTOGRAM_BOOLEAN("PaymentRequest.CheckoutFunnel.SkippedShow", true);
}

void JourneyLogger::RecordSectionSpecificStats(
CompletionStatus completion_status) {
// Record whether the user had suggestions for each requested information.
Expand Down
4 changes: 4 additions & 0 deletions components/payments/core/journey_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class JourneyLogger {
bool is_requested_;
};

// Records the histograms for all the steps of a complete checkout flow that
// were reached.
void RecordCheckoutFlowMetrics();

// Records the histograms for all the sections that were requested by the
// merchant.
void RecordSectionSpecificStats(CompletionStatus completion_status);
Expand Down

0 comments on commit 6ae7018

Please sign in to comment.