RF: Moved Analytics to class (#3222)

* RF: Moved Analytics to class

* Modularisation of Google analytics.

* Removing the code smells

* Fix the unit tests

* Simplified

* Removed comment
10.9-maintenance
J Blackman 2023-01-08 05:56:26 +11:00 committed by GitHub
parent 00075939ac
commit fd99e77335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 251 additions and 233 deletions

View File

@ -1,180 +1,186 @@
'use strict';
const Analytics = function (trackingId, userId, appName, appVersion, gitRevision, os, checkForDebugVersions, optOut, debugMode, buildType) {
this._trackingId = trackingId;
let tracking = null;
export { tracking };
this.setOptOut(optOut);
export function createAnalytics(ga, settings) {
tracking = new Analytics(ga, settings);
}
this._googleAnalytics = googleAnalytics;
class Analytics {
this._googleAnalytics.initialize(this._trackingId, {
storage: 'none',
clientId: userId,
debug: !!debugMode,
});
constructor (ga, settings) {
// trackingId, userId, appName, appVersion, gitRevision, os, checkForDebugVersions, optOut, debugMode, buildType
this._trackingId = settings.trackingId;
// Make it work for the Chrome App:
this._googleAnalytics.set('forceSSL', true);
this._googleAnalytics.set('transport', 'xhr');
this.setOptOut(settings.optOut);
// Make it work for NW.js:
this._googleAnalytics.set('checkProtocolTask', null);
this._googleAnalytics = ga;
this._googleAnalytics.set('appName', appName);
this._googleAnalytics.set('appVersion', debugMode ? `${appVersion}-debug` : appVersion);
this._googleAnalytics.initialize(this._trackingId, {
storage: 'none',
clientId: settings.userId,
debug: !!settings.debugMode,
});
this.EVENT_CATEGORIES = {
APPLICATION: 'Application',
FLIGHT_CONTROLLER: 'FlightController',
FLASHING: 'Flashing',
};
// Make it work for the Chrome App:
this._googleAnalytics.set('forceSSL', true);
this._googleAnalytics.set('transport', 'xhr');
this.DATA = {
BOARD_TYPE: 'boardType',
API_VERSION: 'apiVersion',
FIRMWARE_TYPE: 'firmwareType',
FIRMWARE_VERSION: 'firmwareVersion',
FIRMWARE_NAME: 'firmwareName',
FIRMWARE_SOURCE: 'firmwareSource',
FIRMWARE_CHANNEL: 'firmwareChannel',
FIRMWARE_ERASE_ALL: 'firmwareEraseAll',
FIRMWARE_SIZE: 'firmwareSize',
MCU_ID: 'mcuId',
LOGGING_STATUS: 'loggingStatus',
LOG_SIZE: 'logSize',
TARGET_NAME: 'targetName',
BOARD_NAME: 'boardName',
MANUFACTURER_ID: 'manufacturerId',
MCU_TYPE: 'mcuType',
};
// Make it work for NW.js:
this._googleAnalytics.set('checkProtocolTask', null);
this.DIMENSIONS = {
CONFIGURATOR_OS: 1,
BOARD_TYPE: 2,
FIRMWARE_TYPE: 3,
FIRMWARE_VERSION: 4,
API_VERSION: 5,
FIRMWARE_NAME: 6,
FIRMWARE_SOURCE: 7,
FIRMWARE_ERASE_ALL: 8,
CONFIGURATOR_EXPERT_MODE: 9,
FIRMWARE_CHANNEL: 10,
LOGGING_STATUS: 11,
MCU_ID: 12,
CONFIGURATOR_CHANGESET_ID: 13,
CONFIGURATOR_USE_DEBUG_VERSIONS: 14,
TARGET_NAME: 15,
BOARD_NAME: 16,
MANUFACTURER_ID: 17,
MCU_TYPE: 18,
CONFIGURATOR_BUILD_TYPE: 19,
};
this._googleAnalytics.set('appName', settings.appName);
this._googleAnalytics.set('appVersion', settings.debugMode ? `${settings.appVersion}-debug` : settings.appVersion);
this.METRICS = {
FIRMWARE_SIZE: 1,
LOG_SIZE: 2,
};
this.EVENT_CATEGORIES = {
APPLICATION: 'Application',
FLIGHT_CONTROLLER: 'FlightController',
FLASHING: 'Flashing',
};
this.setDimension(this.DIMENSIONS.CONFIGURATOR_OS, os);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_CHANGESET_ID, gitRevision);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_USE_DEBUG_VERSIONS, checkForDebugVersions);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_BUILD_TYPE, buildType);
this.DATA = {
BOARD_TYPE: 'boardType',
API_VERSION: 'apiVersion',
FIRMWARE_TYPE: 'firmwareType',
FIRMWARE_VERSION: 'firmwareVersion',
FIRMWARE_NAME: 'firmwareName',
FIRMWARE_SOURCE: 'firmwareSource',
FIRMWARE_CHANNEL: 'firmwareChannel',
FIRMWARE_ERASE_ALL: 'firmwareEraseAll',
FIRMWARE_SIZE: 'firmwareSize',
MCU_ID: 'mcuId',
LOGGING_STATUS: 'loggingStatus',
LOG_SIZE: 'logSize',
TARGET_NAME: 'targetName',
BOARD_NAME: 'boardName',
MANUFACTURER_ID: 'manufacturerId',
MCU_TYPE: 'mcuType',
};
this.resetFlightControllerData();
this.resetFirmwareData();
};
this.DIMENSIONS = {
CONFIGURATOR_OS: 1,
BOARD_TYPE: 2,
FIRMWARE_TYPE: 3,
FIRMWARE_VERSION: 4,
API_VERSION: 5,
FIRMWARE_NAME: 6,
FIRMWARE_SOURCE: 7,
FIRMWARE_ERASE_ALL: 8,
CONFIGURATOR_EXPERT_MODE: 9,
FIRMWARE_CHANNEL: 10,
LOGGING_STATUS: 11,
MCU_ID: 12,
CONFIGURATOR_CHANGESET_ID: 13,
CONFIGURATOR_USE_DEBUG_VERSIONS: 14,
TARGET_NAME: 15,
BOARD_NAME: 16,
MANUFACTURER_ID: 17,
MCU_TYPE: 18,
CONFIGURATOR_BUILD_TYPE: 19,
};
Analytics.prototype.setDimension = function (dimension, value) {
const dimensionName = `dimension${dimension}`;
this._googleAnalytics.custom(dimensionName, value);
};
this.METRICS = {
FIRMWARE_SIZE: 1,
LOG_SIZE: 2,
};
Analytics.prototype.setMetric = function (metric, value) {
const metricName = `metric${metric}`;
this._googleAnalytics.custom(metricName, value);
};
this.setDimension(this.DIMENSIONS.CONFIGURATOR_OS, settings.os);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_CHANGESET_ID, settings.gitRevision);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_USE_DEBUG_VERSIONS, settings.checkForDebugVersions);
this.setDimension(this.DIMENSIONS.CONFIGURATOR_BUILD_TYPE, settings.buildType);
Analytics.prototype.sendEvent = function (category, action, options) {
this._googleAnalytics.event(category, action, options);
};
this.resetFlightControllerData();
this.resetFirmwareData();
}
Analytics.prototype.sendChangeEvents = function (category, changeList) {
for (const actionName in changeList) {
if (changeList.hasOwnProperty(actionName)) {
const actionValue = changeList[actionName];
if (actionValue !== undefined) {
this.sendEvent(category, actionName, { eventLabel: actionValue });
setDimension(dimension, value) {
const dimensionName = `dimension${dimension}`;
this._googleAnalytics.custom(dimensionName, value);
}
setMetric(metric, value) {
const metricName = `metric${metric}`;
this._googleAnalytics.custom(metricName, value);
}
sendEvent(category, action, options) {
this._googleAnalytics.event(category, action, options);
}
sendChangeEvents(category, changeList) {
for (const actionName in changeList) {
if (changeList.hasOwnProperty(actionName)) {
const actionValue = changeList[actionName];
if (actionValue !== undefined) {
this.sendEvent(category, actionName, { eventLabel: actionValue });
}
}
}
}
};
Analytics.prototype.sendSaveAndChangeEvents = function (category, changeList, tabName) {
this.sendEvent(category, 'Save', {
eventLabel: tabName,
eventValue: Object.keys(changeList).length,
});
this.sendChangeEvents(category, changeList);
};
sendSaveAndChangeEvents(category, changeList, tabName) {
this.sendEvent(category, 'Save', {
eventLabel: tabName,
eventValue: Object.keys(changeList).length,
});
this.sendChangeEvents(category, changeList);
}
Analytics.prototype.sendAppView = function (viewName) {
this._googleAnalytics.screenview(viewName);
};
sendAppView(viewName) {
this._googleAnalytics.screenview(viewName);
}
Analytics.prototype.sendTiming = function (category, timing, value) {
this._googleAnalytics.timing(category, timing, value);
};
sendTiming(category, timing, value) {
this._googleAnalytics.timing(category, timing, value);
}
Analytics.prototype.sendException = function (message) {
this._googleAnalytics.exception(message);
};
sendException(message) {
this._googleAnalytics.exception(message);
}
Analytics.prototype.setOptOut = function (optOut) {
window[`ga-disable-${this._trackingId}`] = !!optOut;
};
setOptOut(optOut) {
window[`ga-disable-${this._trackingId}`] = !!optOut;
}
Analytics.prototype._rebuildFlightControllerEvent = function () {
this.setDimension(this.DIMENSIONS.BOARD_TYPE, this._flightControllerData[this.DATA.BOARD_TYPE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_TYPE, this._flightControllerData[this.DATA.FIRMWARE_TYPE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_VERSION, this._flightControllerData[this.DATA.FIRMWARE_VERSION]);
this.setDimension(this.DIMENSIONS.API_VERSION, this._flightControllerData[this.DATA.API_VERSION]);
this.setDimension(this.DIMENSIONS.LOGGING_STATUS, this._flightControllerData[this.DATA.LOGGING_STATUS]);
this.setDimension(this.DIMENSIONS.MCU_ID, this._flightControllerData[this.DATA.MCU_ID]);
this.setMetric(this.METRICS.LOG_SIZE, this._flightControllerData[this.DATA.LOG_SIZE]);
this.setDimension(this.DIMENSIONS.TARGET_NAME, this._flightControllerData[this.DATA.TARGET_NAME]);
this.setDimension(this.DIMENSIONS.BOARD_NAME, this._flightControllerData[this.DATA.BOARD_NAME]);
this.setDimension(this.DIMENSIONS.MANUFACTURER_ID, this._flightControllerData[this.DATA.MANUFACTURER_ID]);
this.setDimension(this.DIMENSIONS.MCU_TYPE, this._flightControllerData[this.DATA.MCU_TYPE]);
};
_rebuildFlightControllerEvent() {
this.setDimension(this.DIMENSIONS.BOARD_TYPE, this._flightControllerData[this.DATA.BOARD_TYPE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_TYPE, this._flightControllerData[this.DATA.FIRMWARE_TYPE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_VERSION, this._flightControllerData[this.DATA.FIRMWARE_VERSION]);
this.setDimension(this.DIMENSIONS.API_VERSION, this._flightControllerData[this.DATA.API_VERSION]);
this.setDimension(this.DIMENSIONS.LOGGING_STATUS, this._flightControllerData[this.DATA.LOGGING_STATUS]);
this.setDimension(this.DIMENSIONS.MCU_ID, this._flightControllerData[this.DATA.MCU_ID]);
this.setMetric(this.METRICS.LOG_SIZE, this._flightControllerData[this.DATA.LOG_SIZE]);
this.setDimension(this.DIMENSIONS.TARGET_NAME, this._flightControllerData[this.DATA.TARGET_NAME]);
this.setDimension(this.DIMENSIONS.BOARD_NAME, this._flightControllerData[this.DATA.BOARD_NAME]);
this.setDimension(this.DIMENSIONS.MANUFACTURER_ID, this._flightControllerData[this.DATA.MANUFACTURER_ID]);
this.setDimension(this.DIMENSIONS.MCU_TYPE, this._flightControllerData[this.DATA.MCU_TYPE]);
}
Analytics.prototype.setFlightControllerData = function (property, value) {
this._flightControllerData[property] = value;
setFlightControllerData(property, value) {
this._flightControllerData[property] = value;
this._rebuildFlightControllerEvent();
}
this._rebuildFlightControllerEvent();
};
resetFlightControllerData() {
this._flightControllerData = {};
this._rebuildFlightControllerEvent();
}
Analytics.prototype.resetFlightControllerData = function () {
this._flightControllerData = {};
_rebuildFirmwareEvent() {
this.setDimension(this.DIMENSIONS.FIRMWARE_NAME, this._firmwareData[this.DATA.FIRMWARE_NAME]);
this.setDimension(this.DIMENSIONS.FIRMWARE_SOURCE, this._firmwareData[this.DATA.FIRMWARE_SOURCE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_ERASE_ALL, this._firmwareData[this.DATA.FIRMWARE_ERASE_ALL]);
this.setDimension(this.DIMENSIONS.FIRMWARE_CHANNEL, this._firmwareData[this.DATA.FIRMWARE_CHANNEL]);
this.setMetric(this.METRICS.FIRMWARE_SIZE, this._firmwareData[this.DATA.FIRMWARE_SIZE]);
}
this._rebuildFlightControllerEvent();
};
setFirmwareData(property, value) {
this._firmwareData[property] = value;
this._rebuildFirmwareEvent();
}
Analytics.prototype._rebuildFirmwareEvent = function () {
this.setDimension(this.DIMENSIONS.FIRMWARE_NAME, this._firmwareData[this.DATA.FIRMWARE_NAME]);
this.setDimension(this.DIMENSIONS.FIRMWARE_SOURCE, this._firmwareData[this.DATA.FIRMWARE_SOURCE]);
this.setDimension(this.DIMENSIONS.FIRMWARE_ERASE_ALL, this._firmwareData[this.DATA.FIRMWARE_ERASE_ALL]);
this.setDimension(this.DIMENSIONS.FIRMWARE_CHANNEL, this._firmwareData[this.DATA.FIRMWARE_CHANNEL]);
this.setMetric(this.METRICS.FIRMWARE_SIZE, this._firmwareData[this.DATA.FIRMWARE_SIZE]);
};
Analytics.prototype.setFirmwareData = function (property, value) {
this._firmwareData[property] = value;
this._rebuildFirmwareEvent();
};
Analytics.prototype.resetFirmwareData = function () {
this._firmwareData = {};
this._rebuildFirmwareEvent();
};
resetFirmwareData() {
this._firmwareData = {};
this._rebuildFirmwareEvent();
}
}

View File

@ -51,7 +51,7 @@ CliAutoComplete.setEnabled = function(enable) {
};
CliAutoComplete.initialize = function($textarea, sendLine, writeToOutput) {
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'CliAutoComplete', this.configEnabled);
tracking.sendEvent(tracking.EVENT_CATEGORIES.APPLICATION, 'CliAutoComplete', this.configEnabled);
this.$textarea = $textarea;
this.forceOpen = false;

View File

@ -46,7 +46,7 @@ const Features = function (config) {
Features.prototype.getMask = function () {
const self = this;
analytics.sendChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self._analyticsChanges);
tracking.sendChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self._analyticsChanges);
self._analyticsChanges = {};
return self._featureMask;

View File

@ -225,7 +225,7 @@ function configuration_backup(callback) {
return;
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Backup');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Backup');
console.log('Write SUCCESSFUL');
if (callback) callback();
};
@ -308,7 +308,7 @@ function configuration_restore(callback) {
configuration.FEATURE_CONFIG.features = features;
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Restore');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Restore');
configuration_upload(configuration, callback);
} else {

View File

@ -3,6 +3,7 @@ import { i18n } from './localization.js';
import GUI from './gui.js';
import { get as getConfig, set as setConfig } from './ConfigStorage.js';
import ReleaseChecker from './release_checker.js';
import { tracking, createAnalytics } from './Analytics.js';
$(document).ready(function () {
@ -76,17 +77,13 @@ function appReady() {
}
function checkSetupAnalytics(callback) {
if (!analytics) {
setTimeout(function () {
const result = ConfigStorage.get(['userId', 'analyticsOptOut', 'checkForConfiguratorUnstableVersions' ]);
if (!analytics) {
setupAnalytics(result);
}
if (!tracking) {
const result = getConfig(['userId', 'analyticsOptOut', 'checkForConfiguratorUnstableVersions' ]);
setupAnalytics(result);
}
callback(analytics);
});
} else if (callback) {
callback(analytics);
if (callback) {
callback(tracking);
}
}
@ -102,7 +99,7 @@ function setupAnalytics(result) {
const uid = new ShortUniqueId();
userId = uid.randomUUID(13);
ConfigStorage.set({ 'userId': userId });
setConfig({ 'userId': userId });
}
const optOut = !!result.analyticsOptOut;
@ -110,18 +107,30 @@ function setupAnalytics(result) {
const debugMode = typeof process === "object" && process.versions['nw-flavor'] === 'sdk';
window.analytics = new Analytics('UA-123002063-1', userId, CONFIGURATOR.productName, CONFIGURATOR.version, CONFIGURATOR.gitRevision, GUI.operating_system,
checkForDebugVersions, optOut, debugMode, getBuildType());
const settings = {
trackingId: 'UA-123002063-1',
userId: userId,
appName: CONFIGURATOR.productName,
appVersion: CONFIGURATOR.version,
gitRevision: CONFIGURATOR.gitRevision,
os: GUI.operating_system,
checkForDebugVersions: checkForDebugVersions,
optOut: optOut,
debugMode: debugMode,
buildType: getBuildType(),
};
createAnalytics(googleAnalytics, settings);
window.tracking = tracking;
function logException(exception) {
analytics.sendException(exception.stack);
tracking.sendException(exception.stack);
}
if (typeof process === "object") {
process.on('uncaughtException', logException);
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppStart', { sessionControl: 'start' });
tracking.sendEvent(tracking.EVENT_CATEGORIES.APPLICATION, 'AppStart', { sessionControl: 'start' });
$('.connect_b a.connect').removeClass('disabled');
$('.firmware_b a.flash').removeClass('disabled');
@ -187,7 +196,7 @@ function closeHandler() {
this.hide();
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' });
tracking.sendEvent(tracking.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' });
closeSerial();
@ -799,7 +808,7 @@ function showErrorDialog(message) {
// TODO: all of these are used as globals in other parts.
// once moved to modules extract to own module.
window.googleAnalytics = analytics;
window.analytics = null;
window.tracking = null;
window.showErrorDialog = showErrorDialog;
window.generateFilename = generateFilename;
window.updateTabList = updateTabList;

View File

@ -157,15 +157,15 @@ function finishClose(finishedCallback) {
const wasConnected = CONFIGURATOR.connectionValid;
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Disconnected');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Disconnected');
if (connectionTimestamp) {
const connectedTime = Date.now() - connectionTimestamp;
analytics.sendTiming(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Connected', connectedTime);
tracking.sendTiming(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Connected', connectedTime);
}
// close reset to custom defaults dialog
$('#dialogResetToCustomDefaults')[0].close();
analytics.resetFlightControllerData();
tracking.resetFlightControllerData();
serial.disconnect(onClosed);
@ -249,17 +249,17 @@ function onOpen(openInfo) {
console.log(`Requesting configuration data`);
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () {
analytics.setFlightControllerData(analytics.DATA.API_VERSION, FC.CONFIG.apiVersion);
tracking.setFlightControllerData(tracking.DATA.API_VERSION, FC.CONFIG.apiVersion);
GUI.log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion]));
if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_ACCEPTED)) {
MSP.send_message(MSPCodes.MSP_FC_VARIANT, false, false, function () {
analytics.setFlightControllerData(analytics.DATA.FIRMWARE_TYPE, FC.CONFIG.flightControllerIdentifier);
tracking.setFlightControllerData(tracking.DATA.FIRMWARE_TYPE, FC.CONFIG.flightControllerIdentifier);
if (FC.CONFIG.flightControllerIdentifier === 'BTFL') {
MSP.send_message(MSPCodes.MSP_FC_VERSION, false, false, function () {
analytics.setFlightControllerData(analytics.DATA.FIRMWARE_VERSION, FC.CONFIG.flightControllerVersion);
tracking.setFlightControllerData(tracking.DATA.FIRMWARE_VERSION, FC.CONFIG.flightControllerVersion);
GUI.log(i18n.getMessage('fcInfoReceived', [FC.CONFIG.flightControllerIdentifier, FC.CONFIG.flightControllerVersion]));
@ -271,7 +271,7 @@ function onOpen(openInfo) {
});
});
} else {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareType', FC.CONFIG.flightControllerIdentifier);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareType', FC.CONFIG.flightControllerIdentifier);
const dialog = $('.dialogConnectWarning')[0];
@ -287,7 +287,7 @@ function onOpen(openInfo) {
}
});
} else {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareVersion', FC.CONFIG.apiVersion);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareVersion', FC.CONFIG.apiVersion);
const dialog = $('.dialogConnectWarning')[0];
@ -303,7 +303,7 @@ function onOpen(openInfo) {
}
});
} else {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SerialPortFailed');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SerialPortFailed');
console.log('Failed to open serial port');
GUI.log(i18n.getMessage('serialPortOpenFail'));
@ -341,11 +341,11 @@ function abortConnect() {
}
function processBoardInfo() {
analytics.setFlightControllerData(analytics.DATA.BOARD_TYPE, FC.CONFIG.boardIdentifier);
analytics.setFlightControllerData(analytics.DATA.TARGET_NAME, FC.CONFIG.targetName);
analytics.setFlightControllerData(analytics.DATA.BOARD_NAME, FC.CONFIG.boardName);
analytics.setFlightControllerData(analytics.DATA.MANUFACTURER_ID, FC.CONFIG.manufacturerId);
analytics.setFlightControllerData(analytics.DATA.MCU_TYPE, FC.getMcuType());
tracking.setFlightControllerData(tracking.DATA.BOARD_TYPE, FC.CONFIG.boardIdentifier);
tracking.setFlightControllerData(tracking.DATA.TARGET_NAME, FC.CONFIG.targetName);
tracking.setFlightControllerData(tracking.DATA.BOARD_NAME, FC.CONFIG.boardName);
tracking.setFlightControllerData(tracking.DATA.MANUFACTURER_ID, FC.CONFIG.manufacturerId);
tracking.setFlightControllerData(tracking.DATA.MCU_TYPE, FC.getMcuType());
GUI.log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion]));
@ -353,7 +353,7 @@ function processBoardInfo() {
const dialog = $('#dialogResetToCustomDefaults')[0];
$('#dialogResetToCustomDefaults-acceptbtn').click(function() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'AcceptResetToCustomDefaults');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'AcceptResetToCustomDefaults');
const buffer = [];
buffer.push(mspHelper.RESET_TYPES.CUSTOM_DEFAULTS);
@ -367,7 +367,7 @@ function processBoardInfo() {
});
$('#dialogResetToCustomDefaults-cancelbtn').click(function() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CancelResetToCustomDefaults');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CancelResetToCustomDefaults');
dialog.close();
@ -392,7 +392,7 @@ function checkReportProblems() {
if (bit_check(FC.CONFIG.configurationProblems, FC.CONFIGURATION_PROBLEM_FLAGS[problemName])) {
problemItemTemplate.clone().html(i18n.getMessage(`reportProblemsDialog${problemName}`)).appendTo(problemDialogList);
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, PROBLEM_ANALYTICS_EVENT, problemName);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, PROBLEM_ANALYTICS_EVENT, problemName);
return true;
}
@ -411,7 +411,7 @@ function checkReportProblems() {
[CONFIGURATOR.latestVersion, CONFIGURATOR.latestVersionReleaseUrl, CONFIGURATOR.getDisplayVersion(), FC.CONFIG.flightControllerVersion])).appendTo(problemDialogList);
needsProblemReportingDialog = true;
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, PROBLEM_ANALYTICS_EVENT,
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, PROBLEM_ANALYTICS_EVENT,
`${problemName};${CONFIGURATOR.API_VERSION_MAX_SUPPORTED};${FC.CONFIG.apiVersion}`);
}
@ -440,8 +440,8 @@ function processUid() {
MSP.send_message(MSPCodes.MSP_UID, false, false, function () {
const deviceIdentifier = FC.CONFIG.deviceIdentifier;
analytics.setFlightControllerData(analytics.DATA.MCU_ID, objectHash.sha1(deviceIdentifier));
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Connected');
tracking.setFlightControllerData(tracking.DATA.MCU_ID, objectHash.sha1(deviceIdentifier));
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Connected');
connectionTimestamp = Date.now();
GUI.log(i18n.getMessage('uniqueDeviceIdReceived', [deviceIdentifier]));

View File

@ -2,6 +2,7 @@ import { i18n } from "../localization";
import Clipboard from "../Clipboard";
import GUI from '../gui';
import BuildApi from '../BuildApi';
import { tracking } from '../Analytics';
const cli = {
lineDelayMs: 15,
@ -54,7 +55,7 @@ function getCliCommand(command, cliBuffer) {
function copyToClipboard(text) {
function onCopySuccessful() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliCopyToClipboard', text.length);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliCopyToClipboard', text.length);
const button = TABS.cli.GUI.copyButton;
const origText = button.text();
const origWidth = button.css("width");
@ -177,7 +178,7 @@ cli.initialize = function (callback) {
if (self.outputHistory.length > 0 && writer.length === 0) {
writer.write(new Blob([self.outputHistory], {type: 'text/plain'}));
} else {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliSave', self.outputHistory.length);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliSave', self.outputHistory.length);
console.log('write complete');
}
@ -222,7 +223,7 @@ cli.initialize = function (callback) {
function executeSnippet(fileName) {
const commands = previewArea.val();
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliExecuteFromFile', fileName);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CliExecuteFromFile', fileName);
executeCommands(commands);
self.GUI.snippetPreviewWindow.close();

View File

@ -1,6 +1,7 @@
import semver from 'semver';
import { i18n } from '../localization';
import GUI from '../gui';
import { tracking } from "../Analytics";
const configuration = {
analyticsChanges: {},
@ -501,7 +502,7 @@ configuration.initialize = function (callback) {
FC.RX_CONFIG.fpvCamAngleDegrees = parseInt($('input[name="fpvCamAngleDegrees"]').val());
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'configuration');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'configuration');
self.analyticsChanges = {};
// fill some data

View File

@ -4,6 +4,7 @@ import { get as getConfig, set as setConfig } from '../ConfigStorage';
import { get as getStorage, set as setStorage } from '../SessionStorage';
import BuildApi from '../BuildApi';
import ConfigInserter from "../ConfigInserter.js";
import { tracking } from "../Analytics";
const firmware_flasher = {
targets: null,
@ -113,7 +114,7 @@ firmware_flasher.initialize = function (callback) {
self.parsed_hex = data;
if (self.parsed_hex) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SIZE, self.parsed_hex.bytes_total);
tracking.setFirmwareData(tracking.DATA.FIRMWARE_SIZE, self.parsed_hex.bytes_total);
showLoadedHex(key);
} else {
self.flashingMessage(i18n.getMessage('firmwareFlasherHexCorrupted'), self.FLASH_MESSAGE_TYPES.INVALID);
@ -246,7 +247,7 @@ firmware_flasher.initialize = function (callback) {
i18n.localizePage();
buildType_e.change(function() {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_CHANNEL, $('option:selected', this).text());
tracking.setFirmwareData(tracking.DATA.FIRMWARE_CHANNEL, $('option:selected', this).text());
$("a.load_remote_file").addClass('disabled');
const build_type = $(this).val();
@ -472,7 +473,7 @@ firmware_flasher.initialize = function (callback) {
eraseAll = true;
}
analytics.setFirmwareData(analytics.DATA.FIRMWARE_ERASE_ALL, eraseAll.toString());
tracking.setFirmwareData(tracking.DATA.FIRMWARE_ERASE_ALL, eraseAll.toString());
if (!$('option:selected', portPickerElement).data().isDFU) {
if (String(portPickerElement.val()) !== '0') {
@ -489,7 +490,7 @@ firmware_flasher.initialize = function (callback) {
baud = parseInt($('#flash_manual_baud_rate').val());
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'Flashing', self.fileName || null);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'Flashing', self.fileName || null);
STM32.connect(port, baud, firmware, options);
} else {
@ -497,7 +498,7 @@ firmware_flasher.initialize = function (callback) {
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
}
} else {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'Flashing', self.fileName || null);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'Flashing', self.fileName || null);
STM32DFU.connect(usbDevices, firmware, options);
}
@ -701,8 +702,8 @@ firmware_flasher.initialize = function (callback) {
self.enableFlashing(false);
self.developmentFirmwareLoaded = false;
analytics.setFirmwareData(analytics.DATA.FIRMWARE_CHANNEL, undefined);
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'file');
tracking.setFirmwareData(tracking.DATA.FIRMWARE_CHANNEL, undefined);
tracking.setFirmwareData(tracking.DATA.FIRMWARE_SOURCE, 'file');
chrome.fileSystem.chooseEntry({
type: 'openFile',
@ -725,7 +726,7 @@ firmware_flasher.initialize = function (callback) {
console.log('Loading file from:', path);
fileEntry.file(function (file) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, file.name);
tracking.setFirmwareData(tracking.DATA.FIRMWARE_NAME, file.name);
const reader = new FileReader();
reader.onloadend = function(e) {
@ -739,7 +740,7 @@ firmware_flasher.initialize = function (callback) {
self.parsed_hex = data;
if (self.parsed_hex) {
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SIZE, self.parsed_hex.bytes_total);
tracking.setFirmwareData(tracking.DATA.FIRMWARE_SIZE, self.parsed_hex.bytes_total);
self.localFirmwareLoaded = true;
showLoadedHex(file.name);
@ -786,7 +787,7 @@ firmware_flasher.initialize = function (callback) {
self.localFirmwareLoaded = false;
self.developmentFirmwareLoaded = buildTypesToShow[$('select[name="build_type"]').val()].tag === 'firmwareFlasherOptionLabelBuildTypeDevelopment';
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'http');
tracking.setFirmwareData(tracking.DATA.FIRMWARE_SOURCE, 'http');
if ($('select[name="firmware_version"]').val() === "0") {
GUI.log(i18n.getMessage('firmwareFlasherNoFirmwareSelected'));
@ -874,7 +875,7 @@ firmware_flasher.initialize = function (callback) {
return;
}
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, response.file);
tracking.setFirmwareData(tracking.DATA.FIRMWARE_NAME, response.file);
updateStatus('Pending', response.key, 0, false);
@ -921,7 +922,7 @@ firmware_flasher.initialize = function (callback) {
if (!exitDfuElement.hasClass('disabled')) {
exitDfuElement.addClass("disabled");
if (!GUI.connect_lock) { // button disabled while flashing is in progress
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
try {
console.log('Closing DFU');
STM32DFU.connect(usbDevices, self.parsed_hex, { exitDfu: true });
@ -1079,7 +1080,7 @@ firmware_flasher.initialize = function (callback) {
return;
}
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'SaveFirmware', path);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'SaveFirmware', path);
};
writer.write(blob);
@ -1157,7 +1158,7 @@ firmware_flasher.cleanup = function (callback) {
$('div#flashbutton a.flash_state').removeClass('active');
$('div#flashbutton a.flash').removeClass('active');
analytics.resetFirmwareData();
tracking.resetFirmwareData();
if (callback) callback();
};

View File

@ -4,6 +4,7 @@ import { get as getConfig, set as setConfig } from '../ConfigStorage';
import MotorOutputReorderConfig from "../../components/MotorOutputReordering/MotorOutputReorderingConfig";
import MotorOutputReorderComponent from "../../components/MotorOutputReordering/MotorOutputReorderingComponent";
import EscDshotDirectionComponent from "../../components/EscDshotDirection/EscDshotDirectionComponent";
import { tracking } from "../Analytics";
const motors = {
previousDshotBidir: null,
@ -1142,7 +1143,7 @@ motors.initialize = async function (callback) {
}
await MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'motors');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'motors');
self.analyticsChanges = {};
self.configHasChanged = false;

View File

@ -1,5 +1,6 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
let sdcardTimer;
@ -137,7 +138,7 @@ onboard_logging.initialize = function (callback) {
.toggleClass("msc-supported", true);
$('a.onboardLoggingRebootMsc').click(function () {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc');
const buffer = [];
if (GUI.operating_system === "Linux") {
@ -434,9 +435,9 @@ onboard_logging.initialize = function (callback) {
if (dataflashPresent && FC.SDCARD.state === MSP.SDCARD_STATE_NOT_PRESENT) {
loggingStatus = 'Dataflash';
analytics.setFlightControllerData(analytics.DATA.LOG_SIZE, FC.DATAFLASH.usedSize);
tracking.setFlightControllerData(tracking.DATA.LOG_SIZE, FC.DATAFLASH.usedSize);
}
analytics.setFlightControllerData(analytics.DATA.LOGGING_STATUS, loggingStatus);
tracking.setFlightControllerData(tracking.DATA.LOGGING_STATUS, loggingStatus);
if (FC.SDCARD.supported && !sdcardTimer) {
// Poll for changes in SD card status
@ -469,7 +470,7 @@ onboard_logging.initialize = function (callback) {
}
function mark_saving_dialog_done(startTime, totalBytes, totalBytesCompressed) {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SaveDataflash');
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SaveDataflash');
const totalTime = (new Date().getTime() - startTime) / 1000;
console.log(`Received ${totalBytes} bytes in ${totalTime.toFixed(2)}s (${
@ -631,8 +632,8 @@ onboard_logging.initialize = function (callback) {
};
onboard_logging.cleanup = function (callback) {
analytics.setFlightControllerData(analytics.DATA.LOGGING_STATUS, undefined);
analytics.setFlightControllerData(analytics.DATA.LOG_SIZE, undefined);
tracking.setFlightControllerData(tracking.DATA.LOGGING_STATUS, undefined);
tracking.setFlightControllerData(tracking.DATA.LOG_SIZE, undefined);
if (sdcardTimer) {
clearTimeout(sdcardTimer);

View File

@ -1,5 +1,6 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
const FONT = {};
const SYM = {};
@ -3259,7 +3260,7 @@ osd.initialize = function(callback) {
}
});
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'osd');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'osd');
self.analyticsChanges = {};
});

View File

@ -1,6 +1,7 @@
import { i18n } from "../localization";
import { colorTables, getColorForPercentage } from '../utils/css.js';
import GUI from '../gui';
import { tracking } from "../Analytics";
const pid_tuning = {
RATE_PROFILE_MASK: 128,
@ -2263,7 +2264,7 @@ pid_tuning.initialize = function (callback) {
self.refresh();
});
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'pid_tuning');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'pid_tuning');
self.analyticsChanges = {};
});

View File

@ -1,6 +1,7 @@
import semver from 'semver';
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
const ports = {
analyticsChanges: {},
@ -358,7 +359,7 @@ ports.initialize = function (callback) {
}
function on_save_handler() {
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'ports');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'ports');
self.analyticsChanges = {};
// update configuration based on current ui state

View File

@ -1,5 +1,6 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { tracking } from "../Analytics";
const power = {
supported: false,
@ -11,8 +12,6 @@ power.initialize = function (callback) {
if (GUI.active_tab != 'power') {
GUI.active_tab = 'power';
// Disabled on merge into betaflight-configurator
//googleAnalytics.sendAppView('Power');
}
if (GUI.calibrationManager) {
@ -473,7 +472,7 @@ power.initialize = function (callback) {
FC.BATTERY_CONFIG.vbatwarningcellvoltage = parseFloat($('input[name="warningcellvoltage"]').val());
FC.BATTERY_CONFIG.capacity = parseInt($('input[name="capacity"]').val());
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'power');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'power');
save_power_config();
});

View File

@ -1,7 +1,7 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { get as getConfig, set as setConfig } from '../ConfigStorage';
import { tracking } from "../Analytics";
import CryptoES from 'crypto-es';
const receiver = {
@ -493,7 +493,7 @@ receiver.initialize = function (callback) {
}
}
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, tab.analyticsChanges, 'receiver');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, tab.analyticsChanges, 'receiver');
tab.analyticsChanges = {};
MSP.send_message(MSPCodes.MSP_SET_RX_MAP, mspHelper.crunch(MSPCodes.MSP_SET_RX_MAP), false, save_rssi_config);

View File

@ -8,8 +8,6 @@ setup_osd.initialize = function (callback) {
if (GUI.active_tab != 'setup_osd') {
GUI.active_tab = 'setup_osd';
// Disabled on merge into betaflight-configurator
//googleAnalytics.sendAppView('Setup OSD');
}
function load_status() {

View File

@ -110,8 +110,6 @@ transponder.initialize = function(callback) {
/////////////////////////////////////////////
GUI.active_tab = 'transponder';
// Disabled on merge into betaflight-configurator
//googleAnalytics.sendAppView('Transponder');
// transponder supported added in MSP API Version 1.16.0
if (FC.CONFIG) {

View File

@ -1,6 +1,7 @@
import { i18n } from "../localization";
import Clipboard from "../Clipboard";
import GUI from '../gui';
import { tracking } from "../Analytics";
const vtx = {
supported: false,
@ -646,7 +647,7 @@ vtx.initialize = function (callback) {
// we get here at the end of the truncate method, change to the new end
writer.onwriteend = function() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableLuaSave', text.length);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableLuaSave', text.length);
console.log('Write VTX table lua file end');
GUI.log(i18n.getMessage('vtxSavedLuaFileOk'));
};
@ -697,7 +698,7 @@ vtx.initialize = function (callback) {
// we get here at the end of the truncate method, change to the new end
writer.onwriteend = function() {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableSave', text.length);
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableSave', text.length);
console.log(vtxConfig);
console.log('Write VTX file end');
GUI.log(i18n.getMessage('vtxSavedFileOk'));
@ -834,7 +835,7 @@ vtx.initialize = function (callback) {
// Start MSP saving
save_vtx_config();
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'vtx');
tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'vtx');
function save_vtx_config() {
MSP.send_message(MSPCodes.MSP_SET_VTX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VTX_CONFIG), false, save_vtx_powerlevels);

View File

@ -108,7 +108,6 @@
<script type="text/javascript" src="./js/RateCurve.js"></script>
<script type="text/javascript" src="./js/Features.js"></script>
<script type="text/javascript" src="./js/Beepers.js"></script>
<script type="text/javascript" src="./js/Analytics.js"></script>
<script type="text/javascript" src="./js/GitHubApi.js"></script>
<script type="module" src="./js/main.js"></script>
<script type="text/javascript" src="./js/LogoManager.js"></script>

View File

@ -6,7 +6,7 @@ class MockAnalytics {
}
}
let analytics;
let tracking;
describe('TABS.cli', () => {
@ -33,7 +33,7 @@ describe('TABS.cli', () => {
CliAutoComplete.setEnabled(false); // not testing the client-side autocomplete
before(() => {
analytics = new MockAnalytics();
tracking = new MockAnalytics();
$('body').append(cliTab);