mixpanel-browser 2.47.0 → 2.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/dist/mixpanel.amd.js +115 -76
- package/dist/mixpanel.cjs.js +115 -76
- package/dist/mixpanel.globals.js +115 -76
- package/dist/mixpanel.min.js +103 -102
- package/dist/mixpanel.umd.js +115 -76
- package/doc/readme.io/javascript-full-api-reference.md +31 -1
- package/package.json +1 -1
- package/src/config.js +1 -1
- package/src/mixpanel-core.js +83 -44
- package/src/mixpanel-group.js +1 -1
- package/src/mixpanel-people.js +9 -7
- package/src/mixpanel-persistence.js +20 -23
- package/src/utils.js +1 -0
package/src/mixpanel-core.js
CHANGED
|
@@ -81,11 +81,18 @@ if (navigator['sendBeacon']) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
var DEFAULT_API_ROUTES = {
|
|
85
|
+
'track': 'track/',
|
|
86
|
+
'engage': 'engage/',
|
|
87
|
+
'groups': 'groups/'
|
|
88
|
+
};
|
|
89
|
+
|
|
84
90
|
/*
|
|
85
91
|
* Module-level globals
|
|
86
92
|
*/
|
|
87
93
|
var DEFAULT_CONFIG = {
|
|
88
94
|
'api_host': 'https://api-js.mixpanel.com',
|
|
95
|
+
'api_routes': DEFAULT_API_ROUTES,
|
|
89
96
|
'api_method': 'POST',
|
|
90
97
|
'api_transport': 'XHR',
|
|
91
98
|
'api_payload_format': PAYLOAD_TYPE_BASE64,
|
|
@@ -284,6 +291,10 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
284
291
|
if (!_.localStorage.is_supported(true) || !USE_XHR) {
|
|
285
292
|
this._batch_requests = false;
|
|
286
293
|
console.log('Turning off Mixpanel request-queueing; needs XHR and localStorage support');
|
|
294
|
+
_.each(this.get_batcher_configs(), function(batcher_config) {
|
|
295
|
+
console.log('Clearing batch queue ' + batcher_config.queue_key);
|
|
296
|
+
_.localStorage.remove(batcher_config.queue_key);
|
|
297
|
+
});
|
|
287
298
|
} else {
|
|
288
299
|
this.init_batchers();
|
|
289
300
|
if (sendBeacon && window.addEventListener) {
|
|
@@ -348,7 +359,7 @@ MixpanelLib.prototype._loaded = function() {
|
|
|
348
359
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
349
360
|
this['persistence'].update_search_keyword(document.referrer);
|
|
350
361
|
if (this.get_config('store_google')) {
|
|
351
|
-
this.register(_.info.campaignParams()
|
|
362
|
+
this.register(_.info.campaignParams());
|
|
352
363
|
}
|
|
353
364
|
if (this.get_config('save_referrer')) {
|
|
354
365
|
this['persistence'].update_referrer_info(document.referrer);
|
|
@@ -631,12 +642,22 @@ MixpanelLib.prototype.are_batchers_initialized = function() {
|
|
|
631
642
|
return !!this.request_batchers.events;
|
|
632
643
|
};
|
|
633
644
|
|
|
645
|
+
MixpanelLib.prototype.get_batcher_configs = function() {
|
|
646
|
+
var queue_prefix = '__mpq_' + this.get_config('token');
|
|
647
|
+
var api_routes = this.get_config('api_routes');
|
|
648
|
+
this._batcher_configs = this._batcher_configs || {
|
|
649
|
+
events: {type: 'events', endpoint: '/' + api_routes['track'], queue_key: queue_prefix + '_ev'},
|
|
650
|
+
people: {type: 'people', endpoint: '/' + api_routes['engage'], queue_key: queue_prefix + '_pp'},
|
|
651
|
+
groups: {type: 'groups', endpoint: '/' + api_routes['groups'], queue_key: queue_prefix + '_gr'}
|
|
652
|
+
};
|
|
653
|
+
return this._batcher_configs;
|
|
654
|
+
};
|
|
655
|
+
|
|
634
656
|
MixpanelLib.prototype.init_batchers = function() {
|
|
635
|
-
var token = this.get_config('token');
|
|
636
657
|
if (!this.are_batchers_initialized()) {
|
|
637
658
|
var batcher_for = _.bind(function(attrs) {
|
|
638
659
|
return new RequestBatcher(
|
|
639
|
-
|
|
660
|
+
attrs.queue_key,
|
|
640
661
|
{
|
|
641
662
|
libConfig: this['config'],
|
|
642
663
|
sendRequestFunc: _.bind(function(data, options, cb) {
|
|
@@ -655,10 +676,11 @@ MixpanelLib.prototype.init_batchers = function() {
|
|
|
655
676
|
}
|
|
656
677
|
);
|
|
657
678
|
}, this);
|
|
679
|
+
var batcher_configs = this.get_batcher_configs();
|
|
658
680
|
this.request_batchers = {
|
|
659
|
-
events: batcher_for(
|
|
660
|
-
people: batcher_for(
|
|
661
|
-
groups: batcher_for(
|
|
681
|
+
events: batcher_for(batcher_configs.events),
|
|
682
|
+
people: batcher_for(batcher_configs.people),
|
|
683
|
+
groups: batcher_for(batcher_configs.groups)
|
|
662
684
|
};
|
|
663
685
|
}
|
|
664
686
|
if (this.get_config('batch_autostart')) {
|
|
@@ -667,6 +689,7 @@ MixpanelLib.prototype.init_batchers = function() {
|
|
|
667
689
|
};
|
|
668
690
|
|
|
669
691
|
MixpanelLib.prototype.start_batch_senders = function() {
|
|
692
|
+
this._batchers_were_started = true;
|
|
670
693
|
if (this.are_batchers_initialized()) {
|
|
671
694
|
this._batch_requests = true;
|
|
672
695
|
_.each(this.request_batchers, function(batcher) {
|
|
@@ -818,7 +841,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
818
841
|
}
|
|
819
842
|
|
|
820
843
|
// set defaults
|
|
821
|
-
properties =
|
|
844
|
+
properties = _.extend({}, properties);
|
|
822
845
|
properties['token'] = this.get_config('token');
|
|
823
846
|
|
|
824
847
|
// set $duration if time_event was previously called for this event
|
|
@@ -864,7 +887,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
864
887
|
var ret = this._track_or_batch({
|
|
865
888
|
type: 'events',
|
|
866
889
|
data: data,
|
|
867
|
-
endpoint: this.get_config('api_host') + '/track
|
|
890
|
+
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
|
|
868
891
|
batcher: this.request_batchers.events,
|
|
869
892
|
should_send_immediately: should_send_immediately,
|
|
870
893
|
send_request_options: options
|
|
@@ -910,13 +933,14 @@ MixpanelLib.prototype.set_group = addOptOutCheckMixpanelLib(function(group_key,
|
|
|
910
933
|
*/
|
|
911
934
|
MixpanelLib.prototype.add_group = addOptOutCheckMixpanelLib(function(group_key, group_id, callback) {
|
|
912
935
|
var old_values = this.get_property(group_key);
|
|
936
|
+
var prop = {};
|
|
913
937
|
if (old_values === undefined) {
|
|
914
|
-
var prop = {};
|
|
915
938
|
prop[group_key] = [group_id];
|
|
916
939
|
this.register(prop);
|
|
917
940
|
} else {
|
|
918
941
|
if (old_values.indexOf(group_id) === -1) {
|
|
919
942
|
old_values.push(group_id);
|
|
943
|
+
prop[group_key] = old_values;
|
|
920
944
|
this.register(prop);
|
|
921
945
|
}
|
|
922
946
|
}
|
|
@@ -1461,6 +1485,16 @@ MixpanelLib.prototype.name_tag = function(name_tag) {
|
|
|
1461
1485
|
* The default config is:
|
|
1462
1486
|
*
|
|
1463
1487
|
* {
|
|
1488
|
+
* // host for requests (customizable for e.g. a local proxy)
|
|
1489
|
+
* api_host: 'https://api-js.mixpanel.com',
|
|
1490
|
+
*
|
|
1491
|
+
* // endpoints for different types of requests
|
|
1492
|
+
* api_routes: {
|
|
1493
|
+
* track: 'track/',
|
|
1494
|
+
* engage: 'engage/',
|
|
1495
|
+
* groups: 'groups/',
|
|
1496
|
+
* }
|
|
1497
|
+
*
|
|
1464
1498
|
* // HTTP method for tracking requests
|
|
1465
1499
|
* api_method: 'POST'
|
|
1466
1500
|
*
|
|
@@ -1644,7 +1678,7 @@ MixpanelLib.prototype._run_hook = function(hook_name) {
|
|
|
1644
1678
|
* @param {String} property_name The name of the super property you want to retrieve
|
|
1645
1679
|
*/
|
|
1646
1680
|
MixpanelLib.prototype.get_property = function(property_name) {
|
|
1647
|
-
return this['persistence'][
|
|
1681
|
+
return this['persistence'].load_prop([property_name]);
|
|
1648
1682
|
};
|
|
1649
1683
|
|
|
1650
1684
|
MixpanelLib.prototype.toString = function() {
|
|
@@ -1717,9 +1751,13 @@ MixpanelLib.prototype._gdpr_update_persistence = function(options) {
|
|
|
1717
1751
|
}
|
|
1718
1752
|
|
|
1719
1753
|
if (disabled) {
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1754
|
+
this.stop_batch_senders();
|
|
1755
|
+
} else {
|
|
1756
|
+
// only start batchers after opt-in if they have previously been started
|
|
1757
|
+
// in order to avoid unintentionally starting up batching for the first time
|
|
1758
|
+
if (this._batchers_were_started) {
|
|
1759
|
+
this.start_batch_senders();
|
|
1760
|
+
}
|
|
1723
1761
|
}
|
|
1724
1762
|
};
|
|
1725
1763
|
|
|
@@ -1921,37 +1959,38 @@ MixpanelLib.prototype.report_error = function(msg, err) {
|
|
|
1921
1959
|
// EXPORTS (for closure compiler)
|
|
1922
1960
|
|
|
1923
1961
|
// MixpanelLib Exports
|
|
1924
|
-
MixpanelLib.prototype['init']
|
|
1925
|
-
MixpanelLib.prototype['reset']
|
|
1926
|
-
MixpanelLib.prototype['disable']
|
|
1927
|
-
MixpanelLib.prototype['time_event']
|
|
1928
|
-
MixpanelLib.prototype['track']
|
|
1929
|
-
MixpanelLib.prototype['track_links']
|
|
1930
|
-
MixpanelLib.prototype['track_forms']
|
|
1931
|
-
MixpanelLib.prototype['track_pageview']
|
|
1932
|
-
MixpanelLib.prototype['register']
|
|
1933
|
-
MixpanelLib.prototype['register_once']
|
|
1934
|
-
MixpanelLib.prototype['unregister']
|
|
1935
|
-
MixpanelLib.prototype['identify']
|
|
1936
|
-
MixpanelLib.prototype['alias']
|
|
1937
|
-
MixpanelLib.prototype['name_tag']
|
|
1938
|
-
MixpanelLib.prototype['set_config']
|
|
1939
|
-
MixpanelLib.prototype['get_config']
|
|
1940
|
-
MixpanelLib.prototype['get_property']
|
|
1941
|
-
MixpanelLib.prototype['get_distinct_id']
|
|
1942
|
-
MixpanelLib.prototype['toString']
|
|
1943
|
-
MixpanelLib.prototype['opt_out_tracking']
|
|
1944
|
-
MixpanelLib.prototype['opt_in_tracking']
|
|
1945
|
-
MixpanelLib.prototype['has_opted_out_tracking']
|
|
1946
|
-
MixpanelLib.prototype['has_opted_in_tracking']
|
|
1947
|
-
MixpanelLib.prototype['clear_opt_in_out_tracking']
|
|
1948
|
-
MixpanelLib.prototype['get_group']
|
|
1949
|
-
MixpanelLib.prototype['set_group']
|
|
1950
|
-
MixpanelLib.prototype['add_group']
|
|
1951
|
-
MixpanelLib.prototype['remove_group']
|
|
1952
|
-
MixpanelLib.prototype['track_with_groups']
|
|
1953
|
-
MixpanelLib.prototype['start_batch_senders']
|
|
1954
|
-
MixpanelLib.prototype['stop_batch_senders']
|
|
1962
|
+
MixpanelLib.prototype['init'] = MixpanelLib.prototype.init;
|
|
1963
|
+
MixpanelLib.prototype['reset'] = MixpanelLib.prototype.reset;
|
|
1964
|
+
MixpanelLib.prototype['disable'] = MixpanelLib.prototype.disable;
|
|
1965
|
+
MixpanelLib.prototype['time_event'] = MixpanelLib.prototype.time_event;
|
|
1966
|
+
MixpanelLib.prototype['track'] = MixpanelLib.prototype.track;
|
|
1967
|
+
MixpanelLib.prototype['track_links'] = MixpanelLib.prototype.track_links;
|
|
1968
|
+
MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
|
|
1969
|
+
MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
|
|
1970
|
+
MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
|
|
1971
|
+
MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
|
|
1972
|
+
MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
|
|
1973
|
+
MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
|
|
1974
|
+
MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
|
|
1975
|
+
MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
|
|
1976
|
+
MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
|
|
1977
|
+
MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
|
|
1978
|
+
MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
|
|
1979
|
+
MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
|
|
1980
|
+
MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
|
|
1981
|
+
MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
|
|
1982
|
+
MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
|
|
1983
|
+
MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
|
|
1984
|
+
MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
|
|
1985
|
+
MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
|
|
1986
|
+
MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
|
|
1987
|
+
MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
|
|
1988
|
+
MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
|
|
1989
|
+
MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
|
|
1990
|
+
MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
|
|
1991
|
+
MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
|
|
1992
|
+
MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
|
|
1993
|
+
MixpanelLib.prototype['DEFAULT_API_ROUTES'] = DEFAULT_API_ROUTES;
|
|
1955
1994
|
|
|
1956
1995
|
// MixpanelPersistence Exports
|
|
1957
1996
|
MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
|
package/src/mixpanel-group.js
CHANGED
|
@@ -146,7 +146,7 @@ MixpanelGroup.prototype._send_request = function(data, callback) {
|
|
|
146
146
|
return this._mixpanel._track_or_batch({
|
|
147
147
|
type: 'groups',
|
|
148
148
|
data: date_encoded_data,
|
|
149
|
-
endpoint: this._get_config('api_host') + '/groups
|
|
149
|
+
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['groups'],
|
|
150
150
|
batcher: this._mixpanel.request_batchers.groups
|
|
151
151
|
}, callback);
|
|
152
152
|
};
|
package/src/mixpanel-people.js
CHANGED
|
@@ -348,7 +348,7 @@ MixpanelPeople.prototype._send_request = function(data, callback) {
|
|
|
348
348
|
return this._mixpanel._track_or_batch({
|
|
349
349
|
type: 'people',
|
|
350
350
|
data: date_encoded_data,
|
|
351
|
-
endpoint: this._get_config('api_host') + '/engage
|
|
351
|
+
endpoint: this._get_config('api_host') + '/' + this._get_config('api_routes')['engage'],
|
|
352
352
|
batcher: this._mixpanel.request_batchers.people
|
|
353
353
|
}, callback);
|
|
354
354
|
};
|
|
@@ -384,11 +384,12 @@ MixpanelPeople.prototype._enqueue = function(data) {
|
|
|
384
384
|
|
|
385
385
|
MixpanelPeople.prototype._flush_one_queue = function(action, action_method, callback, queue_to_params_fn) {
|
|
386
386
|
var _this = this;
|
|
387
|
-
var queued_data = _.extend({}, this._mixpanel['persistence'].
|
|
387
|
+
var queued_data = _.extend({}, this._mixpanel['persistence'].load_queue(action));
|
|
388
388
|
var action_params = queued_data;
|
|
389
389
|
|
|
390
390
|
if (!_.isUndefined(queued_data) && _.isObject(queued_data) && !_.isEmptyObject(queued_data)) {
|
|
391
391
|
_this._mixpanel['persistence']._pop_from_people_queue(action, queued_data);
|
|
392
|
+
_this._mixpanel['persistence'].save();
|
|
392
393
|
if (queue_to_params_fn) {
|
|
393
394
|
action_params = queue_to_params_fn(queued_data);
|
|
394
395
|
}
|
|
@@ -410,8 +411,6 @@ MixpanelPeople.prototype._flush = function(
|
|
|
410
411
|
_set_callback, _add_callback, _append_callback, _set_once_callback, _union_callback, _unset_callback, _remove_callback
|
|
411
412
|
) {
|
|
412
413
|
var _this = this;
|
|
413
|
-
var $append_queue = this._mixpanel['persistence']._get_queue(APPEND_ACTION);
|
|
414
|
-
var $remove_queue = this._mixpanel['persistence']._get_queue(REMOVE_ACTION);
|
|
415
414
|
|
|
416
415
|
this._flush_one_queue(SET_ACTION, this.set, _set_callback);
|
|
417
416
|
this._flush_one_queue(SET_ONCE_ACTION, this.set_once, _set_once_callback);
|
|
@@ -421,6 +420,7 @@ MixpanelPeople.prototype._flush = function(
|
|
|
421
420
|
|
|
422
421
|
// we have to fire off each $append individually since there is
|
|
423
422
|
// no concat method server side
|
|
423
|
+
var $append_queue = this._mixpanel['persistence'].load_queue(APPEND_ACTION);
|
|
424
424
|
if (!_.isUndefined($append_queue) && _.isArray($append_queue) && $append_queue.length) {
|
|
425
425
|
var $append_item;
|
|
426
426
|
var append_callback = function(response, data) {
|
|
@@ -432,16 +432,17 @@ MixpanelPeople.prototype._flush = function(
|
|
|
432
432
|
}
|
|
433
433
|
};
|
|
434
434
|
for (var i = $append_queue.length - 1; i >= 0; i--) {
|
|
435
|
+
$append_queue = this._mixpanel['persistence'].load_queue(APPEND_ACTION);
|
|
435
436
|
$append_item = $append_queue.pop();
|
|
437
|
+
_this._mixpanel['persistence'].save();
|
|
436
438
|
if (!_.isEmptyObject($append_item)) {
|
|
437
439
|
_this.append($append_item, append_callback);
|
|
438
440
|
}
|
|
439
441
|
}
|
|
440
|
-
// Save the shortened append queue
|
|
441
|
-
_this._mixpanel['persistence'].save();
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
// same for $remove
|
|
445
|
+
var $remove_queue = this._mixpanel['persistence'].load_queue(REMOVE_ACTION);
|
|
445
446
|
if (!_.isUndefined($remove_queue) && _.isArray($remove_queue) && $remove_queue.length) {
|
|
446
447
|
var $remove_item;
|
|
447
448
|
var remove_callback = function(response, data) {
|
|
@@ -453,12 +454,13 @@ MixpanelPeople.prototype._flush = function(
|
|
|
453
454
|
}
|
|
454
455
|
};
|
|
455
456
|
for (var j = $remove_queue.length - 1; j >= 0; j--) {
|
|
457
|
+
$remove_queue = this._mixpanel['persistence'].load_queue(REMOVE_ACTION);
|
|
456
458
|
$remove_item = $remove_queue.pop();
|
|
459
|
+
_this._mixpanel['persistence'].save();
|
|
457
460
|
if (!_.isEmptyObject($remove_item)) {
|
|
458
461
|
_this.remove($remove_item, remove_callback);
|
|
459
462
|
}
|
|
460
463
|
}
|
|
461
|
-
_this._mixpanel['persistence'].save();
|
|
462
464
|
}
|
|
463
465
|
};
|
|
464
466
|
|
|
@@ -72,6 +72,9 @@ var MixpanelPersistence = function(config) {
|
|
|
72
72
|
|
|
73
73
|
MixpanelPersistence.prototype.properties = function() {
|
|
74
74
|
var p = {};
|
|
75
|
+
|
|
76
|
+
this.load();
|
|
77
|
+
|
|
75
78
|
// Filter out reserved properties
|
|
76
79
|
_.each(this['props'], function(v, k) {
|
|
77
80
|
if (!_.include(RESERVED_PROPERTIES, k)) {
|
|
@@ -148,6 +151,7 @@ MixpanelPersistence.prototype.upgrade = function(config) {
|
|
|
148
151
|
|
|
149
152
|
MixpanelPersistence.prototype.save = function() {
|
|
150
153
|
if (this.disabled) { return; }
|
|
154
|
+
|
|
151
155
|
this.storage.set(
|
|
152
156
|
this.name,
|
|
153
157
|
_.JSONEncode(this['props']),
|
|
@@ -159,6 +163,11 @@ MixpanelPersistence.prototype.save = function() {
|
|
|
159
163
|
);
|
|
160
164
|
};
|
|
161
165
|
|
|
166
|
+
MixpanelPersistence.prototype.load_prop = function(key) {
|
|
167
|
+
this.load();
|
|
168
|
+
return this['props'][key];
|
|
169
|
+
};
|
|
170
|
+
|
|
162
171
|
MixpanelPersistence.prototype.remove = function() {
|
|
163
172
|
// remove both domain and subdomain cookies
|
|
164
173
|
this.storage.remove(this.name, false, this.cookie_domain);
|
|
@@ -182,6 +191,8 @@ MixpanelPersistence.prototype.register_once = function(props, default_value, day
|
|
|
182
191
|
if (typeof(default_value) === 'undefined') { default_value = 'None'; }
|
|
183
192
|
this.expire_days = (typeof(days) === 'undefined') ? this.default_expiry : days;
|
|
184
193
|
|
|
194
|
+
this.load();
|
|
195
|
+
|
|
185
196
|
_.each(props, function(val, prop) {
|
|
186
197
|
if (!this['props'].hasOwnProperty(prop) || this['props'][prop] === default_value) {
|
|
187
198
|
this['props'][prop] = val;
|
|
@@ -203,8 +214,8 @@ MixpanelPersistence.prototype.register = function(props, days) {
|
|
|
203
214
|
if (_.isObject(props)) {
|
|
204
215
|
this.expire_days = (typeof(days) === 'undefined') ? this.default_expiry : days;
|
|
205
216
|
|
|
217
|
+
this.load();
|
|
206
218
|
_.extend(this['props'], props);
|
|
207
|
-
|
|
208
219
|
this.save();
|
|
209
220
|
|
|
210
221
|
return true;
|
|
@@ -213,6 +224,7 @@ MixpanelPersistence.prototype.register = function(props, days) {
|
|
|
213
224
|
};
|
|
214
225
|
|
|
215
226
|
MixpanelPersistence.prototype.unregister = function(prop) {
|
|
227
|
+
this.load();
|
|
216
228
|
if (prop in this['props']) {
|
|
217
229
|
delete this['props'][prop];
|
|
218
230
|
this.save();
|
|
@@ -239,19 +251,6 @@ MixpanelPersistence.prototype.get_referrer_info = function() {
|
|
|
239
251
|
});
|
|
240
252
|
};
|
|
241
253
|
|
|
242
|
-
// safely fills the passed in object with stored properties,
|
|
243
|
-
// does not override any properties defined in both
|
|
244
|
-
// returns the passed in object
|
|
245
|
-
MixpanelPersistence.prototype.safe_merge = function(props) {
|
|
246
|
-
_.each(this['props'], function(val, prop) {
|
|
247
|
-
if (!(prop in props)) {
|
|
248
|
-
props[prop] = val;
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
return props;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
254
|
MixpanelPersistence.prototype.update_config = function(config) {
|
|
256
255
|
this.default_expiry = this.expire_days = config['cookie_expiration'];
|
|
257
256
|
this.set_disabled(config['disable_persistence']);
|
|
@@ -395,7 +394,7 @@ MixpanelPersistence.prototype._add_to_people_queue = function(queue, data) {
|
|
|
395
394
|
};
|
|
396
395
|
|
|
397
396
|
MixpanelPersistence.prototype._pop_from_people_queue = function(queue, data) {
|
|
398
|
-
var q = this.
|
|
397
|
+
var q = this['props'][this._get_queue_key(queue)];
|
|
399
398
|
if (!_.isUndefined(q)) {
|
|
400
399
|
_.each(data, function(v, k) {
|
|
401
400
|
if (queue === APPEND_ACTION || queue === REMOVE_ACTION) {
|
|
@@ -411,11 +410,13 @@ MixpanelPersistence.prototype._pop_from_people_queue = function(queue, data) {
|
|
|
411
410
|
delete q[k];
|
|
412
411
|
}
|
|
413
412
|
}, this);
|
|
414
|
-
|
|
415
|
-
this.save();
|
|
416
413
|
}
|
|
417
414
|
};
|
|
418
415
|
|
|
416
|
+
MixpanelPersistence.prototype.load_queue = function(queue) {
|
|
417
|
+
return this.load_prop(this._get_queue_key(queue));
|
|
418
|
+
};
|
|
419
|
+
|
|
419
420
|
MixpanelPersistence.prototype._get_queue_key = function(queue) {
|
|
420
421
|
if (queue === SET_ACTION) {
|
|
421
422
|
return SET_QUEUE_KEY;
|
|
@@ -436,25 +437,21 @@ MixpanelPersistence.prototype._get_queue_key = function(queue) {
|
|
|
436
437
|
}
|
|
437
438
|
};
|
|
438
439
|
|
|
439
|
-
MixpanelPersistence.prototype._get_queue = function(queue) {
|
|
440
|
-
return this['props'][this._get_queue_key(queue)];
|
|
441
|
-
};
|
|
442
440
|
MixpanelPersistence.prototype._get_or_create_queue = function(queue, default_val) {
|
|
443
441
|
var key = this._get_queue_key(queue);
|
|
444
442
|
default_val = _.isUndefined(default_val) ? {} : default_val;
|
|
445
|
-
|
|
446
443
|
return this['props'][key] || (this['props'][key] = default_val);
|
|
447
444
|
};
|
|
448
445
|
|
|
449
446
|
MixpanelPersistence.prototype.set_event_timer = function(event_name, timestamp) {
|
|
450
|
-
var timers = this
|
|
447
|
+
var timers = this.load_prop(EVENT_TIMERS_KEY) || {};
|
|
451
448
|
timers[event_name] = timestamp;
|
|
452
449
|
this['props'][EVENT_TIMERS_KEY] = timers;
|
|
453
450
|
this.save();
|
|
454
451
|
};
|
|
455
452
|
|
|
456
453
|
MixpanelPersistence.prototype.remove_event_timer = function(event_name) {
|
|
457
|
-
var timers = this
|
|
454
|
+
var timers = this.load_prop(EVENT_TIMERS_KEY) || {};
|
|
458
455
|
var timestamp = timers[event_name];
|
|
459
456
|
if (!_.isUndefined(timestamp)) {
|
|
460
457
|
delete this['props'][EVENT_TIMERS_KEY][event_name];
|