Index: chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc |
diff --git a/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc b/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc |
index 27d1cdf651ba5b6d6dd6c9a8ca92afb0de9c2561..088fcf5f4ec887ec795b9f5c2ba06871cacbff0d 100644 |
--- a/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc |
+++ b/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc |
@@ -13,6 +13,7 @@ |
#include "chrome/common/url_constants.h" |
#include "content/public/browser/navigation_details.h" |
#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/user_metrics.h" |
#include "content/public/browser/web_contents.h" |
// Macro to log UMA statistics related to the 8 tiles shown on the NTP. |
@@ -33,6 +34,16 @@ enum SuggestionsType { |
const char kImpressionHistogramWithProvider[] = |
"NewTabPage.SuggestionsImpression.%s"; |
+// Number of Most Visited elements on the NTP for logging purposes. |
+const int kNumMostVisited = 8; |
+ |
+// Name of the histogram keeping track of Most Visited clicks. |
+const char kMostVisitedHistogramName[] = "NewTabPage.MostVisited"; |
+ |
+// Format string to generate the name for the histogram keeping track of |
+// suggestion clicks. |
+const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s"; |
+ |
} // namespace |
DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); |
@@ -58,6 +69,13 @@ NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents( |
return logger; |
} |
+// static |
+std::string NTPUserDataLogger::GetHistogramNameForProvider( |
beaudoin
2014/03/04 21:33:15
GetNavigationHistogramNameForProvider(
Maybe add
huangs
2014/03/04 22:10:43
Done; added GetImpressionHistogramNameForProvider(
|
+ const std::string& provider) { |
+ return base::StringPrintf(kMostVisitedHistogramWithProvider, |
+ provider.c_str()); |
+} |
+ |
void NTPUserDataLogger::EmitNtpStatistics() { |
UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); |
number_of_mouseovers_ = 0; |
@@ -143,12 +161,37 @@ void NTPUserDataLogger::LogImpression(int position, |
base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
base::StringPrintf(kImpressionHistogramWithProvider, |
base::UTF16ToUTF8(provider).c_str()), |
- 1, MostVisitedIframeSource::kNumMostVisited, |
- MostVisitedIframeSource::kNumMostVisited + 1, |
+ 1, |
+ kNumMostVisited, |
+ kNumMostVisited + 1, |
base::Histogram::kUmaTargetedHistogramFlag); |
counter->Add(position); |
beaudoin
2014/03/04 21:33:15
I'd be tempted to use the exact same pattern as be
huangs
2014/03/04 22:10:43
Done; added kImpressionHistogramName.
Note that t
|
} |
+void NTPUserDataLogger::LogNavigation(int position, |
+ const base::string16& provider) { |
+ // Log the Most Visited navigation. |
beaudoin
2014/03/04 21:33:15
for both navigations that have providers and those
huangs
2014/03/04 22:10:43
Done.
|
+ UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position, |
+ kNumMostVisited); |
+ |
+ // If a provider is specified, log the metric specific to it. |
+ if (!provider.empty()) { |
+ // Cannot rely on UMA histograms macro because the name of the histogram is |
+ // generated dynamically. |
+ base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
+ GetHistogramNameForProvider(base::UTF16ToUTF8(provider)), |
+ 1, |
+ kNumMostVisited, |
+ kNumMostVisited + 1, |
+ base::Histogram::kUmaTargetedHistogramFlag); |
+ counter->Add(position); |
+ } |
+ |
+ // Records the action. This will be available as a time-stamped stream |
+ // server-side and can be used to compute time-to-long-dwell. |
+ content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
+} |
+ |
// content::WebContentsObserver override |
void NTPUserDataLogger::NavigationEntryCommitted( |
const content::LoadCommittedDetails& load_details) { |