1+ import ShortUniqueId from 'short-unique-id' ;
2+ import googleAnalytics from 'universal-ga' ;
3+ import { set as setConfig , get as getConfig } from './ConfigStorage' ;
4+ import GUI from './gui' ;
5+ import CONFIGURATOR from './data_storage' ;
16
27let tracking = null ;
38export { tracking } ;
@@ -6,6 +11,66 @@ export function createAnalytics(ga, settings) {
611 tracking = new Analytics ( ga , settings ) ;
712}
813
14+ function getBuildType ( ) {
15+ return GUI . Mode ;
16+ }
17+
18+ function setupAnalytics ( result ) {
19+ let userId ;
20+ if ( result . userId ) {
21+ userId = result . userId ;
22+ } else {
23+ const uid = new ShortUniqueId ( ) ;
24+ userId = uid . randomUUID ( 13 ) ;
25+
26+ setConfig ( { 'userId' : userId } ) ;
27+ }
28+
29+ const optOut = ! ! result . analyticsOptOut ;
30+ const checkForDebugVersions = ! ! result . checkForConfiguratorUnstableVersions ;
31+
32+ const debugMode = typeof process === "object" && process . versions [ 'nw-flavor' ] === 'sdk' ;
33+
34+ const settings = {
35+ trackingId : 'UA-123002063-1' ,
36+ userId : userId ,
37+ appName : CONFIGURATOR . productName ,
38+ appVersion : CONFIGURATOR . version ,
39+ gitRevision : CONFIGURATOR . gitRevision ,
40+ os : GUI . operating_system ,
41+ checkForDebugVersions : checkForDebugVersions ,
42+ optOut : optOut ,
43+ debugMode : debugMode ,
44+ buildType : getBuildType ( ) ,
45+ } ;
46+ createAnalytics ( googleAnalytics , settings ) ;
47+ window . tracking = tracking ;
48+
49+ function logException ( exception ) {
50+ tracking . sendException ( exception . stack ) ;
51+ }
52+
53+ if ( typeof process === "object" ) {
54+ process . on ( 'uncaughtException' , logException ) ;
55+ }
56+
57+ tracking . sendEvent ( tracking . EVENT_CATEGORIES . APPLICATION , 'AppStart' , { sessionControl : 'start' } ) ;
58+
59+ $ ( '.connect_b a.connect' ) . removeClass ( 'disabled' ) ;
60+ $ ( '.firmware_b a.flash' ) . removeClass ( 'disabled' ) ;
61+ }
62+
63+ export function checkSetupAnalytics ( callback ) {
64+ if ( ! tracking ) {
65+ const result = getConfig ( [ 'userId' , 'analyticsOptOut' , 'checkForConfiguratorUnstableVersions' ] ) ;
66+ setupAnalytics ( result ) ;
67+ }
68+
69+ if ( callback ) {
70+ callback ( tracking ) ;
71+ }
72+ }
73+
974class Analytics {
1075
1176 constructor ( ga , settings ) {
0 commit comments