@@ -19,16 +19,6 @@ import DEFAULT_OPTIONS from './options';
19
19
import getHost from './get-host' ;
20
20
import baseCookie from './base-cookie' ;
21
21
22
- let AsyncStorage ;
23
- let Platform ;
24
- let DeviceInfo ;
25
- if ( BUILD_COMPAT_REACT_NATIVE ) {
26
- const reactNative = require ( 'react-native' ) ;
27
- AsyncStorage = require ( '@react-native-async-storage/async-storage' ) . default ;
28
- Platform = reactNative . Platform ;
29
- DeviceInfo = require ( 'react-native-device-info' ) ;
30
- }
31
-
32
22
/**
33
23
* AmplitudeClient SDK API - instance constructor.
34
24
* The Amplitude class handles creation of client instances, all you need to do is call amplitude.getInstance()
@@ -203,75 +193,18 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
203
193
this . _isInitialized = true ;
204
194
} ;
205
195
206
- if ( AsyncStorage ) {
207
- this . _migrateUnsentEvents ( ( ) => {
208
- Promise . all ( [
209
- AsyncStorage . getItem ( this . _storageSuffix ) ,
210
- AsyncStorage . getItem ( this . options . unsentKey + this . _storageSuffix ) ,
211
- AsyncStorage . getItem ( this . options . unsentIdentifyKey + this . _storageSuffix ) ,
212
- ] )
213
- . then ( ( values ) => {
214
- if ( values [ 0 ] ) {
215
- const cookieData = JSON . parse ( values [ 0 ] ) ;
216
- if ( cookieData ) {
217
- _loadCookieDataProps ( this , cookieData ) ;
218
- }
219
- }
220
- if ( this . options . saveEvents ) {
221
- this . _unsentEvents = this . _parseSavedUnsentEventsString ( values [ 1 ] )
222
- . map ( ( event ) => ( { event } ) )
223
- . concat ( this . _unsentEvents ) ;
224
- this . _unsentIdentifys = this . _parseSavedUnsentEventsString ( values [ 2 ] )
225
- . map ( ( event ) => ( { event } ) )
226
- . concat ( this . _unsentIdentifys ) ;
227
- }
228
- if ( DeviceInfo ) {
229
- Promise . all ( [
230
- DeviceInfo . getCarrier ( ) ,
231
- DeviceInfo . getModel ( ) ,
232
- DeviceInfo . getManufacturer ( ) ,
233
- DeviceInfo . getVersion ( ) ,
234
- DeviceInfo . getUniqueId ( ) ,
235
- ] )
236
- . then ( ( values ) => {
237
- this . deviceInfo = {
238
- carrier : values [ 0 ] ,
239
- model : values [ 1 ] ,
240
- manufacturer : values [ 2 ] ,
241
- version : values [ 3 ] ,
242
- } ;
243
- initFromStorage ( values [ 4 ] ) ;
244
- this . runQueuedFunctions ( ) ;
245
- if ( type ( opt_callback ) === 'function' ) {
246
- opt_callback ( this ) ;
247
- }
248
- } )
249
- . catch ( ( err ) => {
250
- this . options . onError ( err ) ;
251
- } ) ;
252
- } else {
253
- initFromStorage ( ) ;
254
- this . runQueuedFunctions ( ) ;
255
- }
256
- } )
257
- . catch ( ( err ) => {
258
- this . options . onError ( err ) ;
259
- } ) ;
260
- } ) ;
261
- } else {
262
- if ( this . options . saveEvents ) {
263
- this . _unsentEvents = this . _loadSavedUnsentEvents ( this . options . unsentKey )
264
- . map ( ( event ) => ( { event } ) )
265
- . concat ( this . _unsentEvents ) ;
266
- this . _unsentIdentifys = this . _loadSavedUnsentEvents ( this . options . unsentIdentifyKey )
267
- . map ( ( event ) => ( { event } ) )
268
- . concat ( this . _unsentIdentifys ) ;
269
- }
270
- initFromStorage ( ) ;
271
- this . runQueuedFunctions ( ) ;
272
- if ( type ( opt_callback ) === 'function' ) {
273
- opt_callback ( this ) ;
274
- }
196
+ if ( this . options . saveEvents ) {
197
+ this . _unsentEvents = this . _loadSavedUnsentEvents ( this . options . unsentKey )
198
+ . map ( ( event ) => ( { event } ) )
199
+ . concat ( this . _unsentEvents ) ;
200
+ this . _unsentIdentifys = this . _loadSavedUnsentEvents ( this . options . unsentIdentifyKey )
201
+ . map ( ( event ) => ( { event } ) )
202
+ . concat ( this . _unsentIdentifys ) ;
203
+ }
204
+ initFromStorage ( ) ;
205
+ this . runQueuedFunctions ( ) ;
206
+ if ( type ( opt_callback ) === 'function' ) {
207
+ opt_callback ( this ) ;
275
208
}
276
209
} catch ( err ) {
277
210
utils . log . error ( err ) ;
@@ -341,53 +274,6 @@ const _validateUnsentEventQueue = (queue) => {
341
274
}
342
275
} ;
343
276
344
- /**
345
- * @private
346
- */
347
- AmplitudeClient . prototype . _migrateUnsentEvents = function _migrateUnsentEvents ( cb ) {
348
- Promise . all ( [ AsyncStorage . getItem ( this . options . unsentKey ) , AsyncStorage . getItem ( this . options . unsentIdentifyKey ) ] )
349
- . then ( ( values ) => {
350
- if ( this . options . saveEvents ) {
351
- var unsentEventsString = values [ 0 ] ;
352
- var unsentIdentifyKey = values [ 1 ] ;
353
-
354
- var itemsToSet = [ ] ;
355
- var itemsToRemove = [ ] ;
356
-
357
- if ( unsentEventsString ) {
358
- itemsToSet . push (
359
- AsyncStorage . setItem ( this . options . unsentKey + this . _storageSuffix , JSON . stringify ( unsentEventsString ) ) ,
360
- ) ;
361
- itemsToRemove . push ( AsyncStorage . removeItem ( this . options . unsentKey ) ) ;
362
- }
363
-
364
- if ( unsentIdentifyKey ) {
365
- itemsToSet . push (
366
- AsyncStorage . setItem (
367
- this . options . unsentIdentifyKey + this . _storageSuffix ,
368
- JSON . stringify ( unsentIdentifyKey ) ,
369
- ) ,
370
- ) ;
371
- itemsToRemove . push ( AsyncStorage . removeItem ( this . options . unsentIdentifyKey ) ) ;
372
- }
373
-
374
- if ( itemsToSet . length > 0 ) {
375
- Promise . all ( itemsToSet )
376
- . then ( ( ) => {
377
- Promise . all ( itemsToRemove ) ;
378
- } )
379
- . catch ( ( err ) => {
380
- this . options . onError ( err ) ;
381
- } ) ;
382
- }
383
- }
384
- } )
385
- . then ( cb )
386
- . catch ( ( err ) => {
387
- this . options . onError ( err ) ;
388
- } ) ;
389
- } ;
390
-
391
277
/**
392
278
* @private
393
279
*/
@@ -721,9 +607,6 @@ var _saveCookieData = function _saveCookieData(scope) {
721
607
identifyId : scope . _identifyId ,
722
608
sequenceNumber : scope . _sequenceNumber ,
723
609
} ;
724
- if ( AsyncStorage ) {
725
- AsyncStorage . setItem ( scope . _storageSuffix , JSON . stringify ( cookieData ) ) ;
726
- }
727
610
728
611
if ( scope . _useOldCookie ) {
729
612
scope . cookieStorage . set ( scope . options . cookieName + scope . _storageSuffix , cookieData ) ;
@@ -872,21 +755,13 @@ AmplitudeClient.prototype.saveEvents = function saveEvents() {
872
755
try {
873
756
const serializedUnsentEvents = JSON . stringify ( this . _unsentEvents . map ( ( { event } ) => event ) ) ;
874
757
875
- if ( AsyncStorage ) {
876
- AsyncStorage . setItem ( this . options . unsentKey + this . _storageSuffix , serializedUnsentEvents ) ;
877
- } else {
878
- this . _setInStorage ( localStorage , this . options . unsentKey , serializedUnsentEvents ) ;
879
- }
758
+ this . _setInStorage ( localStorage , this . options . unsentKey , serializedUnsentEvents ) ;
880
759
} catch ( e ) { } /* eslint-disable-line no-empty */
881
760
882
761
try {
883
762
const serializedIdentifys = JSON . stringify ( this . _unsentIdentifys . map ( ( unsentIdentify ) => unsentIdentify . event ) ) ;
884
763
885
- if ( AsyncStorage ) {
886
- AsyncStorage . setItem ( this . options . unsentIdentifyKey + this . _storageSuffix , serializedIdentifys ) ;
887
- } else {
888
- this . _setInStorage ( localStorage , this . options . unsentIdentifyKey , serializedIdentifys ) ;
889
- }
764
+ this . _setInStorage ( localStorage , this . options . unsentIdentifyKey , serializedIdentifys ) ;
890
765
} catch ( e ) { } /* eslint-disable-line no-empty */
891
766
} ;
892
767
@@ -1260,9 +1135,8 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
1260
1135
timestamp ,
1261
1136
callback ,
1262
1137
) {
1263
- if ( ! BUILD_COMPAT_REACT_NATIVE ) {
1264
- _loadCookieData ( this ) ; // reload cookie before each log event to sync event meta-data between windows and tabs
1265
- }
1138
+ _loadCookieData ( this ) ; // reload cookie before each log event to sync event meta-data between windows and tabs
1139
+
1266
1140
if ( ! eventType ) {
1267
1141
if ( type ( callback ) === 'function' ) {
1268
1142
callback ( 0 , 'No request sent' , { reason : 'Missing eventType' } ) ;
@@ -1291,23 +1165,9 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
1291
1165
this . _lastEventTime = eventTime ;
1292
1166
_saveCookieData ( this ) ;
1293
1167
1294
- let osName = this . _ua . browser . name ;
1295
- let osVersion = this . _ua . browser . major ;
1296
- let deviceModel = this . _ua . os . name ;
1297
- let deviceManufacturer ;
1298
-
1299
- let versionName ;
1300
- let carrier ;
1301
- if ( BUILD_COMPAT_REACT_NATIVE ) {
1302
- osName = Platform . OS ;
1303
- osVersion = Platform . Version ;
1304
- if ( this . deviceInfo ) {
1305
- carrier = this . deviceInfo . carrier ;
1306
- deviceManufacturer = this . deviceInfo . manufacturer ;
1307
- deviceModel = this . deviceInfo . model ;
1308
- versionName = this . deviceInfo . version ;
1309
- }
1310
- }
1168
+ const osName = this . _ua . browser . name ;
1169
+ const osVersion = this . _ua . browser . major ;
1170
+ const deviceModel = this . _ua . os . name ;
1311
1171
1312
1172
userProperties = userProperties || { } ;
1313
1173
var trackingOptions = { ...this . _apiPropertiesTrackingOptions } ;
@@ -1322,20 +1182,18 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
1322
1182
event_id : eventId ,
1323
1183
session_id : this . _sessionId || - 1 ,
1324
1184
event_type : eventType ,
1325
- version_name : _shouldTrackField ( this , 'version_name' ) ? this . options . versionName || versionName || null : null ,
1185
+ version_name : this . options . versionName || null ,
1326
1186
platform : _shouldTrackField ( this , 'platform' ) ? this . options . platform : null ,
1327
1187
os_name : _shouldTrackField ( this , 'os_name' ) ? osName || null : null ,
1328
1188
os_version : _shouldTrackField ( this , 'os_version' ) ? osVersion || null : null ,
1329
1189
device_model : _shouldTrackField ( this , 'device_model' ) ? deviceModel || null : null ,
1330
- device_manufacturer : _shouldTrackField ( this , 'device_manufacturer' ) ? deviceManufacturer || null : null ,
1331
1190
language : _shouldTrackField ( this , 'language' ) ? this . options . language : null ,
1332
- carrier : _shouldTrackField ( this , 'carrier' ) ? carrier || null : null ,
1333
1191
api_properties : apiProperties ,
1334
1192
event_properties : utils . truncate ( utils . validateProperties ( eventProperties ) ) ,
1335
1193
user_properties : utils . truncate ( utils . validateProperties ( userProperties ) ) ,
1336
1194
uuid : UUID ( ) ,
1337
1195
library : {
1338
- name : BUILD_COMPAT_REACT_NATIVE ? 'amplitude-react-native' : 'amplitude-js' ,
1196
+ name : 'amplitude-js' ,
1339
1197
version : version ,
1340
1198
} ,
1341
1199
sequence_number : sequenceNumber , // for ordering events and identifys
0 commit comments