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

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: Increase Total 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
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..6d959f3170d77ad39bb4fc438349d70c1128020a 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -234,6 +234,9 @@ var GoogleNowEvent = {
// added before it.
};
+// CARD_TYPES_TOTAL is the maximum histogram value and card type value.
+var CARD_TYPES_TOTAL = 300;
Ilya Sherman 2014/03/26 00:32:50 Hmm, can you use a sparse histogram rather than al
robliao 2014/03/26 00:42:53 Got docs on how to do this? I only see histogram-l
Ilya Sherman 2014/03/26 03:55:41 You might need to expand the metricsPrivate API to
robliao 2014/03/27 00:51:51 Done. https://codereview.chromium.org/213433003/ O
+
/**
* Records a Google Now Event.
* @param {GoogleNowEvent} event Event identifier.
@@ -251,6 +254,41 @@ function recordEvent(event) {
}
/**
+ * Records a notification clicked event.
+ * @param {number|undefined} cardTypeId Card type ID.
+ */
+function recordNotificationClick(cardTypeId) {
+ if (cardTypeId !== undefined) {
+ var metricDescription = {
+ metricName: 'GoogleNow.Card.Clicked',
+ type: 'histogram-linear',
+ min: 1,
+ max: CARD_TYPES_TOTAL,
+ buckets: CARD_TYPES_TOTAL + 1
+ };
+ chrome.metricsPrivate.recordValue(metricDescription, 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) {
+ var metricDescription = {
+ metricName: 'GoogleNow.Card.Button.Clicked' + buttonIndex,
+ type: 'histogram-linear',
+ min: 1,
+ max: CARD_TYPES_TOTAL,
+ buckets: CARD_TYPES_TOTAL + 1
+ };
+ chrome.metricsPrivate.recordValue(metricDescription, 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 +841,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 +851,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 +1148,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);

Powered by Google App Engine
This is Rietveld 408576698