mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 12:55:14 +03:00
Added Google analytics collection.
This commit is contained in:
parent
5b0a6349a7
commit
8d5d81f9cf
10 changed files with 277 additions and 4 deletions
|
@ -1,19 +1,60 @@
|
|||
'use strict';
|
||||
|
||||
var analytics;
|
||||
|
||||
openNewWindowsInExternalBrowser();
|
||||
|
||||
//Asynchronous configuration to be done.
|
||||
//When finish the startProcess() function must be called
|
||||
$(document).ready(function () {
|
||||
i18n.init(function() {
|
||||
startProcess();
|
||||
setupAnalytics();
|
||||
initializeSerialBackend();
|
||||
});
|
||||
});
|
||||
|
||||
function setupAnalytics() {
|
||||
analytics = new Analytics('com.betaflight.configurator', 'UA-123002063-1', GUI.operating_system);
|
||||
chrome.storage.local.get('userId', function (result) {
|
||||
var userId;
|
||||
if (result.userId) {
|
||||
userId = result.userId;
|
||||
} else {
|
||||
var uid = new ShortUniqueId();
|
||||
userId = uid.randomUUID(13);
|
||||
|
||||
chrome.storage.local.set({'userId': userId});
|
||||
}
|
||||
|
||||
analytics.tracker.set('userId', userId);
|
||||
|
||||
analytics.tracker.set('sessionControl', 'start');
|
||||
analytics.send(analytics.APPLICATION_EVENT.action('AppStart'))
|
||||
|
||||
function sendCloseEvent() {
|
||||
analytics.send(analytics.APPLICATION_EVENT.action('AppClose'))
|
||||
analytics.tracker.set('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);
|
||||
}
|
||||
|
||||
startProcess();
|
||||
});
|
||||
}
|
||||
|
||||
//Process to execute to real start the app
|
||||
function startProcess() {
|
||||
|
||||
// translate to user-selected language
|
||||
i18n.localizePage();
|
||||
|
||||
|
@ -113,6 +154,8 @@ function startProcess() {
|
|||
GUI.tab_switch_in_progress = false;
|
||||
}
|
||||
|
||||
analytics.sendAppView(tab);
|
||||
|
||||
switch (tab) {
|
||||
case 'landing':
|
||||
TABS.landing.initialize(content_ready);
|
||||
|
@ -249,6 +292,28 @@ function startProcess() {
|
|||
$('div.checkForConfiguratorUnstableVersions').hide();
|
||||
}
|
||||
|
||||
chrome.storage.local.get('analyticsOptOut', function (result) {
|
||||
if (result.analyticsOptOut) {
|
||||
$('div.analyticsOptOut input').prop('checked', true);
|
||||
}
|
||||
|
||||
$('div.analyticsOptOut input').change(function () {
|
||||
var checked = $(this).is(':checked');
|
||||
|
||||
chrome.storage.local.set({'analyticsOptOut': checked});
|
||||
|
||||
if (checked) {
|
||||
analytics.send(analytics.APPLICATION_EVENT.action('OptOut'));
|
||||
}
|
||||
|
||||
analytics.setTrackingPermitted(!checked);
|
||||
|
||||
if (!checked) {
|
||||
analytics.send(analytics.APPLICATION_EVENT.action('OptIn'));
|
||||
}
|
||||
}).change();
|
||||
});
|
||||
|
||||
chrome.storage.local.get('userLanguageSelect', function (result) {
|
||||
|
||||
var userLanguage_e = $('div.userLanguage select');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue