diff options
author | rltoscano@google.com <rltoscano@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-03 20:06:17 +0000 |
---|---|---|
committer | rltoscano@google.com <rltoscano@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-03 20:06:17 +0000 |
commit | 8d0072997388eadb6cc600a8f749dc6264795ba8 (patch) | |
tree | fd407cb1443d28824007cd6048d6ebd276cf1492 /chrome/browser/resources/print_preview | |
parent | 8484c8fff2f32aad13a16af54e7f3864b6fc21ff (diff) | |
download | chromium_src-8d0072997388eadb6cc600a8f749dc6264795ba8.zip chromium_src-8d0072997388eadb6cc600a8f749dc6264795ba8.tar.gz chromium_src-8d0072997388eadb6cc600a8f749dc6264795ba8.tar.bz2 |
Implements metrics for destination search.
BUG=128275
TEST=
Review URL: https://chromiumcodereview.appspot.com/10480002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/print_preview')
4 files changed, 92 insertions, 3 deletions
diff --git a/chrome/browser/resources/print_preview/metrics.js b/chrome/browser/resources/print_preview/metrics.js new file mode 100644 index 0000000..bdeaf14 --- /dev/null +++ b/chrome/browser/resources/print_preview/metrics.js @@ -0,0 +1,46 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +cr.define('print_preview', function() { + 'use strict'; + + /** + * Object used to measure usage statistics. + * @constructor + */ + function Metrics() {}; + + /** + * Enumeration of metrics buckets to record. + * @enum {number} + */ + Metrics.Bucket = { + // Used when the print destination search widget is shown. + DESTINATION_SEARCH_SHOWN: 0, + // Used when the user selects a print destination. + DESTINATION_SELECTED: 1, + // Used when the print destination search widget is closed without selecting + // a print destination. + DESTINATION_SELECTION_CANCELED: 2, + // Used when the Google Cloud Print promotions is shown to the user. + CLOUDPRINT_PROMO_SHOWN: 3, + // Used when the user chooses to sign-in to their Google account. + SIGNIN_TRIGGERED: 4 + }; + + Metrics.prototype = { + /** + * Increments the counter for a given bucket. + * @param {!print_preview.Metrics.Bucket} bucket Bucket to increment. + */ + increment: function(bucket) { + chrome.send('reportDestinationEvent', bucket); + } + }; + + // Export + return { + Metrics: Metrics + }; +}); diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js index 1fa15a3..3635062 100644 --- a/chrome/browser/resources/print_preview/print_preview.js +++ b/chrome/browser/resources/print_preview/print_preview.js @@ -34,6 +34,13 @@ cr.define('print_preview', function() { this.userInfo_ = new print_preview.UserInfo(); /** + * Metrics object used to report usage statistics. + * @type {!print_preview.Metrics} + * @private + */ + this.metrics_ = new print_preview.Metrics(); + + /** * Data store which holds print destinations. * @type {!print_preview.DestinationStore} * @private @@ -64,7 +71,7 @@ cr.define('print_preview', function() { * @private */ this.destinationSearch_ = new print_preview.DestinationSearch( - this.destinationStore_, this.userInfo_); + this.destinationStore_, this.userInfo_, this.metrics_); this.addChild(this.destinationSearch_); /** @@ -611,6 +618,8 @@ cr.define('print_preview', function() { !e.metaKey) { if (this.destinationSearch_.getIsVisible()) { this.destinationSearch_.setIsVisible(false); + this.metrics_.increment( + print_preview.Metrics.Bucket.DESTINATION_SELECTION_CANCELED); } else { this.close_(); } @@ -650,6 +659,8 @@ cr.define('print_preview', function() { onDestinationChangeButtonActivate_: function() { this.destinationSearch_.setIsVisible(true); this.destinationStore_.startLoadAllCloudDestinations(); + this.metrics_.increment( + print_preview.Metrics.Bucket.DESTINATION_SEARCH_SHOWN); }, /** @@ -731,6 +742,7 @@ cr.define('print_preview', function() { <include src="cloud_print_interface.js"/> <include src="print_preview_utils.js"/> <include src="print_header.js"/> +<include src="metrics.js"/> <include src="settings/page_settings.js"/> <include src="settings/copies_settings.js"/> diff --git a/chrome/browser/resources/print_preview/print_preview_utils.js b/chrome/browser/resources/print_preview/print_preview_utils.js index 14eec32..a7b6a74 100644 --- a/chrome/browser/resources/print_preview/print_preview_utils.js +++ b/chrome/browser/resources/print_preview/print_preview_utils.js @@ -187,8 +187,16 @@ function pageSetToPageRanges(pageSet) { } /** + * @param {!HTMLElement} element Element to check for visibility. + * @return {boolean} Whether the given element is visible. + */ +function getIsVisible(element) { + return !element.hidden; +} + +/** * Shows or hides an element. - * @param {Element} element Element to show or hide. + * @param {!HTMLElement} element Element to show or hide. * @param {boolean} isVisible Whether the element should be visible or not. */ function setIsVisible(element, isVisible) { diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js index 05c2cee..332e9b11 100644 --- a/chrome/browser/resources/print_preview/search/destination_search.js +++ b/chrome/browser/resources/print_preview/search/destination_search.js @@ -14,10 +14,11 @@ cr.define('print_preview', function() { * containing the destinations to search through. * @param {!print_preview.UserInfo} userInfo Event target that contains * information about the logged in user. + * @param {!print_preview.Metrics} metrics Used to record usage statistics. * @constructor * @extends {print_preview.Component} */ - function DestinationSearch(destinationStore, userInfo) { + function DestinationSearch(destinationStore, userInfo, metrics) { print_preview.Component.call(this); /** @@ -35,6 +36,13 @@ cr.define('print_preview', function() { this.userInfo_ = userInfo; /** + * Used to record usage statistics. + * @type {!print_preview.Metrics} + * @private + */ + this.metrics_ = metrics; + + /** * Search box used to search through the destination lists. * @type {!print_preview.SearchBox} * @private @@ -136,6 +144,12 @@ cr.define('print_preview', function() { this.searchBox_.focus(); this.getElement().classList.remove( DestinationSearch.Classes_.TRANSPARENT); + var promoEl = this.getElement().getElementsByClassName( + DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; + if (getIsVisible(promoEl)) { + this.metrics_.increment( + print_preview.Metrics.Bucket.CLOUDPRINT_PROMO_SHOWN); + } } else { this.getElement().classList.add(DestinationSearch.Classes_.TRANSPARENT); // Collapse all destination lists @@ -167,6 +181,10 @@ cr.define('print_preview', function() { var promoEl = this.getElement().getElementsByClassName( DestinationSearch.Classes_.CLOUDPRINT_PROMO)[0]; setIsVisible(promoEl, true); + if (this.getIsVisible()) { + this.metrics_.increment( + print_preview.Metrics.Bucket.CLOUDPRINT_PROMO_SHOWN); + } }, /** @override */ @@ -301,6 +319,8 @@ cr.define('print_preview', function() { onCloseClick_: function() { this.setIsVisible(false); this.resetSearch_(); + this.metrics_.increment( + print_preview.Metrics.Bucket.DESTINATION_SELECTION_CANCELED); }, /** @@ -313,6 +333,8 @@ cr.define('print_preview', function() { this.setIsVisible(false); this.resetSearch_(); this.destinationStore_.selectDestination(evt.destination); + this.metrics_.increment( + print_preview.Metrics.Bucket.DESTINATION_SELECTED); }, /** @@ -382,6 +404,7 @@ cr.define('print_preview', function() { */ onSignInActivated_: function() { cr.dispatchSimpleEvent(this, DestinationSearch.EventType.SIGN_IN); + this.metrics_.increment(print_preview.Metrics.Bucket.SIGNIN_TRIGGERED); }, /** |