mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 12:55:14 +03:00
Fixed dimension reporting.
This commit is contained in:
parent
8d5d81f9cf
commit
a72c436e8e
12 changed files with 251 additions and 151 deletions
|
@ -1,9 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
var Analytics = function (serviceName, trackingId, operatingSystem) {
|
||||
this.eventBuilder = analytics.EventBuilder;
|
||||
this.service = analytics.getService(serviceName);
|
||||
this.tracker = this.service.getTracker(trackingId);
|
||||
var Analytics = function (trackingId, userId, appName, appVersion, buildType, optOut, debugMode) {
|
||||
this._trackingId = trackingId;
|
||||
|
||||
this.setOptOut(optOut);
|
||||
|
||||
this._analytics = analytics;
|
||||
|
||||
this._analytics.initialize(this._trackingId, {
|
||||
storage: 'none',
|
||||
clientId: userId,
|
||||
debug: !!debugMode
|
||||
});
|
||||
|
||||
// Make it work for the Chrome App:
|
||||
this._analytics.set('forceSSL', true);
|
||||
this._analytics.set('transport', 'xhr');
|
||||
|
||||
// Make it work for NW.js:
|
||||
this._analytics.set('checkProtocolTask', null);
|
||||
|
||||
this._analytics.set('appName', appName);
|
||||
this._analytics.set('appVersion', debugMode ? appVersion + '-debug' : appVersion);
|
||||
|
||||
this.EVENT_CATEGORIES = {
|
||||
APPLICATION: 'Application',
|
||||
FLIGHT_CONTROLLER: 'FlightController',
|
||||
};
|
||||
|
||||
this.DATA = {
|
||||
BOARD_TYPE: 'boardType',
|
||||
|
@ -14,51 +37,71 @@ var Analytics = function (serviceName, trackingId, operatingSystem) {
|
|||
};
|
||||
|
||||
this.DIMENSIONS = {
|
||||
OS: 1,
|
||||
BUILD_TYPE: 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.setDimension(this.DIMENSIONS.BUILD_TYPE, buildType);
|
||||
|
||||
this.resetFlightControllerData();
|
||||
};
|
||||
|
||||
Analytics.prototype.setTrackingPermitted = function (permitted) {
|
||||
this.service.getConfig().addCallback(function(config) {
|
||||
config.setTrackingPermitted(permitted);
|
||||
});
|
||||
Analytics.prototype.setDimension = function (dimension, value) {
|
||||
var dimensionName = 'dimension' + dimension;
|
||||
this._analytics.custom(dimensionName, value);
|
||||
}
|
||||
|
||||
Analytics.prototype.send = function (event) {
|
||||
this.tracker.send(event);
|
||||
Analytics.prototype.sendEvent = function (category, action, options) {
|
||||
options = options || {};
|
||||
options.eventLabel = options.eventLabel || this.flightControllerData[this.DATA.MCU_ID];
|
||||
this._analytics.event(category, action, options);
|
||||
}
|
||||
|
||||
Analytics.prototype.sendChangeEvents = function (category, changeList) {
|
||||
for (var actionName in changeList) {
|
||||
if (changeList.hasOwnProperty(actionName)) {
|
||||
var actionValue = changeList[actionName];
|
||||
if (actionValue !== undefined) {
|
||||
this.sendEvent(category, actionName, { eventLabel: actionValue });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Analytics.prototype.sendAppView = function (viewName) {
|
||||
this.tracker.sendAppView(viewName);
|
||||
this._analytics.screenview(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.sendTiming = function (category, timing, value) {
|
||||
this._analytics.timing(category, timing, value);
|
||||
}
|
||||
|
||||
Analytics.prototype.sendException = function (message) {
|
||||
this._analytics.exception(message);
|
||||
}
|
||||
|
||||
Analytics.prototype.setOptOut = function (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]);
|
||||
}
|
||||
|
||||
Analytics.prototype.setFlightControllerData = function (property, value) {
|
||||
this.flightControllerData[property] = value;
|
||||
|
||||
this.rebuildFlightControllerEvent();
|
||||
this._rebuildFlightControllerEvent();
|
||||
}
|
||||
|
||||
Analytics.prototype.resetFlightControllerData = function () {
|
||||
this.flightControllerData = {};
|
||||
|
||||
this.rebuildFlightControllerEvent();
|
||||
this._rebuildFlightControllerEvent();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue