@@ -141,6 +141,7 @@ var DEFAULT_OPTIONS = {
141141 saveEvents : true ,
142142 sessionTimeout : 30 * 60 * 1000 ,
143143 unsentKey : 'amplitude_unsent' ,
144+ unsentIdentifyKey : 'amplitude_unsent_identify' ,
144145 uploadBatchSize : 100 ,
145146 batchEvents : false ,
146147 eventUploadThreshold : 30 ,
@@ -157,6 +158,7 @@ var LocalStorageKeys = {
157158 */
158159var Amplitude = function ( ) {
159160 this . _unsentEvents = [ ] ;
161+ this . _unsentIdentifys = [ ] ;
160162 this . _ua = new UAParser ( navigator . userAgent ) . getResult ( ) ;
161163 this . options = object . merge ( { } , DEFAULT_OPTIONS ) ;
162164} ;
@@ -223,9 +225,11 @@ Amplitude.prototype.init = function(apiKey, opt_userId, opt_config) {
223225
224226 if ( this . options . saveEvents ) {
225227 var savedUnsentEventsString = localStorage . getItem ( this . options . unsentKey ) ;
228+ var savedUnsentIdentifysString = localStorage . getItem ( this . options . unsentIdentifyKey ) ;
226229 if ( savedUnsentEventsString ) {
227230 try {
228231 this . _unsentEvents = JSON . parse ( savedUnsentEventsString ) ;
232+ this . _unsentIdentifys = JSON . parse ( savedUnsentIdentifysString ) ;
229233 } catch ( e ) {
230234 //log(e);
231235 }
@@ -263,9 +267,14 @@ Amplitude.prototype.nextEventId = function() {
263267 return this . _eventId ;
264268} ;
265269
270+ // returns the number of unsent events and identifys
271+ Amplitude . prototype . _unsentCount = function ( ) {
272+ return this . _unsentEvents . length + this . _unsentIdentifys . length ;
273+ } ;
274+
266275// returns true if sendEvents called immediately
267276Amplitude . prototype . _sendEventsIfReady = function ( callback ) {
268- if ( this . _unsentEvents . length === 0 ) {
277+ if ( this . _unsentCount ( ) === 0 ) {
269278 return false ;
270279 }
271280
@@ -274,7 +283,7 @@ Amplitude.prototype._sendEventsIfReady = function(callback) {
274283 return true ;
275284 }
276285
277- if ( this . _unsentEvents . length >= this . options . eventUploadThreshold ) {
286+ if ( this . _unsentCount ( ) >= this . options . eventUploadThreshold ) {
278287 this . sendEvents ( callback ) ;
279288 return true ;
280289 }
@@ -292,9 +301,6 @@ var _loadCookieData = function(scope) {
292301 if ( cookieData . userId ) {
293302 scope . options . userId = cookieData . userId ;
294303 }
295- if ( cookieData . globalUserProperties ) {
296- scope . options . userProperties = cookieData . globalUserProperties ;
297- }
298304 if ( cookieData . optOut !== undefined ) {
299305 scope . options . optOut = cookieData . optOut ;
300306 }
@@ -305,7 +311,6 @@ var _saveCookieData = function(scope) {
305311 Cookie . set ( scope . options . cookieName , {
306312 deviceId : scope . options . deviceId ,
307313 userId : scope . options . userId ,
308- globalUserProperties : scope . options . userProperties ,
309314 optOut : scope . options . optOut
310315 } ) ;
311316} ;
@@ -359,6 +364,7 @@ Amplitude.prototype._getReferringDomain = function() {
359364Amplitude . prototype . saveEvents = function ( ) {
360365 try {
361366 localStorage . setItem ( this . options . unsentKey , JSON . stringify ( this . _unsentEvents ) ) ;
367+ localStorage . setItem ( this . options . unsentIdentifyKey , JSON . stringify ( this . _unsentIdentifys ) ) ;
362368 } catch ( e ) {
363369 //log(e);
364370 }
@@ -565,7 +571,7 @@ Amplitude.prototype.removeEvents = function (maxEventId) {
565571} ;
566572
567573Amplitude . prototype . sendEvents = function ( callback ) {
568- if ( ! this . _sending && ! this . options . optOut && this . _unsentEvents . length > 0 ) {
574+ if ( ! this . _sending && ! this . options . optOut && this . _unsentCount ( ) > 0 ) {
569575 this . _sending = true ;
570576 var url = ( 'https:' === window . location . protocol ? 'https' : 'http' ) + '://' +
571577 this . options . apiEndpoint + '/' ;
0 commit comments