1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 16:55:24 +03:00

Made initialisation lazy, added tracking for expert mode.

This commit is contained in:
mikeller 2018-08-09 01:08:17 +12:00
parent ff30958d73
commit 237dc08ca6
2 changed files with 78 additions and 59 deletions

View file

@ -5,7 +5,7 @@ var Analytics = function (trackingId, userId, appName, appVersion, buildType, op
this.setOptOut(optOut); this.setOptOut(optOut);
this._analytics = analytics; this._analytics = googleAnalytics;
this._analytics.initialize(this._trackingId, { this._analytics.initialize(this._trackingId, {
storage: 'none', storage: 'none',
@ -42,7 +42,7 @@ var Analytics = function (trackingId, userId, appName, appVersion, buildType, op
}; };
this.DIMENSIONS = { this.DIMENSIONS = {
BUILD_TYPE: 1, CONFIGURATOR_BUILD_TYPE: 1,
BOARD_TYPE: 2, BOARD_TYPE: 2,
FIRMWARE_TYPE: 3, FIRMWARE_TYPE: 3,
FIRMWARE_VERSION: 4, FIRMWARE_VERSION: 4,
@ -50,9 +50,10 @@ var Analytics = function (trackingId, userId, appName, appVersion, buildType, op
FIRMWARE_NAME: 6, FIRMWARE_NAME: 6,
FIRMWARE_CHANNEL: 7, FIRMWARE_CHANNEL: 7,
FIRMWARE_ERASE_ALL: 8, FIRMWARE_ERASE_ALL: 8,
CONFIGURATOR_EXPERT_MODE: 9,
}; };
this.setDimension(this.DIMENSIONS.BUILD_TYPE, buildType); this.setDimension(this.DIMENSIONS.CONFIGURATOR_BUILD_TYPE, buildType);
this.resetFlightControllerData(); this.resetFlightControllerData();
this.resetFirmwareData(); this.resetFirmwareData();

View file

@ -1,61 +1,74 @@
'use strict'; 'use strict';
var analytics; var googleAnalytics = analytics;
var analytics = undefined;
openNewWindowsInExternalBrowser(); openNewWindowsInExternalBrowser();
$(document).ready(function () { $(document).ready(function () {
i18n.init(function() { i18n.init(function() {
setupAnalytics(); startProcess();
initializeSerialBackend(); initializeSerialBackend();
}); });
}); });
function setupAnalytics() { function checkSetupAnalytics(callback) {
chrome.storage.local.get(['userId', 'analyticsOptOut'], function (result) { if (!analytics) {
var userId; setTimeout(function () {
if (result.userId) { chrome.storage.local.get(['userId', 'analyticsOptOut'], function (result) {
userId = result.userId; if (!analytics) {
} else { setupAnalytics(result);
var uid = new ShortUniqueId(); }
userId = uid.randomUUID(13);
chrome.storage.local.set({ 'userId': userId }); callback(analytics);
}
var optOut = !!result.analyticsOptOut;
var debugMode = process.versions['nw-flavor'] === 'sdk';
analytics = new Analytics('UA-123002063-1', userId, 'Betaflight Configurator', getManifestVersion(), GUI.operating_system, optOut, debugMode);
function logException(exception) {
analytics.sendException(exception.stack);
}
process.on('uncaughtException', logException);
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppStart', { sessionControl: 'start' });
function sendCloseEvent() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' })
}
try {
var gui = require('nw.gui');
var win = gui.Window.get();
win.on('close', function () {
sendCloseEvent();
this.close(true);
}); });
} catch (ex) { });
// Looks like we're in Chrome - but the event does not actually get fired } else if (callback) {
chrome.runtime.onSuspend.addListener(sendCloseEvent); callback(analytics);
} }
};
startProcess(); function setupAnalytics(result) {
}); var userId;
if (result.userId) {
userId = result.userId;
} else {
var uid = new ShortUniqueId();
userId = uid.randomUUID(13);
chrome.storage.local.set({ 'userId': userId });
}
var optOut = !!result.analyticsOptOut;
var debugMode = process.versions['nw-flavor'] === 'sdk';
analytics = new Analytics('UA-123002063-1', userId, 'Betaflight Configurator', getManifestVersion(), GUI.operating_system, optOut, debugMode);
function logException(exception) {
analytics.sendException(exception.stack);
}
process.on('uncaughtException', logException);
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppStart', { sessionControl: 'start' });
function sendCloseEvent() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' })
}
try {
var gui = require('nw.gui');
var win = gui.Window.get();
win.on('close', function () {
sendCloseEvent();
this.close(true);
});
} catch (ex) {
// Looks like we're in Chrome - but the event does not actually get fired
chrome.runtime.onSuspend.addListener(sendCloseEvent);
}
} }
//Process to execute to real start the app //Process to execute to real start the app
@ -159,7 +172,9 @@ function startProcess() {
GUI.tab_switch_in_progress = false; GUI.tab_switch_in_progress = false;
} }
analytics.sendAppView(tab); checkSetupAnalytics(function (analytics) {
analytics.sendAppView(tab);
});
switch (tab) { switch (tab) {
case 'landing': case 'landing':
@ -265,10 +280,6 @@ function startProcess() {
chrome.storage.local.set({'permanentExpertMode': checked}); chrome.storage.local.set({'permanentExpertMode': checked});
$('input[name="expertModeCheckbox"]').prop('checked', checked).change(); $('input[name="expertModeCheckbox"]').prop('checked', checked).change();
if (FEATURE_CONFIG) {
updateTabList(FEATURE_CONFIG.features);
}
}).change(); }).change();
}); });
@ -307,15 +318,17 @@ function startProcess() {
chrome.storage.local.set({'analyticsOptOut': checked}); chrome.storage.local.set({'analyticsOptOut': checked});
if (checked) { checkSetupAnalytics(function (analytics) {
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'OptOut'); if (checked) {
} analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'OptOut');
}
analytics.setOptOut(checked); analytics.setOptOut(checked);
if (!checked) { if (!checked) {
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'OptIn'); analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'OptIn');
} }
});
}).change(); }).change();
}); });
@ -469,6 +482,11 @@ function startProcess() {
} }
$('input[name="expertModeCheckbox"]').change(function () { $('input[name="expertModeCheckbox"]').change(function () {
var checked = $(this).is(':checked');
checkSetupAnalytics(function (analytics) {
analytics.setDimension(analytics.DIMENSIONS.CONFIGURATOR_EXPERT_MODE, checked ? 'On' : 'Off');
});
if (FEATURE_CONFIG) { if (FEATURE_CONFIG) {
updateTabList(FEATURE_CONFIG.features); updateTabList(FEATURE_CONFIG.features);
} }