| 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..2f771867542870143ea9ef945a985853c100000a 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.
|
| @@ -28,11 +29,24 @@ enum SuggestionsType {
|
| SUGGESTIONS_TYPE_COUNT = 2
|
| };
|
|
|
| +// Number of Most Visited elements on the NTP for logging purposes.
|
| +const int kNumMostVisited = 8;
|
| +
|
| +// Name of the histogram keeping track of Most Visited impressions.
|
| +const char kImpressionHistogramName[] = "NewTabPage.SuggestionsImpression";
|
| +
|
| // Format string to generate the name for the histogram keeping track of
|
| // suggestion impressions.
|
| const char kImpressionHistogramWithProvider[] =
|
| "NewTabPage.SuggestionsImpression.%s";
|
|
|
| +// Name of the histogram keeping track of Most Visited navigations.
|
| +const char kMostVisitedHistogramName[] = "NewTabPage.MostVisited";
|
| +
|
| +// Format string to generate the name for the histogram keeping track of
|
| +// suggestion navigations.
|
| +const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s";
|
| +
|
| } // namespace
|
|
|
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
|
| @@ -58,6 +72,20 @@ NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
|
| return logger;
|
| }
|
|
|
| +// static
|
| +std::string NTPUserDataLogger::GetImpressionHistogramNameForProvider(
|
| + const std::string& provider) {
|
| + return base::StringPrintf(kImpressionHistogramWithProvider,
|
| + provider.c_str());
|
| +}
|
| +
|
| +// static
|
| +std::string NTPUserDataLogger::GetNavigationHistogramNameForProvider(
|
| + 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;
|
| @@ -138,15 +166,48 @@ void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) {
|
|
|
| void NTPUserDataLogger::LogImpression(int position,
|
| const base::string16& provider) {
|
| - // Cannot rely on UMA histograms macro because the name of the histogram is
|
| - // generated dynamically.
|
| - base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
|
| - base::StringPrintf(kImpressionHistogramWithProvider,
|
| - base::UTF16ToUTF8(provider).c_str()),
|
| - 1, MostVisitedIframeSource::kNumMostVisited,
|
| - MostVisitedIframeSource::kNumMostVisited + 1,
|
| - base::Histogram::kUmaTargetedHistogramFlag);
|
| - counter->Add(position);
|
| + // Log the Most Visited navigation for navigations that have providers and
|
| + // those that dont.
|
| + UMA_HISTOGRAM_ENUMERATION(kImpressionHistogramName, 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(
|
| + GetImpressionHistogramNameForProvider(base::UTF16ToUTF8(provider)),
|
| + 1,
|
| + kNumMostVisited,
|
| + kNumMostVisited + 1,
|
| + base::Histogram::kUmaTargetedHistogramFlag);
|
| + counter->Add(position);
|
| + }
|
| +}
|
| +
|
| +void NTPUserDataLogger::LogNavigation(int position,
|
| + const base::string16& provider) {
|
| + // Log the Most Visited navigation for navigations that have providers and
|
| + // those that dont.
|
| + 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(
|
| + GetNavigationHistogramNameForProvider(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
|
|
|