@@ -5627,7 +5627,7 @@ var uuid$1 = function uuid(a) {
5627
5627
) ;
5628
5628
} ;
5629
5629
5630
- var version = '4.2.1 ' ;
5630
+ var version = '4.3.0 ' ;
5631
5631
5632
5632
var getLanguage = function getLanguage ( ) {
5633
5633
return navigator && ( navigator . languages && navigator . languages [ 0 ] || navigator . language || navigator . userLanguage ) || undefined ;
@@ -5725,7 +5725,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
5725
5725
this . options . domain = this . cookieStorage . options ( ) . domain ;
5726
5726
5727
5727
if ( this . _instanceName === constants . DEFAULT_INSTANCE ) {
5728
- _upgradeCookeData ( this ) ;
5728
+ _upgradeCookieData ( this ) ;
5729
5729
}
5730
5730
_loadCookieData ( this ) ;
5731
5731
@@ -6025,7 +6025,7 @@ AmplitudeClient.prototype._setInStorage = function _setInStorage(storage, key, v
6025
6025
* Need to unify all sources into one place with a one-time upgrade/migration.
6026
6026
* @private
6027
6027
*/
6028
- var _upgradeCookeData = function _upgradeCookeData ( scope ) {
6028
+ var _upgradeCookieData = function _upgradeCookieData ( scope ) {
6029
6029
// skip if already migrated to 4.10+
6030
6030
var cookieData = scope . cookieStorage . get ( scope . options . cookieName + scope . _storageSuffix ) ;
6031
6031
if ( type ( cookieData ) === 'object' ) {
@@ -6459,7 +6459,7 @@ var _convertProxyObjectToRealObject = function _convertProxyObjectToRealObject(i
6459
6459
AmplitudeClient . prototype . identify = function ( identify_obj , opt_callback ) {
6460
6460
if ( ! this . _apiKeySet ( 'identify()' ) ) {
6461
6461
if ( type ( opt_callback ) === 'function' ) {
6462
- opt_callback ( 0 , 'No request sent' ) ;
6462
+ opt_callback ( 0 , 'No request sent' , { reason : 'API key is not set' } ) ;
6463
6463
}
6464
6464
return ;
6465
6465
}
@@ -6473,13 +6473,16 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
6473
6473
// only send if there are operations
6474
6474
if ( Object . keys ( identify_obj . userPropertiesOperations ) . length > 0 ) {
6475
6475
return this . _logEvent ( constants . IDENTIFY_EVENT , null , null , identify_obj . userPropertiesOperations , null , null , opt_callback ) ;
6476
+ } else {
6477
+ if ( type ( opt_callback ) === 'function' ) {
6478
+ opt_callback ( 0 , 'No request sent' , { reason : 'No user property operations' } ) ;
6479
+ }
6476
6480
}
6477
6481
} else {
6478
6482
utils . log . error ( 'Invalid identify input type. Expected Identify object but saw ' + type ( identify_obj ) ) ;
6479
- }
6480
-
6481
- if ( type ( opt_callback ) === 'function' ) {
6482
- opt_callback ( 0 , 'No request sent' ) ;
6483
+ if ( type ( opt_callback ) === 'function' ) {
6484
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid identify input type' } ) ;
6485
+ }
6483
6486
}
6484
6487
} ;
6485
6488
@@ -6502,9 +6505,15 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
6502
6505
*/
6503
6506
AmplitudeClient . prototype . _logEvent = function _logEvent ( eventType , eventProperties , apiProperties , userProperties , groups , timestamp , callback ) {
6504
6507
_loadCookieData ( this ) ; // reload cookie before each log event to sync event meta-data between windows and tabs
6505
- if ( ! eventType || this . options . optOut ) {
6508
+ if ( ! eventType ) {
6509
+ if ( type ( callback ) === 'function' ) {
6510
+ callback ( 0 , 'No request sent' , { reason : 'Missing eventType' } ) ;
6511
+ }
6512
+ return ;
6513
+ }
6514
+ if ( this . options . optOut ) {
6506
6515
if ( type ( callback ) === 'function' ) {
6507
- callback ( 0 , 'No request sent' ) ;
6516
+ callback ( 0 , 'No request sent' , { reason : 'optOut is set to true' } ) ;
6508
6517
}
6509
6518
return ;
6510
6519
}
@@ -6568,7 +6577,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
6568
6577
}
6569
6578
6570
6579
if ( ! this . _sendEventsIfReady ( callback ) && type ( callback ) === 'function' ) {
6571
- callback ( 0 , 'No request sent' ) ;
6580
+ callback ( 0 , 'No request sent' , { reason : 'No events to send or upload queued' } ) ;
6572
6581
}
6573
6582
6574
6583
return eventId ;
@@ -6619,9 +6628,21 @@ AmplitudeClient.prototype.logEvent = function logEvent(eventType, eventPropertie
6619
6628
* @example amplitudeClient.logEvent('Clicked Homepage Button', {'finished_flow': false, 'clicks': 15});
6620
6629
*/
6621
6630
AmplitudeClient . prototype . logEventWithTimestamp = function logEvent ( eventType , eventProperties , timestamp , opt_callback ) {
6622
- if ( ! this . _apiKeySet ( 'logEvent()' ) || ! utils . validateInput ( eventType , 'eventType' , 'string' ) || utils . isEmptyString ( eventType ) ) {
6631
+ if ( ! this . _apiKeySet ( 'logEvent()' ) ) {
6632
+ if ( type ( opt_callback ) === 'function' ) {
6633
+ opt_callback ( 0 , 'No request sent' , { reason : 'API key not set' } ) ;
6634
+ }
6635
+ return - 1 ;
6636
+ }
6637
+ if ( ! utils . validateInput ( eventType , 'eventType' , 'string' ) ) {
6638
+ if ( type ( opt_callback ) === 'function' ) {
6639
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid type for eventType' } ) ;
6640
+ }
6641
+ return - 1 ;
6642
+ }
6643
+ if ( utils . isEmptyString ( eventType ) ) {
6623
6644
if ( type ( opt_callback ) === 'function' ) {
6624
- opt_callback ( 0 , 'No request sent' ) ;
6645
+ opt_callback ( 0 , 'No request sent' , { reason : 'Missing eventType' } ) ;
6625
6646
}
6626
6647
return - 1 ;
6627
6648
}
@@ -6644,9 +6665,15 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
6644
6665
* @example amplitudeClient.logEventWithGroups('Clicked Button', null, {'orgId': 24});
6645
6666
*/
6646
6667
AmplitudeClient . prototype . logEventWithGroups = function ( eventType , eventProperties , groups , opt_callback ) {
6647
- if ( ! this . _apiKeySet ( 'logEventWithGroup()' ) || ! utils . validateInput ( eventType , 'eventType' , 'string ') ) {
6668
+ if ( ! this . _apiKeySet ( 'logEventWithGroups() ' ) ) {
6648
6669
if ( type ( opt_callback ) === 'function' ) {
6649
- opt_callback ( 0 , 'No request sent' ) ;
6670
+ opt_callback ( 0 , 'No request sent' , { reason : 'API key not set' } ) ;
6671
+ }
6672
+ return - 1 ;
6673
+ }
6674
+ if ( ! utils . validateInput ( eventType , 'eventType' , 'string' ) ) {
6675
+ if ( type ( opt_callback ) === 'function' ) {
6676
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid type for eventType' } ) ;
6650
6677
}
6651
6678
return - 1 ;
6652
6679
}
@@ -6751,9 +6778,27 @@ var _removeEvents = function _removeEvents(scope, eventQueue, maxId) {
6751
6778
* Note the server response code and response body are passed to the callback as input arguments.
6752
6779
*/
6753
6780
AmplitudeClient . prototype . sendEvents = function sendEvents ( callback ) {
6754
- if ( ! this . _apiKeySet ( 'sendEvents()' ) || this . _sending || this . options . optOut || this . _unsentCount ( ) === 0 ) {
6781
+ if ( ! this . _apiKeySet ( 'sendEvents()' ) ) {
6782
+ if ( type ( callback ) === 'function' ) {
6783
+ callback ( 0 , 'No request sent' , { reason : 'API key not set' } ) ;
6784
+ }
6785
+ return ;
6786
+ }
6787
+ if ( this . options . optOut ) {
6788
+ if ( type ( callback ) === 'function' ) {
6789
+ callback ( 0 , 'No request sent' , { reason : 'optOut is set to true' } ) ;
6790
+ }
6791
+ return ;
6792
+ }
6793
+ if ( this . _unsentCount ( ) === 0 ) {
6794
+ if ( type ( callback ) === 'function' ) {
6795
+ callback ( 0 , 'No request sent' , { reason : 'No events to send' } ) ;
6796
+ }
6797
+ return ;
6798
+ }
6799
+ if ( this . _sending ) {
6755
6800
if ( type ( callback ) === 'function' ) {
6756
- callback ( 0 , 'No request sent' ) ;
6801
+ callback ( 0 , 'No request sent' , { reason : 'Request already in progress' } ) ;
6757
6802
}
6758
6803
return ;
6759
6804
}
0 commit comments