@@ -5627,7 +5627,7 @@ var uuid$1 = function uuid(a) {
56275627 ) ;
56285628} ;
56295629
5630- var version = '4.2.1 ' ;
5630+ var version = '4.3.0 ' ;
56315631
56325632var getLanguage = function getLanguage ( ) {
56335633 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
57255725 this . options . domain = this . cookieStorage . options ( ) . domain ;
57265726
57275727 if ( this . _instanceName === constants . DEFAULT_INSTANCE ) {
5728- _upgradeCookeData ( this ) ;
5728+ _upgradeCookieData ( this ) ;
57295729 }
57305730 _loadCookieData ( this ) ;
57315731
@@ -6025,7 +6025,7 @@ AmplitudeClient.prototype._setInStorage = function _setInStorage(storage, key, v
60256025 * Need to unify all sources into one place with a one-time upgrade/migration.
60266026 * @private
60276027 */
6028- var _upgradeCookeData = function _upgradeCookeData ( scope ) {
6028+ var _upgradeCookieData = function _upgradeCookieData ( scope ) {
60296029 // skip if already migrated to 4.10+
60306030 var cookieData = scope . cookieStorage . get ( scope . options . cookieName + scope . _storageSuffix ) ;
60316031 if ( type ( cookieData ) === 'object' ) {
@@ -6459,7 +6459,7 @@ var _convertProxyObjectToRealObject = function _convertProxyObjectToRealObject(i
64596459AmplitudeClient . prototype . identify = function ( identify_obj , opt_callback ) {
64606460 if ( ! this . _apiKeySet ( 'identify()' ) ) {
64616461 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' } ) ;
64636463 }
64646464 return ;
64656465 }
@@ -6473,13 +6473,16 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
64736473 // only send if there are operations
64746474 if ( Object . keys ( identify_obj . userPropertiesOperations ) . length > 0 ) {
64756475 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+ }
64766480 }
64776481 } else {
64786482 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+ }
64836486 }
64846487} ;
64856488
@@ -6502,9 +6505,15 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
65026505 */
65036506AmplitudeClient . prototype . _logEvent = function _logEvent ( eventType , eventProperties , apiProperties , userProperties , groups , timestamp , callback ) {
65046507 _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 ) {
65066515 if ( type ( callback ) === 'function' ) {
6507- callback ( 0 , 'No request sent' ) ;
6516+ callback ( 0 , 'No request sent' , { reason : 'optOut is set to true' } ) ;
65086517 }
65096518 return ;
65106519 }
@@ -6568,7 +6577,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
65686577 }
65696578
65706579 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' } ) ;
65726581 }
65736582
65746583 return eventId ;
@@ -6619,9 +6628,21 @@ AmplitudeClient.prototype.logEvent = function logEvent(eventType, eventPropertie
66196628 * @example amplitudeClient.logEvent('Clicked Homepage Button', {'finished_flow': false, 'clicks': 15});
66206629 */
66216630AmplitudeClient . 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 ) ) {
66236644 if ( type ( opt_callback ) === 'function' ) {
6624- opt_callback ( 0 , 'No request sent' ) ;
6645+ opt_callback ( 0 , 'No request sent' , { reason : 'Missing eventType' } ) ;
66256646 }
66266647 return - 1 ;
66276648 }
@@ -6644,9 +6665,15 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
66446665 * @example amplitudeClient.logEventWithGroups('Clicked Button', null, {'orgId': 24});
66456666 */
66466667AmplitudeClient . prototype . logEventWithGroups = function ( eventType , eventProperties , groups , opt_callback ) {
6647- if ( ! this . _apiKeySet ( 'logEventWithGroup()' ) || ! utils . validateInput ( eventType , 'eventType' , 'string ') ) {
6668+ if ( ! this . _apiKeySet ( 'logEventWithGroups() ' ) ) {
66486669 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' } ) ;
66506677 }
66516678 return - 1 ;
66526679 }
@@ -6751,9 +6778,27 @@ var _removeEvents = function _removeEvents(scope, eventQueue, maxId) {
67516778 * Note the server response code and response body are passed to the callback as input arguments.
67526779 */
67536780AmplitudeClient . 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 ) {
67556800 if ( type ( callback ) === 'function' ) {
6756- callback ( 0 , 'No request sent' ) ;
6801+ callback ( 0 , 'No request sent' , { reason : 'Request already in progress' } ) ;
67576802 }
67586803 return ;
67596804 }
0 commit comments