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

Unified Diff: chrome/browser/resources/google_now/background.js

Issue 211663004: Cards Clicked Metrics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use the new sparse histogram support. Created 6 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/google_now/background.js
diff --git a/chrome/browser/resources/google_now/background.js b/chrome/browser/resources/google_now/background.js
index 8be55592d81acab781bf4b24305191f2c1ca7b2b..f5ddd231a23841d2dc04dd9352a5d9f89b10c446 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -251,6 +251,29 @@ function recordEvent(event) {
}
/**
+ * Records a notification clicked event.
+ * @param {number|undefined} cardTypeId Card type ID.
+ */
+function recordNotificationClick(cardTypeId) {
+ if (cardTypeId !== undefined) {
+ chrome.metricsPrivate.recordSparseValue(
+ 'GoogleNow.Card.Clicked', cardTypeId);
+ }
+}
+
+/**
+ * Records a button clicked event.
+ * @param {number|undefined} cardTypeId Card type ID.
+ * @param {number} buttonIndex Button Index
+ */
+function recordButtonClick(cardTypeId, buttonIndex) {
+ if (cardTypeId !== undefined) {
+ chrome.metricsPrivate.recordSparseValue(
+ 'GoogleNow.Card.Button.Clicked' + buttonIndex, cardTypeId);
+ }
+}
+
+/**
* Checks the result of the HTTP Request and updates the authentication
* manager on any failure.
* @param {string} token Authentication token to validate against an
@@ -803,9 +826,9 @@ function openUrl(url) {
* Opens URL corresponding to the clicked part of the notification.
* @param {ChromeNotificationId} chromeNotificationId chrome.notifications ID of
* the card.
- * @param {function((ActionUrls|undefined)): (string|undefined)} selector
- * Function that extracts the url for the clicked area from the button
- * action URLs info.
+ * @param {function(NotificationDataEntry): (string|undefined)} selector
+ * Function that extracts the url for the clicked area from the
+ * notification data entry.
*/
function onNotificationClicked(chromeNotificationId, selector) {
fillFromChromeLocalStorage({
@@ -813,11 +836,11 @@ function onNotificationClicked(chromeNotificationId, selector) {
notificationsData: {}
}).then(function(items) {
/** @type {(NotificationDataEntry|undefined)} */
- var notificationData = items.notificationsData[chromeNotificationId];
- if (!notificationData)
+ var notificationDataEntry = items.notificationsData[chromeNotificationId];
+ if (!notificationDataEntry)
return;
- var url = selector(notificationData.actionUrls);
+ var url = selector(notificationDataEntry);
if (!url)
return;
@@ -1110,21 +1133,33 @@ authenticationManager.addListener(function() {
instrumented.notifications.onClicked.addListener(
function(chromeNotificationId) {
chrome.metricsPrivate.recordUserAction('GoogleNow.MessageClicked');
- onNotificationClicked(chromeNotificationId, function(actionUrls) {
- return actionUrls && actionUrls.messageUrl;
- });
- });
+ onNotificationClicked(chromeNotificationId,
+ function(notificationDataEntry) {
+ var actionUrls = notificationDataEntry.actionUrls;
+ var url = actionUrls && actionUrls.messageUrl;
+ if (url) {
+ recordNotificationClick(notificationDataEntry.cardTypeId);
+ }
+ return url;
+ });
+ });
instrumented.notifications.onButtonClicked.addListener(
function(chromeNotificationId, buttonIndex) {
chrome.metricsPrivate.recordUserAction(
'GoogleNow.ButtonClicked' + buttonIndex);
- onNotificationClicked(chromeNotificationId, function(actionUrls) {
- var url = actionUrls.buttonUrls[buttonIndex];
- verify(url !== undefined, 'onButtonClicked: no url for a button');
- return url;
- });
- });
+ onNotificationClicked(chromeNotificationId,
+ function(notificationDataEntry) {
+ var actionUrls = notificationDataEntry.actionUrls;
+ var url = actionUrls.buttonUrls[buttonIndex];
+ if (url) {
+ recordButtonClick(notificationDataEntry.cardTypeId, buttonIndex);
+ } else {
+ verify(false, 'onButtonClicked: no url for a button');
+ }
+ return url;
+ });
+ });
instrumented.notifications.onClosed.addListener(onNotificationClosed);
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698