mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 02:36:32 +00:00
Integrate Mixpanel
This commit is contained in:
parent
fb0ec6d322
commit
1c6675ab4f
@ -15,6 +15,7 @@
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"polymer": "Polymer/polymer#^1.1.0"
|
||||
"polymer": "Polymer/polymer#^1.1.0",
|
||||
"angular-mixpanel": "~1.1.2"
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ require('./browser/modules/selection-state');
|
||||
require('./browser/modules/drive-scanner');
|
||||
require('./browser/modules/image-writer');
|
||||
require('./browser/modules/path');
|
||||
require('./browser/modules/analytics');
|
||||
|
||||
const app = angular.module('Etcher', [
|
||||
'ui.bootstrap',
|
||||
@ -43,17 +44,18 @@ const app = angular.module('Etcher', [
|
||||
'Etcher.path',
|
||||
'Etcher.selection-state',
|
||||
'Etcher.drive-scanner',
|
||||
'Etcher.image-writer'
|
||||
'Etcher.image-writer',
|
||||
'Etcher.analytics'
|
||||
]);
|
||||
|
||||
app.controller('AppController', function($q, $log, DriveScannerService, SelectionStateService, ImageWriterService) {
|
||||
app.controller('AppController', function($q, $log, DriveScannerService, SelectionStateService, ImageWriterService, AnalyticsService) {
|
||||
let self = this;
|
||||
this.selection = SelectionStateService;
|
||||
this.writer = ImageWriterService;
|
||||
this.scanner = DriveScannerService;
|
||||
|
||||
this.restart = function(options) {
|
||||
$log.debug('Restarting');
|
||||
AnalyticsService.log('Restarting');
|
||||
this.selection.clear(options);
|
||||
|
||||
self.state = {
|
||||
@ -75,7 +77,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
// `angular.equals` is used instead of `_.isEqual` to
|
||||
// cope with `$$hashKey`.
|
||||
if (!angular.equals(self.selection.getDrive(), drive)) {
|
||||
$log.debug(`Autoselecting drive: ${drive.device}`);
|
||||
AnalyticsService.log(`Autoselecting drive: ${drive.device}`);
|
||||
self.selectDrive(drive);
|
||||
}
|
||||
|
||||
@ -99,13 +101,13 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
this.selectImage = function() {
|
||||
return $q.when(dialog.selectImage()).then(function(image) {
|
||||
self.selection.setImage(image);
|
||||
$log.debug(`Image selected: ${image}`);
|
||||
AnalyticsService.log(`Image selected: ${image}`);
|
||||
});
|
||||
};
|
||||
|
||||
this.selectDrive = function(drive) {
|
||||
self.selection.setDrive(drive);
|
||||
$log.debug(`Drive selected: ${drive.device}`);
|
||||
AnalyticsService.log(`Drive selected: ${drive.device}`);
|
||||
};
|
||||
|
||||
this.reselectImage = function() {
|
||||
@ -119,7 +121,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
// "returns" to the first step.
|
||||
self.selection.clear();
|
||||
|
||||
$log.debug('Reselecting image');
|
||||
AnalyticsService.log('Reselecting image');
|
||||
};
|
||||
|
||||
this.reselectDrive = function() {
|
||||
@ -128,7 +130,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
}
|
||||
|
||||
self.selection.removeDrive();
|
||||
$log.debug('Reselecting drive');
|
||||
AnalyticsService.log('Reselecting drive');
|
||||
};
|
||||
|
||||
this.burn = function(image, drive) {
|
||||
@ -137,7 +139,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
// otherwise Windows throws EPERM
|
||||
self.scanner.stop();
|
||||
|
||||
$log.debug(`Burning ${image} to ${drive.device}`);
|
||||
AnalyticsService.log(`Burning ${image} to ${drive.device}`);
|
||||
return self.writer.burn(image, drive, function(state) {
|
||||
self.state = state;
|
||||
$log.debug(`Progress: ${self.state.progress}% at ${self.state.speed} MB/s`);
|
||||
@ -146,7 +148,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
currentWindow.setProgressBar(self.state.progress / 100);
|
||||
|
||||
}).then(function() {
|
||||
$log.debug('Done!');
|
||||
AnalyticsService.log('Done!');
|
||||
}).catch(dialog.showError).finally(function() {
|
||||
|
||||
// Remove progress bar from task bar
|
||||
|
65
lib/browser/modules/analytics.js
Normal file
65
lib/browser/modules/analytics.js
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2016 Resin.io
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module Etcher.analytics
|
||||
*/
|
||||
|
||||
const angular = require('angular');
|
||||
const username = require('username');
|
||||
const app = require('electron').remote.app;
|
||||
|
||||
// Force Mixpanel snippet to load Mixpanel locally
|
||||
// instead of using a CDN for performance reasons
|
||||
window.MIXPANEL_CUSTOM_LIB_URL = '../bower_components/mixpanel/mixpanel.js';
|
||||
|
||||
require('../../../bower_components/mixpanel/mixpanel-jslib-snippet.js');
|
||||
require('../../../bower_components/angular-mixpanel/src/angular-mixpanel');
|
||||
const analytics = angular.module('Etcher.analytics', [
|
||||
'analytics.mixpanel'
|
||||
]);
|
||||
|
||||
analytics.config(function($mixpanelProvider) {
|
||||
$mixpanelProvider.apiKey('63e5fc4563e00928da67d1226364dd4c');
|
||||
|
||||
$mixpanelProvider.superProperties({
|
||||
distinct_id: username.sync(),
|
||||
version: app.getVersion(),
|
||||
node: process.version,
|
||||
arch: process.arch
|
||||
});
|
||||
});
|
||||
|
||||
analytics.service('AnalyticsService', function($log, $mixpanel) {
|
||||
|
||||
/**
|
||||
* @summary Log an event
|
||||
* @function
|
||||
* @private
|
||||
*
|
||||
* @param {String} message - message
|
||||
*
|
||||
* @example
|
||||
* AnalyticsService.log('Hello World');
|
||||
*/
|
||||
this.log = function(message) {
|
||||
$mixpanel.track(message);
|
||||
$log.debug(message);
|
||||
};
|
||||
|
||||
});
|
@ -52,7 +52,8 @@
|
||||
"resin-image-write": "^2.0.5",
|
||||
"sudo-prompt": "^2.2.0",
|
||||
"trackjs": "^2.1.16",
|
||||
"umount": "^1.1.1"
|
||||
"umount": "^1.1.1",
|
||||
"username": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"angular-mocks": "^1.4.7",
|
||||
|
Loading…
x
Reference in New Issue
Block a user