mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-15 20:35:23 +03:00
Added Google analytics collection.
This commit is contained in:
parent
5b0a6349a7
commit
8d5d81f9cf
10 changed files with 277 additions and 4 deletions
64
src/js/Analytics.js
Normal file
64
src/js/Analytics.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
'use strict';
|
||||
|
||||
var Analytics = function (serviceName, trackingId, operatingSystem) {
|
||||
this.eventBuilder = analytics.EventBuilder;
|
||||
this.service = analytics.getService(serviceName);
|
||||
this.tracker = this.service.getTracker(trackingId);
|
||||
|
||||
this.DATA = {
|
||||
BOARD_TYPE: 'boardType',
|
||||
FIRMWARE_TYPE: 'firmwareType',
|
||||
FIRMWARE_VERSION: 'firmwareVersion',
|
||||
API_VERSION: 'apiVersion',
|
||||
MCU_ID: 'mcuId',
|
||||
};
|
||||
|
||||
this.DIMENSIONS = {
|
||||
OS: 1,
|
||||
BOARD_TYPE: 2,
|
||||
FIRMWARE_TYPE: 3,
|
||||
FIRMWARE_VERSION: 4,
|
||||
API_VERSION: 5,
|
||||
};
|
||||
|
||||
this.APPLICATION_EVENT = this.eventBuilder.builder()
|
||||
.category('Application')
|
||||
.dimension(this.DIMENSIONS.OS, operatingSystem);
|
||||
|
||||
this.resetFlightControllerData();
|
||||
};
|
||||
|
||||
Analytics.prototype.setTrackingPermitted = function (permitted) {
|
||||
this.service.getConfig().addCallback(function(config) {
|
||||
config.setTrackingPermitted(permitted);
|
||||
});
|
||||
}
|
||||
|
||||
Analytics.prototype.send = function (event) {
|
||||
this.tracker.send(event);
|
||||
}
|
||||
|
||||
Analytics.prototype.sendAppView = function (viewName) {
|
||||
this.tracker.sendAppView(viewName);
|
||||
}
|
||||
|
||||
Analytics.prototype.rebuildFlightControllerEvent = function () {
|
||||
this.FLIGHT_CONTROLLER_EVENT = this.eventBuilder.builder()
|
||||
.category('FlightController')
|
||||
.dimension(this.DIMENSIONS.BOARD_TYPE, this.flightControllerData[this.DATA.BOARD_TYPE])
|
||||
.dimension(this.DIMENSIONS.FIRMWARE_TYPE, this.flightControllerData[this.DATA.FIRMWARE_TYPE])
|
||||
.dimension(this.DIMENSIONS.FIRMWARE_VERSION, this.flightControllerData[this.DATA.FIRMWARE_VERSION])
|
||||
.dimension(this.DIMENSIONS.API_VERSION, this.flightControllerData[this.DATA.API_VERSION]);
|
||||
}
|
||||
|
||||
Analytics.prototype.setFlightControllerData = function (property, value) {
|
||||
this.flightControllerData[property] = value;
|
||||
|
||||
this.rebuildFlightControllerEvent();
|
||||
}
|
||||
|
||||
Analytics.prototype.resetFlightControllerData = function () {
|
||||
this.flightControllerData = {};
|
||||
|
||||
this.rebuildFlightControllerEvent();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue