Adds the NewTabPage.SuggestedSitesAction stat.

BUG=118427
TEST=With the "NTP Suggestions page" flag enabled, go to the NTP and switch between panes (e.g. Apps and Suggested), then click on a link in the Suggestd pane. Go back to the NTP and type a URL in the Omnibox. Open a new tab and close it. Then, go to about:histograms and verify that there are data points at least for values 1, 11, 12 and 13 in the NewTabPage.SuggestedSitesAction stat. Other values are OK, as long as these are present.

Review URL: http://codereview.chromium.org/9958116

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132249 0039d316-1c4b-4281-b951-d872f2087c98
parent d326e27e
......@@ -7,6 +7,16 @@ cr.define('ntp', function() {
var TilePage = ntp.TilePage;
/**
* See description for these values in suggestions_page_handler.h.
* @enum {number}
*/
var SuggestedSitesAction = {
CLICKED_SUGGESTED_TILE: 11,
CLICKED_OTHER_NTP_PANE: 12,
OTHER: 13
};
/**
* A counter for generating unique tile IDs.
*/
......@@ -134,6 +144,8 @@ cr.define('ntp', function() {
// Records the index of this tile.
chrome.send('metricsHandler:recordInHistogram',
['NewTabPage.SuggestedSite', this.index, 8]);
chrome.send('suggestedSitesAction',
[SuggestedSitesAction.CLICKED_SUGGESTED_TILE]);
}
},
......@@ -286,6 +298,9 @@ cr.define('ntp', function() {
this.classList.add('suggestions-page');
this.data_ = null;
this.suggestionsTiles_ = this.getElementsByClassName('suggestions real');
this.addEventListener('carddeselected', this.handleCardDeselected_);
this.addEventListener('cardselected', this.handleCardSelected_);
},
/**
......@@ -313,6 +328,25 @@ cr.define('ntp', function() {
}
},
/**
* Handles the 'card deselected' event (i.e. the user clicked to another
* pane).
* @param {Event} e The CardChanged event.
*/
handleCardDeselected_: function(e) {
chrome.send('suggestedSitesAction',
[SuggestedSitesAction.CLICKED_OTHER_NTP_PANE]);
},
/**
* Handles the 'card selected' event (i.e. the user clicked to select the
* Suggested pane).
* @param {Event} e The CardChanged event.
*/
handleCardSelected_: function(e) {
chrome.send('suggestedSitesSelected');
},
/**
* Array of suggestions data objects.
* @type {Array}
......
......@@ -11,6 +11,7 @@
#include "base/md5.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram.h"
#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
......@@ -27,18 +28,62 @@
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
using content::UserMetricsAction;
namespace {
// Those values are defined in histograms.xml. These represent the action that
// the user has taken to leave the Suggested pane, given that they have viewed
// that pane on the NTP.
enum SuggestedSitesActions {
// Values 0 to 10 are the core values from PageTransition (see
// page_transition_types.h).
// The user has clicked on a Suggested tile.
SUGGESTED_SITES_ACTION_CLICKED_SUGGESTED_TILE = 11,
// The user has moved to another pane within the NTP.
SUGGESTED_SITES_ACTION_CLICKED_OTHER_NTP_PANE,
// Any action other than what is listed here (e.g. closing the tab, etc.).
SUGGESTED_SITES_ACTION_OTHER,
// The number of suggested sites actions that we log.
NUM_SUGGESTED_SITES_ACTIONS
};
} // namespace
SuggestionsHandler::SuggestionsHandler()
: got_first_suggestions_request_(false) {
: got_first_suggestions_request_(false),
suggestions_viewed_(false),
user_action_logged_(false) {
}
SuggestionsHandler::~SuggestionsHandler() {
// TODO(macourteau): ensure that |suggestions_viewed_| gets set correctly,
// once the Suggestions pane gets statically included into the NTP (e.g.,
// if the Suggestions pane is the one shown by default, the
// |suggestions_viewed_| flag might not get set).
if (!user_action_logged_ && suggestions_viewed_) {
const GURL ntp_url = GURL(chrome::kChromeUINewTabURL);
int action_id = SUGGESTED_SITES_ACTION_OTHER;
content::NavigationEntry* entry =
web_ui()->GetWebContents()->GetController().GetActiveEntry();
if (entry && (entry->GetURL() != ntp_url)) {
action_id =
content::PageTransitionStripQualifier(entry->GetTransitionType());
}
UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id,
NUM_SUGGESTED_SITES_ACTIONS);
}
}
void SuggestionsHandler::RegisterMessages() {
......@@ -81,6 +126,12 @@ void SuggestionsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist",
base::Bind(&SuggestionsHandler::HandleClearBlacklist,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("suggestedSitesAction",
base::Bind(&SuggestionsHandler::HandleSuggestedSitesAction,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("suggestedSitesSelected",
base::Bind(&SuggestionsHandler::HandleSuggestedSitesSelected,
base::Unretained(this)));
}
void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) {
......@@ -135,6 +186,26 @@ void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) {
// TODO(georgey) clear blacklist.
}
void SuggestionsHandler::HandleSuggestedSitesAction(
const base::ListValue* args) {
DCHECK(args);
double action_id;
if (!args->GetDouble(0, &action_id))
NOTREACHED();
UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction",
static_cast<int>(action_id),
NUM_SUGGESTED_SITES_ACTIONS);
suggestions_viewed_ = true;
user_action_logged_ = true;
}
void SuggestionsHandler::HandleSuggestedSitesSelected(
const base::ListValue* args) {
suggestions_viewed_ = true;
}
void SuggestionsHandler::SetPagesValueFromTopSites(
const history::MostVisitedURLList& data) {
pages_value_.reset(new ListValue());
......
......@@ -33,7 +33,6 @@ class Value;
class SuggestionsHandler : public content::WebUIMessageHandler,
public content::NotificationObserver {
public:
SuggestionsHandler();
virtual ~SuggestionsHandler();
......@@ -52,6 +51,12 @@ class SuggestionsHandler : public content::WebUIMessageHandler,
// Callback for the "clearSuggestionsURLsBlacklist" message.
void HandleClearBlacklist(const base::ListValue* args);
// Callback for the "suggestedSitesAction" message.
void HandleSuggestedSitesAction(const base::ListValue* args);
// Callback for the "suggestedSitesSelected" message.
void HandleSuggestedSitesSelected(const base::ListValue* args);
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
......@@ -95,6 +100,12 @@ class SuggestionsHandler : public content::WebUIMessageHandler,
// Keep the results of the db query here.
scoped_ptr<base::ListValue> pages_value_;
// Whether the user has viewed the 'suggested' pane.
bool suggestions_viewed_;
// Whether the user has performed a "tracked" action to leave the page or not.
bool user_action_logged_;
DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler);
};
......
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