@@ -464,13 +464,21 @@ Amplitude.prototype.setUserProperties = function(userProperties) {
464464} ;
465465
466466Amplitude . prototype . identify = function ( identify ) {
467+
468+ if ( type ( identify ) === 'object' && '_q' in identify ) {
469+ var instance = new Identify ( ) ;
470+ // Apply the queued commands
471+ for ( var i = 0 ; i < identify . _q . length ; i ++ ) {
472+ var fn = instance [ identify . _q [ i ] [ 0 ] ] ;
473+ if ( fn && type ( fn ) === 'function' ) {
474+ fn . apply ( instance , identify . _q [ i ] . slice ( 1 ) ) ;
475+ }
476+ }
477+ identify = instance ;
478+ }
479+
467480 if ( identify instanceof Identify && Object . keys ( identify . userPropertiesOperations ) . length > 0 ) {
468481 this . _logEvent ( IDENTIFY_EVENT , null , null , identify . userPropertiesOperations ) ;
469- } else if ( type ( identify ) === 'object' && 'p' in identify ) {
470- var identifyObject = new Identify ( ) . fromProxyObject ( identify ) ;
471- if ( Object . keys ( identifyObject . userPropertiesOperations ) . length > 0 ) {
472- this . _logEvent ( IDENTIFY_EVENT , null , null , identifyObject . userPropertiesOperations ) ;
473- }
474482 }
475483} ;
476484
@@ -3295,14 +3303,10 @@ var type = require('./type');
32953303 * only the first operation will be saved, and the rest will be ignored.
32963304 */
32973305
3298- // maps operation to identify string and proxy key
3299- // order listed also defines order of processing
3300- var OPERATIONS = {
3301- 'AMP_OP_SET_ONCE' : { 'opString' : '$setOnce' , 'proxyKey' : 'so' } ,
3302- 'AMP_OP_UNSET' : { 'opString' : '$unset' , 'proxyKey' : 'u' } ,
3303- 'AMP_OP_SET' : { 'opString' : '$set' , 'proxyKey' : 's' } ,
3304- 'AMP_OP_ADD' : { 'opString' : '$add' , 'proxyKey' : 'a' }
3305- } ;
3306+ var AMP_OP_ADD = '$add' ;
3307+ var AMP_OP_SET = '$set' ;
3308+ var AMP_OP_SET_ONCE = '$setOnce' ;
3309+ var AMP_OP_UNSET = '$unset' ;
33063310
33073311var log = function ( s ) {
33083312 console . log ( '[Amplitude] ' + s ) ;
@@ -3313,63 +3317,41 @@ var Identify = function() {
33133317 this . properties = [ ] ; // keep track of keys that have been added
33143318} ;
33153319
3316- Identify . prototype . fromProxyObject = function ( proxyObject ) {
3317- if ( ! ( 'p' in proxyObject ) ) {
3318- return this ;
3319- }
3320- Object . keys ( OPERATIONS ) . forEach ( function ( operation ) {
3321- this . _addOperationsFromProxyObjectDictionary ( operation , proxyObject . p ) ;
3322- } . bind ( this ) ) ;
3323- return this ;
3324- } ;
3325-
3326- Identify . prototype . _addOperationsFromProxyObjectDictionary = function ( operation , proxyObjectDict ) {
3327- var proxyKey = OPERATIONS [ operation ] . proxyKey ;
3328- if ( ! ( proxyKey in proxyObjectDict ) ) {
3329- return ;
3330- }
3331- var userPropertiesOperations = proxyObjectDict [ proxyKey ] ;
3332- Object . keys ( userPropertiesOperations ) . forEach ( function ( key ) {
3333- this . _addOperation ( operation , key , userPropertiesOperations [ key ] ) ;
3334- } . bind ( this ) ) ;
3335- } ;
3336-
33373320Identify . prototype . add = function ( property , value ) {
33383321 if ( type ( value ) === 'number' || type ( value ) === 'string' ) {
3339- this . _addOperation ( ' AMP_OP_ADD' , property , value ) ;
3322+ this . _addOperation ( AMP_OP_ADD , property , value ) ;
33403323 } else {
33413324 log ( 'Unsupported type for value: ' + type ( value ) + ', expecting number or string' ) ;
33423325 }
33433326 return this ;
33443327} ;
33453328
33463329Identify . prototype . set = function ( property , value ) {
3347- this . _addOperation ( ' AMP_OP_SET' , property , value ) ;
3330+ this . _addOperation ( AMP_OP_SET , property , value ) ;
33483331 return this ;
33493332} ;
33503333
33513334Identify . prototype . setOnce = function ( property , value ) {
3352- this . _addOperation ( ' AMP_OP_SET_ONCE' , property , value ) ;
3335+ this . _addOperation ( AMP_OP_SET_ONCE , property , value ) ;
33533336 return this ;
33543337} ;
33553338
33563339Identify . prototype . unset = function ( property ) {
3357- this . _addOperation ( ' AMP_OP_UNSET' , property , '-' ) ;
3340+ this . _addOperation ( AMP_OP_UNSET , property , '-' ) ;
33583341 return this ;
33593342} ;
33603343
33613344Identify . prototype . _addOperation = function ( operation , property , value ) {
3362- var opString = OPERATIONS [ operation ] . opString ;
33633345 // check that property wasn't already used in this Identify
33643346 if ( this . properties . indexOf ( property ) !== - 1 ) {
3365- log ( 'User property "' + property + '" already used in this identify, skipping operation ' + opString ) ;
3347+ log ( 'User property "' + property + '" already used in this identify, skipping operation ' + operation ) ;
33663348 return ;
33673349 }
33683350
3369- if ( ! ( opString in this . userPropertiesOperations ) ) {
3370- this . userPropertiesOperations [ opString ] = { } ;
3351+ if ( ! ( operation in this . userPropertiesOperations ) ) {
3352+ this . userPropertiesOperations [ operation ] = { } ;
33713353 }
3372- this . userPropertiesOperations [ opString ] [ property ] = value ;
3354+ this . userPropertiesOperations [ operation ] [ property ] = value ;
33733355 this . properties . push ( property ) ;
33743356} ;
33753357
0 commit comments