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

Unified Diff: chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc

Issue 2124903003: Record impressions/navigations only once per tile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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: 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 6773db8f0576592b652752373fffc45cf165fe34..ab4587c3049889f6e1a6dcbc89083b530712b12a 100644
--- a/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc
@@ -89,10 +89,19 @@ NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
// We record the URL of this NTP in order to identify navigations that
// originate from it. We use the NavigationController's URL since it might
// differ from the WebContents URL which is usually chrome://newtab/.
+ //
+ // We update the NTP URL every time this function is called, because the NTP
+ // URL sometimes changes while it is open, and we care about the final one for
+ // detecting when the user leaves or returns to the NTP.
Marc Treib 2016/07/12 08:17:46 ...wait, what? It can change while the NTP is open
sfiera 2016/07/12 08:37:33 Yep. Reproduction: 1. Start Chromium with a clean
Marc Treib 2016/07/12 08:58:47 The *tiles* can change, but the NTP URL? I guess i
sfiera 2016/07/12 09:08:58 Oh, misread that. But still yes. On first launch,
Marc Treib 2016/07/14 14:40:52 On subsequent runs, the Google TLD doesn't change
+ //
+ // TODO(sfiera): move to a world where the NTP URL is always chrome://newtab/.
Marc Treib 2016/07/12 08:17:46 hahahahaha... wait, you're serious. Let me laugh e
sfiera 2016/07/14 14:11:08 Restricted the TODO somewhat--I expect it's a non-
Marc Treib 2016/07/14 14:40:52 External as in remote? No. We might conceivably mo
const content::NavigationEntry* entry =
content->GetController().GetVisibleEntry();
- if (entry)
+ if (entry && (logger->ntp_url_ != entry->GetURL())) {
+ VLOG(1) << "NTP URL changed from \"" << logger->ntp_url_ << "\" to \""
+ << entry->GetURL() << "\"";
logger->ntp_url_ = entry->GetURL();
+ }
return logger;
}
@@ -129,6 +138,13 @@ void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
void NTPUserDataLogger::LogMostVisitedImpression(
int position, NTPLoggingTileSource tile_source) {
+ if (position >= static_cast<int>(impression_was_logged_.size())) {
Marc Treib 2016/07/12 08:17:46 Hm, might as well just resize this to kNumMostVisi
sfiera 2016/07/14 14:11:07 Do we have a guarantee that we can't be called wit
Marc Treib 2016/07/14 14:40:52 No guarantee, but the histograms support only 8 bi
sfiera 2016/07/15 09:55:10 Fixed to be 8 always.
+ impression_was_logged_.resize(position + 1);
+ } else if (impression_was_logged_[position]) {
+ return;
+ }
+ impression_was_logged_[position] = true;
+
UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position,
kNumMostVisited);
@@ -165,14 +181,30 @@ void NTPUserDataLogger::LogMostVisitedNavigation(
content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
}
+// content::WebContentsObserver override
Marc Treib 2016/07/12 08:17:46 Any reason for moving this up here? (Bad rebase? I
sfiera 2016/07/14 14:11:07 Yep, that. Down.
+void NTPUserDataLogger::NavigationEntryCommitted(
+ const content::LoadCommittedDetails& load_details) {
+ // User is navigating away from NTP; log stats.
+ if (load_details.previous_url.is_valid()
Marc Treib 2016/07/12 08:17:46 We could keep the early-out if the previous URL is
sfiera 2016/07/14 14:11:07 This conditional is now gone, because we don't emi
+ && search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
+ VLOG(1) << "Leaving New Tab Page";
+ EmitNtpStatistics(EmitReason::NAVIGATED_AWAY);
Marc Treib 2016/07/12 08:17:46 Is there no "return" here on purpose? (So that a r
sfiera 2016/07/14 14:11:07 Conditional is gone. (this did handle reload)
+ }
+
+ // User is returning to NTP, probably via the back button; reset stats for
+ // impressions.
+ if (load_details.previous_url.is_valid() &&
+ load_details.entry->GetURL().is_valid() &&
+ search::MatchesOriginAndPath(load_details.entry->GetURL(), ntp_url_)) {
Marc Treib 2016/07/12 08:17:46 Fun fact: search::MatchesOriginAndPath isn't symme
sfiera 2016/07/14 14:11:07 Changed to ==.
+ VLOG(1) << "Returning to New Tab Page";
+ impression_was_logged_.clear();
Marc Treib 2016/07/12 08:17:46 So LoadTime and NumberOfTiles won't be logged agai
sfiera 2016/07/14 14:11:07 Reset has_emitted_.
+ }
+}
+
void NTPUserDataLogger::TabDeactivated() {
EmitNtpStatistics(EmitReason::CLOSED);
}
-void NTPUserDataLogger::MostVisitedItemsChanged() {
- EmitNtpStatistics(EmitReason::MV_CHANGED);
-}
-
NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
: content::WebContentsObserver(contents),
has_server_side_suggestions_(false),
@@ -201,16 +233,6 @@ NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
}
}
-// content::WebContentsObserver override
-void NTPUserDataLogger::NavigationEntryCommitted(
- const content::LoadCommittedDetails& load_details) {
- if (!load_details.previous_url.is_valid())
- return;
-
- if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url))
- EmitNtpStatistics(EmitReason::NAVIGATED_AWAY);
-}
-
void NTPUserDataLogger::EmitNtpStatistics(EmitReason reason) {
// We only send statistics once per page.
// And we don't send if there are no tiles recorded.

Powered by Google App Engine
This is Rietveld 408576698