Commit e8ce7b91 authored by Yuli Huang's avatar Yuli Huang Committed by Commit Bot

Add capture-event for metrics collection.

1. Add capture-event to collect preferences' metrics for taking pictures.
2. Fix analytics.EventBuilder's dimension() method.

BUG=b:117816926
TEST=Tested by taking pictures and checking GA dashboard.

Change-Id: Ib1bd952d8d02a3742417d78f93265eb36b5cfe49
Reviewed-on: https://chromium-review.googlesource.com/c/1482358Reviewed-by: default avatarSheng-hao Tsao <shenghao@google.com>
Commit-Queue: yuli <yuli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634991}
parent 784bdf12
...@@ -129,14 +129,15 @@ cca.App.prototype.setupToggles_ = function() { ...@@ -129,14 +129,15 @@ cca.App.prototype.setupToggles_ = function() {
* Starts the app by loading the model and opening the camera-view. * Starts the app by loading the model and opening the camera-view.
*/ */
cca.App.prototype.start = function() { cca.App.prototype.start = function() {
var ackMigrate = false;
cca.models.FileSystem.initialize(() => { cca.models.FileSystem.initialize(() => {
// Prompt to migrate pictures if needed. // Prompt to migrate pictures if needed.
var message = chrome.i18n.getMessage('migrate_pictures_msg'); var message = chrome.i18n.getMessage('migrate_pictures_msg');
return cca.nav.open('dialog', message, false).then((acked) => { return cca.nav.open('dialog', message, false).then((acked) => {
cca.state.set('migrate-prompted', true);
if (!acked) { if (!acked) {
throw new Error('no-migrate'); throw new Error('no-migrate');
} }
ackMigrate = true;
}); });
}).then((external) => { }).then((external) => {
cca.state.set('ext-fs', external); cca.state.set('ext-fs', external);
...@@ -154,7 +155,7 @@ cca.App.prototype.start = function() { ...@@ -154,7 +155,7 @@ cca.App.prototype.start = function() {
} }
cca.nav.open('warning', 'filesystem-failure'); cca.nav.open('warning', 'filesystem-failure');
}).finally(() => { }).finally(() => {
cca.metrics.log(cca.metrics.Type.LAUNCH); cca.metrics.log(cca.metrics.Type.LAUNCH, ackMigrate);
}); });
}; };
......
...@@ -21,13 +21,27 @@ cca.metrics = cca.metrics || {}; ...@@ -21,13 +21,27 @@ cca.metrics = cca.metrics || {};
*/ */
cca.metrics.base_ = null; cca.metrics.base_ = null;
/**
* @type {analytics}
*/
var analytics = window['analytics'] || {};
/**
* Fixes analytics.EventBuilder's dimension() method.
* @param {number} i
* @param {string} v
* @return {analytics.EventBuilder}
*/
analytics.EventBuilder.prototype.dimen = function(i, v) {
return this.dimension({index: i, value: v});
};
/** /**
* Promise for Google Analytics tracker. * Promise for Google Analytics tracker.
* @type {Promise<analytics.Tracker>} * @type {Promise<analytics.Tracker>}
* @private * @private
*/ */
cca.metrics.ga_ = (function() { cca.metrics.ga_ = (function() {
const analytics = window['analytics'] || {};
const id = 'UA-134822711-2'; // TODO(yuli): Use prod id. const id = 'UA-134822711-2'; // TODO(yuli): Use prod id.
const service = analytics.getService('chrome-camera-app'); const service = analytics.getService('chrome-camera-app');
...@@ -55,7 +69,7 @@ cca.metrics.ga_ = (function() { ...@@ -55,7 +69,7 @@ cca.metrics.ga_ = (function() {
var match = navigator.appVersion.match(/CrOS\s+\S+\s+([\d.]+)/); var match = navigator.appVersion.match(/CrOS\s+\S+\s+([\d.]+)/);
var osVer = match ? match[1] : ''; var osVer = match ? match[1] : '';
cca.metrics.base_ = analytics.EventBuilder.builder() cca.metrics.base_ = analytics.EventBuilder.builder()
.dimension(1, boardName).dimension(2, osVer); .dimen(1, boardName).dimen(2, osVer);
}); });
}; };
...@@ -67,23 +81,39 @@ cca.metrics.ga_ = (function() { ...@@ -67,23 +81,39 @@ cca.metrics.ga_ = (function() {
})(); })();
/** /**
* Tries to fetch the given states and returns the first existing state. * Returns event builder for the metrics type: launch.
* @param {Array<string>} states States to be fetched. * @param {boolean} ackMigrate Whether acknowledged to migrate during launch.
* @return {string} The first existing state among the given states. * @return {analytics.EventBuilder}
* @private * @private
*/ */
cca.metrics.state_ = function(states) { cca.metrics.launchType_ = function(ackMigrate) {
return states.find((state) => cca.state.get(state)) || ''; return cca.metrics.base_.category('launch').action('start')
.label(ackMigrate ? 'ack-migrate' : '');
}; };
/** /**
* Returns event builder for the metrics type: launch. * Returns event builder for the metrics type: capture.
* @param {number=} time Time in minutes for capture-video.
* @return {analytics.EventBuilder} * @return {analytics.EventBuilder}
* @private * @private
*/ */
cca.metrics.launchType_ = function() { cca.metrics.captureType_ = function(time) {
return cca.metrics.base_.category('launch').action('launch-app') var condState = (states, cond) => {
.label(cca.metrics.state_(['migrate-prompted'])); // Return the first existing state among the given states only if there is
// no gate condition or the condition is met.
const prerequisite = !cond || cca.state.get(cond);
return prerequisite && states.find((state) => cca.state.get(state)) || '';
};
return cca.metrics.base_.category('capture')
.action(cca.state.get('record-mode') ? 'capture-video' : 'capture-photo')
.label('') // TODO(yuli): Add camera facing-mode.
.dimen(3, condState(['sound']))
.dimen(4, condState(['mirror']))
.dimen(5, condState(['_3x3', '_4x4', 'golden'], 'grid'))
.dimen(6, condState(['_3sec', '_10sec'], 'timer'))
.dimen(7, condState(['mic'], 'record-mode'))
.value(time || 0);
}; };
/** /**
...@@ -92,6 +122,7 @@ cca.metrics.launchType_ = function() { ...@@ -92,6 +122,7 @@ cca.metrics.launchType_ = function() {
*/ */
cca.metrics.Type = { cca.metrics.Type = {
LAUNCH: cca.metrics.launchType_, LAUNCH: cca.metrics.launchType_,
CAPTURE: cca.metrics.captureType_,
}; };
/** /**
......
...@@ -269,6 +269,7 @@ cca.views.Camera.prototype.endTake_ = function() { ...@@ -269,6 +269,7 @@ cca.views.Camera.prototype.endTake_ = function() {
return Promise.resolve(this.take_).then((blob) => { return Promise.resolve(this.take_).then((blob) => {
if (blob && !blob.handled) { if (blob && !blob.handled) {
// Play a sound and save the result after a successful take. // Play a sound and save the result after a successful take.
cca.metrics.log(cca.metrics.Type.CAPTURE);
blob.handled = true; blob.handled = true;
var recordMode = this.recordMode; var recordMode = this.recordMode;
cca.sound.play(recordMode ? '#sound-rec-end' : '#sound-shutter'); cca.sound.play(recordMode ? '#sound-rec-end' : '#sound-shutter');
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<script src="../js/nav.js"></script> <script src="../js/nav.js"></script>
<script src="../js/main.js"></script> <script src="../js/main.js"></script>
</head> </head>
<body class="mirror mic _3x3"> <body class="sound mirror mic _3x3">
<div id="camera"> <div id="camera">
<div id="preview-wrapper" aria-hidden="true"> <div id="preview-wrapper" aria-hidden="true">
<video id="preview-video"></video> <video id="preview-video"></video>
......
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