Commit 1fafacd8 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Record phone number lengths to UMA.

This collects metrics for the length of phone numbers and the number of
digits in them. These are collected when shown to the user and when the
user actually selects a device to send that number to a device. We also
distinguish between the entry points of right and left click on links
and text selections.

The new metric name is built like this:
Sharing.ClickToCallPhoneNumber{Length,Digits}.
  {LeftClickLink,RightClickLink,RightClickSelection}.
  {Sending,Showing}

Bug: 1001033
Change-Id: I59ed705170153b8adcbe00021cedb5118f1cf27b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1878198Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709400}
parent c8f4cb41
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/external_protocol_dialog.h" #include "chrome/browser/chromeos/external_protocol_dialog.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_ui_controller.h" #include "chrome/browser/sharing/click_to_call/click_to_call_ui_controller.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h" #include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
...@@ -117,6 +118,9 @@ bool MaybeAddDevicesAndShowPicker( ...@@ -117,6 +118,9 @@ bool MaybeAddDevicesAndShowPicker(
std::vector<std::unique_ptr<syncer::DeviceInfo>> devices; std::vector<std::unique_ptr<syncer::DeviceInfo>> devices;
if (ShouldOfferClickToCallForURL(web_contents->GetBrowserContext(), url)) { if (ShouldOfferClickToCallForURL(web_contents->GetBrowserContext(), url)) {
LogClickToCallPhoneNumberSize(GetUnescapedURLContent(url),
SharingClickToCallEntryPoint::kLeftClickLink,
/*send_to_device=*/false);
icon_type = PageActionIconType::kClickToCall; icon_type = PageActionIconType::kClickToCall;
controller = controller =
ClickToCallUiController::GetOrCreateFromWebContents(web_contents); ClickToCallUiController::GetOrCreateFromWebContents(web_contents);
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
...@@ -23,6 +25,7 @@ ...@@ -23,6 +25,7 @@
#include "components/sync/driver/profile_sync_service.h" #include "components/sync/driver/profile_sync_service.h"
#include "components/ukm/test_ukm_recorder.h" #include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h" #include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -58,6 +61,10 @@ class ClickToCallBrowserTestBase : public SharingBrowserTest { ...@@ -58,6 +61,10 @@ class ClickToCallBrowserTestBase : public SharingBrowserTest {
protected: protected:
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
std::string HistogramName(const char* suffix) {
return base::StrCat({"Sharing.ClickToCallPhoneNumber", suffix});
}
private: private:
DISALLOW_COPY_AND_ASSIGN(ClickToCallBrowserTestBase); DISALLOW_COPY_AND_ASSIGN(ClickToCallBrowserTestBase);
}; };
...@@ -199,6 +206,105 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, ...@@ -199,6 +206,105 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
} }
} }
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, ContextMenu_TelLink_Histograms) {
base::HistogramTester histograms;
Init(sync_pb::SharingSpecificFields::CLICK_TO_CALL,
sync_pb::SharingSpecificFields::UNKNOWN);
// Trigger a context menu for a link with 8 digits and 9 characters.
std::unique_ptr<TestRenderViewContextMenu> menu = InitContextMenu(
GURL("tel:1234-5678"), kLinkText, kTextWithoutPhoneNumber);
base::HistogramTester::CountsMap expected_counts;
expected_counts[HistogramName("Digits")] = 1;
expected_counts[HistogramName("Digits.RightClickLink.Showing")] = 1;
expected_counts[HistogramName("Length")] = 1;
expected_counts[HistogramName("Length.RightClickLink.Showing")] = 1;
EXPECT_THAT(histograms.GetTotalCountsForPrefix(HistogramName("")),
testing::ContainerEq(expected_counts));
histograms.ExpectUniqueSample(HistogramName("Digits"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Digits.RightClickLink.Showing"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Length"),
/*sample=*/9, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Length.RightClickLink.Showing"),
/*sample=*/9, /*count=*/1);
// Send the number to the device in the context menu.
menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE,
0);
expected_counts[HistogramName("Digits")] = 2;
expected_counts[HistogramName("Digits.RightClickLink.Sending")] = 1;
expected_counts[HistogramName("Length")] = 2;
expected_counts[HistogramName("Length.RightClickLink.Sending")] = 1;
EXPECT_THAT(histograms.GetTotalCountsForPrefix(HistogramName("")),
testing::ContainerEq(expected_counts));
histograms.ExpectUniqueSample(HistogramName("Digits"),
/*sample=*/8, /*count=*/2);
histograms.ExpectUniqueSample(HistogramName("Digits.RightClickLink.Sending"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Length"),
/*sample=*/9, /*count=*/2);
histograms.ExpectUniqueSample(HistogramName("Length.RightClickLink.Sending"),
/*sample=*/9, /*count=*/1);
}
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest,
ContextMenu_HighlightedText_Histograms) {
base::HistogramTester histograms;
Init(sync_pb::SharingSpecificFields::CLICK_TO_CALL,
sync_pb::SharingSpecificFields::UNKNOWN);
// Trigger a context menu for a selection with 8 digits and 9 characters.
std::unique_ptr<TestRenderViewContextMenu> menu =
InitContextMenu(GURL(kNonTelUrl), kLinkText, "1234-5678");
base::HistogramTester::CountsMap expected_counts;
expected_counts[HistogramName("Digits")] = 1;
expected_counts[HistogramName("Digits.RightClickSelection.Showing")] = 1;
expected_counts[HistogramName("Length")] = 1;
expected_counts[HistogramName("Length.RightClickSelection.Showing")] = 1;
EXPECT_THAT(histograms.GetTotalCountsForPrefix(HistogramName("")),
testing::ContainerEq(expected_counts));
histograms.ExpectUniqueSample(HistogramName("Digits"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(
HistogramName("Digits.RightClickSelection.Showing"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Length"),
/*sample=*/9, /*count=*/1);
histograms.ExpectUniqueSample(
HistogramName("Length.RightClickSelection.Showing"),
/*sample=*/9, /*count=*/1);
// Send the number to the device in the context menu.
menu->ExecuteCommand(IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE,
0);
expected_counts[HistogramName("Digits")] = 2;
expected_counts[HistogramName("Digits.RightClickSelection.Sending")] = 1;
expected_counts[HistogramName("Length")] = 2;
expected_counts[HistogramName("Length.RightClickSelection.Sending")] = 1;
EXPECT_THAT(histograms.GetTotalCountsForPrefix(HistogramName("")),
testing::ContainerEq(expected_counts));
histograms.ExpectUniqueSample(HistogramName("Digits"),
/*sample=*/8, /*count=*/2);
histograms.ExpectUniqueSample(
HistogramName("Digits.RightClickSelection.Sending"),
/*sample=*/8, /*count=*/1);
histograms.ExpectUniqueSample(HistogramName("Length"),
/*sample=*/9, /*count=*/2);
histograms.ExpectUniqueSample(
HistogramName("Length.RightClickSelection.Sending"),
/*sample=*/9, /*count=*/1);
}
class ClickToCallBrowserTestWithContextMenuDisabled class ClickToCallBrowserTestWithContextMenuDisabled
: public ClickToCallBrowserTestBase { : public ClickToCallBrowserTestBase {
public: public:
......
...@@ -54,6 +54,8 @@ void ClickToCallContextMenuObserver::BuildMenu( ...@@ -54,6 +54,8 @@ void ClickToCallContextMenuObserver::BuildMenu(
const std::string& phone_number, const std::string& phone_number,
SharingClickToCallEntryPoint entry_point) { SharingClickToCallEntryPoint entry_point) {
DCHECK(!phone_number.empty()); DCHECK(!phone_number.empty());
LogClickToCallPhoneNumberSize(phone_number, entry_point,
/*send_to_device=*/false);
phone_number_ = phone_number; phone_number_ = phone_number;
entry_point_ = entry_point; entry_point_ = entry_point;
......
...@@ -37,6 +37,9 @@ void ClickToCallUiController::ShowDialog( ...@@ -37,6 +37,9 @@ void ClickToCallUiController::ShowDialog(
const base::Optional<url::Origin>& initiating_origin, const base::Optional<url::Origin>& initiating_origin,
const GURL& url, const GURL& url,
bool hide_default_handler) { bool hide_default_handler) {
LogClickToCallPhoneNumberSize(GetUnescapedURLContent(url),
SharingClickToCallEntryPoint::kLeftClickLink,
/*send_to_device=*/false);
auto* controller = GetOrCreateFromWebContents(web_contents); auto* controller = GetOrCreateFromWebContents(web_contents);
controller->phone_url_ = url; controller->phone_url_ = url;
controller->hide_default_handler_ = hide_default_handler; controller->hide_default_handler_ = hide_default_handler;
...@@ -58,7 +61,7 @@ void ClickToCallUiController::OnDeviceSelected( ...@@ -58,7 +61,7 @@ void ClickToCallUiController::OnDeviceSelected(
/*has_devices=*/true, /*has_apps=*/false, /*has_devices=*/true, /*has_apps=*/false,
SharingClickToCallSelection::kDevice); SharingClickToCallSelection::kDevice);
SendNumberToDevice(device, phone_number); SendNumberToDevice(device, phone_number, entry_point);
} }
void ClickToCallUiController::OnDialogClosed(SharingDialog* dialog) { void ClickToCallUiController::OnDialogClosed(SharingDialog* dialog) {
...@@ -113,12 +116,17 @@ void ClickToCallUiController::OnDeviceChosen(const syncer::DeviceInfo& device) { ...@@ -113,12 +116,17 @@ void ClickToCallUiController::OnDeviceChosen(const syncer::DeviceInfo& device) {
if (ukm_recorder_) if (ukm_recorder_)
std::move(ukm_recorder_).Run(SharingClickToCallSelection::kDevice); std::move(ukm_recorder_).Run(SharingClickToCallSelection::kDevice);
SendNumberToDevice(device, GetUnescapedURLContent(phone_url_)); SendNumberToDevice(device, GetUnescapedURLContent(phone_url_),
SharingClickToCallEntryPoint::kLeftClickLink);
} }
void ClickToCallUiController::SendNumberToDevice( void ClickToCallUiController::SendNumberToDevice(
const syncer::DeviceInfo& device, const syncer::DeviceInfo& device,
const std::string& phone_number) { const std::string& phone_number,
SharingClickToCallEntryPoint entry_point) {
LogClickToCallPhoneNumberSize(phone_number, entry_point,
/*send_to_device=*/true);
SharingMessage sharing_message; SharingMessage sharing_message;
sharing_message.mutable_click_to_call_message()->set_phone_number( sharing_message.mutable_click_to_call_message()->set_phone_number(
phone_number); phone_number);
......
...@@ -69,7 +69,8 @@ class ClickToCallUiController ...@@ -69,7 +69,8 @@ class ClickToCallUiController
// Sends |phone_number| to |device| as a SharingMessage. // Sends |phone_number| to |device| as a SharingMessage.
void SendNumberToDevice(const syncer::DeviceInfo& device, void SendNumberToDevice(const syncer::DeviceInfo& device,
const std::string& phone_number); const std::string& phone_number,
SharingClickToCallEntryPoint entry_point);
UKMRecorderCallback ukm_recorder_; UKMRecorderCallback ukm_recorder_;
GURL phone_url_; GURL phone_url_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/sharing/sharing_metrics.h" #include "chrome/browser/sharing/sharing_metrics.h"
#include <string.h> #include <string.h>
#include <algorithm>
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -32,6 +33,26 @@ const char* GetEnumStringValue(SharingFeatureName feature) { ...@@ -32,6 +33,26 @@ const char* GetEnumStringValue(SharingFeatureName feature) {
} }
} }
// The returned values must match the values of the SharingClickToCallEntryPoint
// suffixes defined in histograms.xml.
const char* ClickToCallEntryPointToSuffix(
SharingClickToCallEntryPoint entry_point) {
switch (entry_point) {
case SharingClickToCallEntryPoint::kLeftClickLink:
return "LeftClickLink";
case SharingClickToCallEntryPoint::kRightClickLink:
return "RightClickLink";
case SharingClickToCallEntryPoint::kRightClickSelection:
return "RightClickSelection";
}
}
// The returned values must match the values of the
// SharingClickToCallSendToDevice suffixes defined in histograms.xml.
const char* SendToDeviceToSuffix(bool send_to_device) {
return send_to_device ? "Sending" : "Showing";
}
const std::string& MessageTypeToMessageSuffix( const std::string& MessageTypeToMessageSuffix(
chrome_browser_sharing::MessageType message_type) { chrome_browser_sharing::MessageType message_type) {
// For proto3 enums unrecognized enum values are kept when parsing and their // For proto3 enums unrecognized enum values are kept when parsing and their
...@@ -247,3 +268,23 @@ void LogSharedClipboardSelectedTextSize(int text_size) { ...@@ -247,3 +268,23 @@ void LogSharedClipboardSelectedTextSize(int text_size) {
UMA_HISTOGRAM_COUNTS_100000("Sharing.SharedClipboardSelectedTextSize", UMA_HISTOGRAM_COUNTS_100000("Sharing.SharedClipboardSelectedTextSize",
text_size); text_size);
} }
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device) {
int length = number.size();
int digits = std::count_if(number.begin(), number.end(),
[](char c) { return std::isdigit(c); });
std::string suffix =
base::StrCat({ClickToCallEntryPointToSuffix(entry_point), ".",
SendToDeviceToSuffix(send_to_device)});
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberLength", length);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberLength.", suffix}), length);
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberDigits", digits);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberDigits.", suffix}), digits);
}
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_SHARING_SHARING_METRICS_H_ #ifndef CHROME_BROWSER_SHARING_SHARING_METRICS_H_
#define CHROME_BROWSER_SHARING_SHARING_METRICS_H_ #define CHROME_BROWSER_SHARING_SHARING_METRICS_H_
#include <string>
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/sharing/proto/sharing_message.pb.h" #include "chrome/browser/sharing/proto/sharing_message.pb.h"
#include "chrome/browser/sharing/sharing_constants.h" #include "chrome/browser/sharing/sharing_constants.h"
...@@ -163,4 +165,9 @@ void LogClickToCallUKM(content::WebContents* web_contents, ...@@ -163,4 +165,9 @@ void LogClickToCallUKM(content::WebContents* web_contents,
// Records the size of the selected text in Shared Clipboard. // Records the size of the selected text in Shared Clipboard.
void LogSharedClipboardSelectedTextSize(int text_size); void LogSharedClipboardSelectedTextSize(int text_size);
// Logs the raw phone number length and the number of digits in it.
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device);
#endif // CHROME_BROWSER_SHARING_SHARING_METRICS_H_ #endif // CHROME_BROWSER_SHARING_SHARING_METRICS_H_
...@@ -134605,6 +134605,34 @@ should be kept until we remove incident reporting. --> ...@@ -134605,6 +134605,34 @@ should be kept until we remove incident reporting. -->
</summary> </summary>
</histogram> </histogram>
<histogram name="Sharing.ClickToCallPhoneNumberDigits" units="digits"
expires_after="M83">
<!-- Name completed by histogram_suffixes name="SharingClickToCallEntryPoint"
and name="SharingClickToCallSendToDevice" -->
<owner>mvanouwerkerk@chromium.org</owner>
<owner>knollr@chromium.org</owner>
<summary>
The number of digits in a phone number. Logged when right clicking on a
selected phone number or tel link, showing the Click to Call dialog and when
selecting a device. Desktop only.
</summary>
</histogram>
<histogram name="Sharing.ClickToCallPhoneNumberLength" units="characters"
expires_after="M83">
<!-- Name completed by histogram_suffixes name="SharingClickToCallEntryPoint"
and name="SharingClickToCallSendToDevice" -->
<owner>mvanouwerkerk@chromium.org</owner>
<owner>knollr@chromium.org</owner>
<summary>
The number of characters in a phone number including digits and non-digits.
Logged when right clicking on a selected phone number or tel link, showing
the Click to Call dialog and when selecting a device. Desktop only.
</summary>
</histogram>
<histogram name="Sharing.ClickToCallReceiveDeviceState" <histogram name="Sharing.ClickToCallReceiveDeviceState"
enum="ClickToCallDeviceState" expires_after="M80"> enum="ClickToCallDeviceState" expires_after="M80">
<owner>mvanouwerkerk@chromium.org</owner> <owner>mvanouwerkerk@chromium.org</owner>
...@@ -179726,6 +179754,31 @@ regressions. --> ...@@ -179726,6 +179754,31 @@ regressions. -->
<affected-histogram name="Setup.Install.Win32ApiError"/> <affected-histogram name="Setup.Install.Win32ApiError"/>
</histogram_suffixes> </histogram_suffixes>
<histogram_suffixes name="SharingClickToCallEntryPoint" separator=".">
<suffix name="LeftClickLink" label="Left click on a tel link"/>
<suffix name="RightClickLink" label="Right click on a tel link"/>
<suffix name="RightClickSelection" label="Right click on a selection"/>
<affected-histogram name="Sharing.ClickToCallPhoneNumberDigits"/>
<affected-histogram name="Sharing.ClickToCallPhoneNumberLength"/>
</histogram_suffixes>
<histogram_suffixes name="SharingClickToCallSendToDevice" separator=".">
<suffix name="Sending" label="Sending to a device"/>
<suffix name="Showing" label="Showing to the user"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberDigits.LeftClickLink"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberDigits.RightClickLink"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberDigits.RightClickSelection"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberLength.LeftClickLink"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberLength.RightClickLink"/>
<affected-histogram
name="Sharing.ClickToCallPhoneNumberLength.RightClickSelection"/>
</histogram_suffixes>
<histogram_suffixes name="SharingClickToCallUi" separator="."> <histogram_suffixes name="SharingClickToCallUi" separator=".">
<suffix name="ContextMenu" label="Context menu"/> <suffix name="ContextMenu" label="Context menu"/>
<suffix name="Dialog" label="Dialog"/> <suffix name="Dialog" label="Dialog"/>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment