@@ -54,15 +54,47 @@ const finishTracking = async (data?: ITrackingInformation) => {
5454 }
5555} ;
5656
57+ const trackPreviewAppData = async ( data : any ) => {
58+ const mobileHelper = $injector . resolve < Mobile . IMobileHelper > ( "mobileHelper" ) ;
59+ const devicesService = $injector . resolve < Mobile . IDevicesService > ( "devicesService" ) ;
60+ await devicesService . initialize ( { platform : data . platform , skipDeviceDetectionInterval : true , skipEmulatorStart : true } ) ;
61+
62+ const devices = await devicesService . getDevicesForPlatform ( data . platform ) ;
63+ _ . each ( devices , async ( device : Mobile . IDevice ) => {
64+ try {
65+ let previewAppFilePath = null ;
66+ if ( mobileHelper . isAndroidPlatform ( device . deviceInfo . platform ) ) {
67+ previewAppFilePath = "/sdcard/org.nativescript.preview/device.json" ;
68+ } else if ( mobileHelper . isiOSPlatform ( device . deviceInfo . platform ) ) {
69+ previewAppFilePath = "Documents/device.json" ;
70+ }
71+
72+ const previewAppFileContent = await device . fileSystem . getFileContent ( previewAppFilePath , "org.nativescript.preview" ) ;
73+ const previewAppDeviceId = JSON . parse ( previewAppFileContent ) . id ;
74+ data . label += `_${ previewAppDeviceId } ` ;
75+
76+ analyticsLoggingService . logData ( { message : `analytics-broker-process will send the data from preview app: ${ data } ` } ) ;
77+ await sendDataForTracking ( data ) ;
78+ } catch ( err ) {
79+ // ignore the error
80+ }
81+ } ) ;
82+ } ;
83+
5784process . on ( "message" , async ( data : ITrackingInformation ) => {
58- analyticsLoggingService . logData ( { message : `analytics-broker-process received message of type: ${ data . type } ` } ) ;
85+ analyticsLoggingService . logData ( { message : `analytics-broker-process received message of type: ${ JSON . stringify ( data ) } ` } ) ;
5986
6087 if ( data . type === TrackingTypes . Finish ) {
6188 receivedFinishMsg = true ;
6289 await finishTracking ( data ) ;
6390 return ;
6491 }
6592
93+ if ( data . type === TrackingTypes . PreviewAppData ) {
94+ await trackPreviewAppData ( < IPreviewAppTrackingInformation > data ) ;
95+ return ;
96+ }
97+
6698 await sendDataForTracking ( data ) ;
6799} ) ;
68100
0 commit comments