@@ -120,6 +120,7 @@ var Request = require('./xhr');
120120var UAParser = require ( 'ua-parser-js' ) ;
121121var UUID = require ( './uuid' ) ;
122122var version = require ( './version' ) ;
123+ var Identify = require ( './identify' ) ;
123124
124125var log = function ( s ) {
125126 console . log ( '[Amplitude] ' + s ) ;
@@ -159,6 +160,7 @@ var Amplitude = function() {
159160 this . options = object . merge ( { } , DEFAULT_OPTIONS ) ;
160161} ;
161162
163+ Amplitude . prototype . _test = new Identify ( ) ;
162164
163165Amplitude . prototype . _eventId = 0 ;
164166Amplitude . prototype . _sending = false ;
@@ -630,7 +632,7 @@ Amplitude.prototype.__VERSION__ = version;
630632
631633module . exports = Amplitude ;
632634
633- } , { "./cookie" :3 , "json" :4 , "./language" :5 , "./localstorage" :6 , "JavaScript-MD5" :7 , "object" :8 , "./xhr" :9 , "ua-parser-js" :10 , "./uuid" :11 , "./version" :12 } ] ,
635+ } , { "./cookie" :3 , "json" :4 , "./language" :5 , "./localstorage" :6 , "JavaScript-MD5" :7 , "object" :8 , "./xhr" :9 , "ua-parser-js" :10 , "./uuid" :11 , "./version" :12 , "./identify" : 13 } ] ,
6346363 : [ function ( require , module , exports ) {
635637/*
636638 * Cookie data
@@ -757,8 +759,8 @@ module.exports = {
757759
758760} ;
759761
760- } , { "./base64" :13 , "json" :4 , "top-domain" :14 } ] ,
761- 13 : [ function ( require , module , exports ) {
762+ } , { "./base64" :14 , "json" :4 , "top-domain" :15 } ] ,
763+ 14 : [ function ( require , module , exports ) {
762764/* jshint bitwise: false */
763765/* global escape, unescape */
764766
@@ -857,8 +859,8 @@ var Base64 = {
857859
858860module . exports = Base64 ;
859861
860- } , { "./utf8" :15 } ] ,
861- 15 : [ function ( require , module , exports ) {
862+ } , { "./utf8" :16 } ] ,
863+ 16 : [ function ( require , module , exports ) {
862864/* jshint bitwise: false */
863865
864866/*
@@ -928,8 +930,8 @@ module.exports = parse && stringify
928930 ? JSON
929931 : require ( 'json-fallback' ) ;
930932
931- } , { "json-fallback" :16 } ] ,
932- 16 : [ function ( require , module , exports ) {
933+ } , { "json-fallback" :17 } ] ,
934+ 17 : [ function ( require , module , exports ) {
933935/*
934936 json2.js
935937 2014-02-04
@@ -1419,7 +1421,7 @@ module.exports = parse && stringify
14191421} ( ) ) ;
14201422
14211423} , { } ] ,
1422- 14 : [ function ( require , module , exports ) {
1424+ 15 : [ function ( require , module , exports ) {
14231425
14241426/**
14251427 * Module dependencies.
@@ -1467,8 +1469,8 @@ function domain(url){
14671469 return match ? match [ 0 ] : '' ;
14681470} ;
14691471
1470- } , { "url" :17 } ] ,
1471- 17 : [ function ( require , module , exports ) {
1472+ } , { "url" :18 } ] ,
1473+ 18 : [ function ( require , module , exports ) {
14721474
14731475/**
14741476 * Parse the given `url`.
@@ -2063,8 +2065,8 @@ Request.prototype.send = function(callback) {
20632065
20642066module . exports = Request ;
20652067
2066- } , { "querystring" :18 } ] ,
2067- 18 : [ function ( require , module , exports ) {
2068+ } , { "querystring" :19 } ] ,
2069+ 19 : [ function ( require , module , exports ) {
20682070
20692071/**
20702072 * Module dependencies.
@@ -2139,8 +2141,8 @@ exports.stringify = function(obj){
21392141 return pairs . join ( '&' ) ;
21402142} ;
21412143
2142- } , { "trim" :19 , "type" :20 } ] ,
2143- 19 : [ function ( require , module , exports ) {
2144+ } , { "trim" :20 , "type" :21 } ] ,
2145+ 20 : [ function ( require , module , exports ) {
21442146
21452147exports = module . exports = trim ;
21462148
@@ -2160,7 +2162,7 @@ exports.right = function(str){
21602162} ;
21612163
21622164} , { } ] ,
2163- 20 : [ function ( require , module , exports ) {
2165+ 21 : [ function ( require , module , exports ) {
21642166/**
21652167 * toString ref.
21662168 */
@@ -3117,5 +3119,65 @@ module.exports = uuid;
3117311912 : [ function ( require , module , exports ) {
31183120module . exports = '2.3.0' ;
31193121
3122+ } , { } ] ,
3123+ 13 : [ function ( require , module , exports ) {
3124+ // var querystring = require('querystring');
3125+
3126+ /*
3127+ * Wrapper for a user properties JSON object that supports operations
3128+ */
3129+
3130+ var AMP_OP_ADD = '$add' ;
3131+ var AMP_OP_SET = '$set' ;
3132+ var AMP_OP_SET_ONCE = '$setOnce' ;
3133+ var AMP_OP_UNSET = '$unset' ;
3134+
3135+
3136+ var Identify = function ( ) {
3137+ this . userPropertiesOperations = { } ;
3138+ this . properties = [ ] ; // keep track of keys that have been added
3139+ } ;
3140+
3141+ var isNumeric = function ( n ) {
3142+ return ! isNaN ( parseFloat ( n ) ) && isFinite ( n ) ;
3143+ } ;
3144+
3145+ Identify . prototype . add = function ( property , value ) {
3146+ if ( isNumeric ( value ) || typeof ( value ) === 'string' || value instanceof String ) {
3147+ this . _addOperation ( AMP_OP_ADD , property , value ) ;
3148+ }
3149+ return this ;
3150+ } ;
3151+
3152+ Identify . prototype . set = function ( property , value ) {
3153+ this . _addOperation ( AMP_OP_SET , property , value ) ;
3154+ return this ;
3155+ } ;
3156+
3157+ Identify . prototype . setOnce = function ( property , value ) {
3158+ this . _addOperation ( AMP_OP_SET_ONCE , property , value ) ;
3159+ return this ;
3160+ } ;
3161+
3162+ Identify . prototype . unset = function ( property ) {
3163+ this . _addOperation ( AMP_OP_UNSET , property , '-' ) ;
3164+ return this ;
3165+ } ;
3166+
3167+ Identify . prototype . _addOperation = function ( operation , property , value ) {
3168+ // check that property wasn't already used in this Identify
3169+ if ( this . properties . indexOf ( property ) !== - 1 ) {
3170+ return ;
3171+ }
3172+
3173+ if ( ! ( operation in this . userPropertiesOperations ) ) {
3174+ this . userPropertiesOperations [ operation ] = { } ;
3175+ }
3176+ this . userPropertiesOperations [ operation ] [ property ] = value ;
3177+ this . properties . push ( property ) ;
3178+ } ;
3179+
3180+ module . exports = Identify ;
3181+
31203182} , { } ] } , { } , { "1" :"" } )
31213183) ;
0 commit comments