mixpanel-browser 2.46.0 → 2.48.0
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/.github/workflows/tests.yml +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/mixpanel.amd.js +250 -114
- package/dist/mixpanel.cjs.js +250 -114
- package/dist/mixpanel.globals.js +250 -114
- package/dist/mixpanel.min.js +105 -102
- package/dist/mixpanel.umd.js +250 -114
- 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 +171 -54
- package/src/mixpanel-group.js +1 -1
- package/src/mixpanel-people.js +9 -7
- package/src/mixpanel-persistence.js +20 -30
- package/src/utils.js +48 -21
|
@@ -262,7 +262,7 @@ mixpanel.library_name.track(...);
|
|
|
262
262
|
| Argument | Type | Description |
|
|
263
263
|
| ------------- | ------------- | ----- |
|
|
264
264
|
| **token** | <span class="mp-arg-type">String</span></br></span><span class="mp-arg-required">required</span> | Your Mixpanel API token |
|
|
265
|
-
| **config** | <span class="mp-arg-type">Object</span></br></span><span class="mp-arg-optional">optional</span> | A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/
|
|
265
|
+
| **config** | <span class="mp-arg-type">Object</span></br></span><span class="mp-arg-optional">optional</span> | A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/v2.46.0/src/mixpanel-core.js#L88-L127">See a list of default config options</a>. |
|
|
266
266
|
| **name** | <span class="mp-arg-type">String</span></br></span><span class="mp-arg-optional">optional</span> | The name for the new mixpanel instance that you want created |
|
|
267
267
|
|
|
268
268
|
|
|
@@ -523,10 +523,20 @@ The default config is:
|
|
|
523
523
|
// secure, meaning they will only be transmitted over https
|
|
524
524
|
secure_cookie: false
|
|
525
525
|
|
|
526
|
+
// disables enriching user profiles with first touch marketing data
|
|
527
|
+
skip_first_touch_marketing: false
|
|
528
|
+
|
|
526
529
|
// the amount of time track_links will
|
|
527
530
|
// wait for Mixpanel's servers to respond
|
|
528
531
|
track_links_timeout: 300
|
|
529
532
|
|
|
533
|
+
// adds any UTM parameters and click IDs present on the page to any events fired
|
|
534
|
+
track_marketing: true
|
|
535
|
+
|
|
536
|
+
// enables automatic page view tracking using default page view events through
|
|
537
|
+
// the track_pageview() method
|
|
538
|
+
track_pageview: false
|
|
539
|
+
|
|
530
540
|
// if you set upgrade to be true, the library will check for
|
|
531
541
|
// a cookie from our old js library and import super
|
|
532
542
|
// properties from it, then the old cookie is deleted
|
|
@@ -684,6 +694,26 @@ If you pass a function in as the properties argument, the function will receive
|
|
|
684
694
|
| **properties** | <span class="mp-arg-type">Object or Function</span></br></span><span class="mp-arg-optional">optional</span> | A properties object or function that returns a dictionary of properties when passed a DOMElement |
|
|
685
695
|
|
|
686
696
|
|
|
697
|
+
___
|
|
698
|
+
## mixpanel.track_pageview
|
|
699
|
+
Track a default Mixpanel page view event, which includes extra default event properties to improve page view data. The <code>config.track_pageview</code> option for <a href="#mixpanelinit">mixpanel.init()</a> may be turned on for tracking page loads automatically.
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
| Argument | Type | Description |
|
|
705
|
+
| ------------- | ------------- | ----- |
|
|
706
|
+
| **properties** | <span class="mp-arg-type">Object</span></br></span><span class="mp-arg-optional">optional</span> | An optional set of additional properties to send with the page view event |
|
|
707
|
+
| **options** | <span class="mp-arg-type">Object</span></br></span><span class="mp-arg-optional">optional</span> | Page view tracking options |
|
|
708
|
+
| **options.event_name** | <span class="mp-arg-type">String</span></br></span><span class="mp-arg-optional">optional</span> | <ul>
|
|
709
|
+
<li>Alternate name for the tracking event</li>
|
|
710
|
+
</ul> |
|
|
711
|
+
#### Returns:
|
|
712
|
+
| Type | Description |
|
|
713
|
+
| ----- | ------------- |
|
|
714
|
+
| <span class="mp-arg-type">Boolean or Object</span> | If the tracking request was successfully initiated/queued, an object with the tracking payload sent to the API server is returned; otherwise false. |
|
|
715
|
+
|
|
716
|
+
|
|
687
717
|
___
|
|
688
718
|
## mixpanel.track_with_groups
|
|
689
719
|
Track an event with specific groups.
|
package/package.json
CHANGED
package/src/config.js
CHANGED
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,
|
|
@@ -99,6 +106,9 @@ var DEFAULT_CONFIG = {
|
|
|
99
106
|
'cookie_domain': '',
|
|
100
107
|
'cookie_name': '',
|
|
101
108
|
'loaded': NOOP_FUNC,
|
|
109
|
+
'track_marketing': true,
|
|
110
|
+
'track_pageview': false,
|
|
111
|
+
'skip_first_touch_marketing': false,
|
|
102
112
|
'store_google': true,
|
|
103
113
|
'save_referrer': true,
|
|
104
114
|
'test': false,
|
|
@@ -165,6 +175,25 @@ var create_mplib = function(token, config, name) {
|
|
|
165
175
|
instance['people'] = new MixpanelPeople();
|
|
166
176
|
instance['people']._init(instance);
|
|
167
177
|
|
|
178
|
+
if (!instance.get_config('skip_first_touch_marketing')) {
|
|
179
|
+
// We need null UTM params in the object because
|
|
180
|
+
// UTM parameters act as a tuple. If any UTM param
|
|
181
|
+
// is present, then we set all UTM params including
|
|
182
|
+
// empty ones together
|
|
183
|
+
var utm_params = _.info.campaignParams(null);
|
|
184
|
+
var initial_utm_params = {};
|
|
185
|
+
var has_utm = false;
|
|
186
|
+
_.each(utm_params, function(utm_value, utm_key) {
|
|
187
|
+
initial_utm_params['initial_' + utm_key] = utm_value;
|
|
188
|
+
if (utm_value) {
|
|
189
|
+
has_utm = true;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
if (has_utm) {
|
|
193
|
+
instance['people'].set_once(initial_utm_params);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
168
197
|
// if any instance on the page has debug = true, we set the
|
|
169
198
|
// global debug to be true
|
|
170
199
|
Config.DEBUG = Config.DEBUG || instance.get_config('debug');
|
|
@@ -196,7 +225,7 @@ var create_mplib = function(token, config, name) {
|
|
|
196
225
|
* mixpanel.library_name.track(...);
|
|
197
226
|
*
|
|
198
227
|
* @param {String} token Your Mixpanel API token
|
|
199
|
-
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/
|
|
228
|
+
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/v2.46.0/src/mixpanel-core.js#L88-L127">See a list of default config options</a>.
|
|
200
229
|
* @param {String} [name] The name for the new mixpanel instance that you want created
|
|
201
230
|
*/
|
|
202
231
|
MixpanelLib.prototype.init = function (token, config, name) {
|
|
@@ -234,7 +263,7 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
234
263
|
// default to JSON payload for standard mixpanel.com API hosts
|
|
235
264
|
if (!('api_payload_format' in config)) {
|
|
236
265
|
var api_host = config['api_host'] || DEFAULT_CONFIG['api_host'];
|
|
237
|
-
if (api_host.match(/\.mixpanel\.com
|
|
266
|
+
if (api_host.match(/\.mixpanel\.com/)) {
|
|
238
267
|
variable_features['api_payload_format'] = PAYLOAD_TYPE_JSON;
|
|
239
268
|
}
|
|
240
269
|
}
|
|
@@ -262,6 +291,10 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
262
291
|
if (!_.localStorage.is_supported(true) || !USE_XHR) {
|
|
263
292
|
this._batch_requests = false;
|
|
264
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
|
+
});
|
|
265
298
|
} else {
|
|
266
299
|
this.init_batchers();
|
|
267
300
|
if (sendBeacon && window.addEventListener) {
|
|
@@ -309,6 +342,10 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
309
342
|
'$device_id': uuid
|
|
310
343
|
}, '');
|
|
311
344
|
}
|
|
345
|
+
|
|
346
|
+
if (this.get_config('track_pageview')) {
|
|
347
|
+
this.track_pageview();
|
|
348
|
+
}
|
|
312
349
|
};
|
|
313
350
|
|
|
314
351
|
// Private methods
|
|
@@ -322,7 +359,7 @@ MixpanelLib.prototype._loaded = function() {
|
|
|
322
359
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
323
360
|
this['persistence'].update_search_keyword(document.referrer);
|
|
324
361
|
if (this.get_config('store_google')) {
|
|
325
|
-
this
|
|
362
|
+
this.register(_.info.campaignParams(), {persistent: false});
|
|
326
363
|
}
|
|
327
364
|
if (this.get_config('save_referrer')) {
|
|
328
365
|
this['persistence'].update_referrer_info(document.referrer);
|
|
@@ -605,12 +642,22 @@ MixpanelLib.prototype.are_batchers_initialized = function() {
|
|
|
605
642
|
return !!this.request_batchers.events;
|
|
606
643
|
};
|
|
607
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
|
+
|
|
608
656
|
MixpanelLib.prototype.init_batchers = function() {
|
|
609
|
-
var token = this.get_config('token');
|
|
610
657
|
if (!this.are_batchers_initialized()) {
|
|
611
658
|
var batcher_for = _.bind(function(attrs) {
|
|
612
659
|
return new RequestBatcher(
|
|
613
|
-
|
|
660
|
+
attrs.queue_key,
|
|
614
661
|
{
|
|
615
662
|
libConfig: this['config'],
|
|
616
663
|
sendRequestFunc: _.bind(function(data, options, cb) {
|
|
@@ -629,10 +676,11 @@ MixpanelLib.prototype.init_batchers = function() {
|
|
|
629
676
|
}
|
|
630
677
|
);
|
|
631
678
|
}, this);
|
|
679
|
+
var batcher_configs = this.get_batcher_configs();
|
|
632
680
|
this.request_batchers = {
|
|
633
|
-
events: batcher_for(
|
|
634
|
-
people: batcher_for(
|
|
635
|
-
groups: batcher_for(
|
|
681
|
+
events: batcher_for(batcher_configs.events),
|
|
682
|
+
people: batcher_for(batcher_configs.people),
|
|
683
|
+
groups: batcher_for(batcher_configs.groups)
|
|
636
684
|
};
|
|
637
685
|
}
|
|
638
686
|
if (this.get_config('batch_autostart')) {
|
|
@@ -641,6 +689,7 @@ MixpanelLib.prototype.init_batchers = function() {
|
|
|
641
689
|
};
|
|
642
690
|
|
|
643
691
|
MixpanelLib.prototype.start_batch_senders = function() {
|
|
692
|
+
this._batchers_were_started = true;
|
|
644
693
|
if (this.are_batchers_initialized()) {
|
|
645
694
|
this._batch_requests = true;
|
|
646
695
|
_.each(this.request_batchers, function(batcher) {
|
|
@@ -792,7 +841,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
792
841
|
}
|
|
793
842
|
|
|
794
843
|
// set defaults
|
|
795
|
-
properties =
|
|
844
|
+
properties = _.extend({}, properties);
|
|
796
845
|
properties['token'] = this.get_config('token');
|
|
797
846
|
|
|
798
847
|
// set $duration if time_event was previously called for this event
|
|
@@ -804,6 +853,10 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
804
853
|
|
|
805
854
|
this._set_default_superprops();
|
|
806
855
|
|
|
856
|
+
var marketing_properties = this.get_config('track_marketing')
|
|
857
|
+
? _.info.marketingParams()
|
|
858
|
+
: {};
|
|
859
|
+
|
|
807
860
|
// note: extend writes to the first object, so lets make sure we
|
|
808
861
|
// don't write to the persistence properties object and info
|
|
809
862
|
// properties object by passing in a new object
|
|
@@ -812,6 +865,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
812
865
|
properties = _.extend(
|
|
813
866
|
{},
|
|
814
867
|
_.info.properties(),
|
|
868
|
+
marketing_properties,
|
|
815
869
|
this['persistence'].properties(),
|
|
816
870
|
this.unpersisted_superprops,
|
|
817
871
|
properties
|
|
@@ -833,7 +887,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
833
887
|
var ret = this._track_or_batch({
|
|
834
888
|
type: 'events',
|
|
835
889
|
data: data,
|
|
836
|
-
endpoint: this.get_config('api_host') + '/track
|
|
890
|
+
endpoint: this.get_config('api_host') + '/' + this.get_config('api_routes')['track'],
|
|
837
891
|
batcher: this.request_batchers.events,
|
|
838
892
|
should_send_immediately: should_send_immediately,
|
|
839
893
|
send_request_options: options
|
|
@@ -879,13 +933,14 @@ MixpanelLib.prototype.set_group = addOptOutCheckMixpanelLib(function(group_key,
|
|
|
879
933
|
*/
|
|
880
934
|
MixpanelLib.prototype.add_group = addOptOutCheckMixpanelLib(function(group_key, group_id, callback) {
|
|
881
935
|
var old_values = this.get_property(group_key);
|
|
936
|
+
var prop = {};
|
|
882
937
|
if (old_values === undefined) {
|
|
883
|
-
var prop = {};
|
|
884
938
|
prop[group_key] = [group_id];
|
|
885
939
|
this.register(prop);
|
|
886
940
|
} else {
|
|
887
941
|
if (old_values.indexOf(group_id) === -1) {
|
|
888
942
|
old_values.push(group_id);
|
|
943
|
+
prop[group_key] = old_values;
|
|
889
944
|
this.register(prop);
|
|
890
945
|
}
|
|
891
946
|
}
|
|
@@ -972,17 +1027,54 @@ MixpanelLib.prototype.get_group = function (group_key, group_id) {
|
|
|
972
1027
|
};
|
|
973
1028
|
|
|
974
1029
|
/**
|
|
975
|
-
* Track
|
|
1030
|
+
* Track a default Mixpanel page view event, which includes extra default event properties to
|
|
1031
|
+
* improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
|
|
1032
|
+
* may be turned on for tracking page loads automatically.
|
|
976
1033
|
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1034
|
+
* ### Usage
|
|
1035
|
+
*
|
|
1036
|
+
* // track a default $mp_web_page_view event
|
|
1037
|
+
* mixpanel.track_pageview();
|
|
1038
|
+
*
|
|
1039
|
+
* // track a page view event with additional event properties
|
|
1040
|
+
* mixpanel.track_pageview({'ab_test_variant': 'card-layout-b'});
|
|
1041
|
+
*
|
|
1042
|
+
* // example approach to track page views on different page types as event properties
|
|
1043
|
+
* mixpanel.track_pageview({'page': 'pricing'});
|
|
1044
|
+
* mixpanel.track_pageview({'page': 'homepage'});
|
|
1045
|
+
*
|
|
1046
|
+
* // UNCOMMON: Tracking a page view event with a custom event_name option. NOT expected to be used for
|
|
1047
|
+
* // individual pages on the same site or product. Use cases for custom event_name may be page
|
|
1048
|
+
* // views on different products or internal applications that are considered completely separate
|
|
1049
|
+
* mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
|
|
1050
|
+
*
|
|
1051
|
+
* @param {Object} [properties] An optional set of additional properties to send with the page view event
|
|
1052
|
+
* @param {Object} [options] Page view tracking options
|
|
1053
|
+
* @param {String} [options.event_name] - Alternate name for the tracking event
|
|
1054
|
+
* @returns {Boolean|Object} If the tracking request was successfully initiated/queued, an object
|
|
1055
|
+
* with the tracking payload sent to the API server is returned; otherwise false.
|
|
979
1056
|
*/
|
|
980
|
-
MixpanelLib.prototype.track_pageview = function(
|
|
981
|
-
if (
|
|
982
|
-
|
|
1057
|
+
MixpanelLib.prototype.track_pageview = addOptOutCheckMixpanelLib(function(properties, options) {
|
|
1058
|
+
if (typeof properties !== 'object') {
|
|
1059
|
+
properties = {};
|
|
983
1060
|
}
|
|
984
|
-
|
|
985
|
-
|
|
1061
|
+
options = options || {};
|
|
1062
|
+
var event_name = options['event_name'] || '$mp_web_page_view';
|
|
1063
|
+
|
|
1064
|
+
var default_page_properties = _.extend(
|
|
1065
|
+
_.info.mpPageViewProperties(),
|
|
1066
|
+
_.info.campaignParams(),
|
|
1067
|
+
_.info.clickParams()
|
|
1068
|
+
);
|
|
1069
|
+
|
|
1070
|
+
var event_properties = _.extend(
|
|
1071
|
+
{},
|
|
1072
|
+
default_page_properties,
|
|
1073
|
+
properties
|
|
1074
|
+
);
|
|
1075
|
+
|
|
1076
|
+
return this.track(event_name, event_properties);
|
|
1077
|
+
});
|
|
986
1078
|
|
|
987
1079
|
/**
|
|
988
1080
|
* Track clicks on a set of document elements. Selector must be a
|
|
@@ -1393,6 +1485,16 @@ MixpanelLib.prototype.name_tag = function(name_tag) {
|
|
|
1393
1485
|
* The default config is:
|
|
1394
1486
|
*
|
|
1395
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
|
+
*
|
|
1396
1498
|
* // HTTP method for tracking requests
|
|
1397
1499
|
* api_method: 'POST'
|
|
1398
1500
|
*
|
|
@@ -1478,10 +1580,20 @@ MixpanelLib.prototype.name_tag = function(name_tag) {
|
|
|
1478
1580
|
* // secure, meaning they will only be transmitted over https
|
|
1479
1581
|
* secure_cookie: false
|
|
1480
1582
|
*
|
|
1583
|
+
* // disables enriching user profiles with first touch marketing data
|
|
1584
|
+
* skip_first_touch_marketing: false
|
|
1585
|
+
*
|
|
1481
1586
|
* // the amount of time track_links will
|
|
1482
1587
|
* // wait for Mixpanel's servers to respond
|
|
1483
1588
|
* track_links_timeout: 300
|
|
1484
1589
|
*
|
|
1590
|
+
* // adds any UTM parameters and click IDs present on the page to any events fired
|
|
1591
|
+
* track_marketing: true
|
|
1592
|
+
*
|
|
1593
|
+
* // enables automatic page view tracking using default page view events through
|
|
1594
|
+
* // the track_pageview() method
|
|
1595
|
+
* track_pageview: false
|
|
1596
|
+
*
|
|
1485
1597
|
* // if you set upgrade to be true, the library will check for
|
|
1486
1598
|
* // a cookie from our old js library and import super
|
|
1487
1599
|
* // properties from it, then the old cookie is deleted
|
|
@@ -1566,7 +1678,7 @@ MixpanelLib.prototype._run_hook = function(hook_name) {
|
|
|
1566
1678
|
* @param {String} property_name The name of the super property you want to retrieve
|
|
1567
1679
|
*/
|
|
1568
1680
|
MixpanelLib.prototype.get_property = function(property_name) {
|
|
1569
|
-
return this['persistence'][
|
|
1681
|
+
return this['persistence'].load_prop([property_name]);
|
|
1570
1682
|
};
|
|
1571
1683
|
|
|
1572
1684
|
MixpanelLib.prototype.toString = function() {
|
|
@@ -1639,9 +1751,13 @@ MixpanelLib.prototype._gdpr_update_persistence = function(options) {
|
|
|
1639
1751
|
}
|
|
1640
1752
|
|
|
1641
1753
|
if (disabled) {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
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
|
+
}
|
|
1645
1761
|
}
|
|
1646
1762
|
};
|
|
1647
1763
|
|
|
@@ -1843,37 +1959,38 @@ MixpanelLib.prototype.report_error = function(msg, err) {
|
|
|
1843
1959
|
// EXPORTS (for closure compiler)
|
|
1844
1960
|
|
|
1845
1961
|
// MixpanelLib Exports
|
|
1846
|
-
MixpanelLib.prototype['init']
|
|
1847
|
-
MixpanelLib.prototype['reset']
|
|
1848
|
-
MixpanelLib.prototype['disable']
|
|
1849
|
-
MixpanelLib.prototype['time_event']
|
|
1850
|
-
MixpanelLib.prototype['track']
|
|
1851
|
-
MixpanelLib.prototype['track_links']
|
|
1852
|
-
MixpanelLib.prototype['track_forms']
|
|
1853
|
-
MixpanelLib.prototype['track_pageview']
|
|
1854
|
-
MixpanelLib.prototype['register']
|
|
1855
|
-
MixpanelLib.prototype['register_once']
|
|
1856
|
-
MixpanelLib.prototype['unregister']
|
|
1857
|
-
MixpanelLib.prototype['identify']
|
|
1858
|
-
MixpanelLib.prototype['alias']
|
|
1859
|
-
MixpanelLib.prototype['name_tag']
|
|
1860
|
-
MixpanelLib.prototype['set_config']
|
|
1861
|
-
MixpanelLib.prototype['get_config']
|
|
1862
|
-
MixpanelLib.prototype['get_property']
|
|
1863
|
-
MixpanelLib.prototype['get_distinct_id']
|
|
1864
|
-
MixpanelLib.prototype['toString']
|
|
1865
|
-
MixpanelLib.prototype['opt_out_tracking']
|
|
1866
|
-
MixpanelLib.prototype['opt_in_tracking']
|
|
1867
|
-
MixpanelLib.prototype['has_opted_out_tracking']
|
|
1868
|
-
MixpanelLib.prototype['has_opted_in_tracking']
|
|
1869
|
-
MixpanelLib.prototype['clear_opt_in_out_tracking']
|
|
1870
|
-
MixpanelLib.prototype['get_group']
|
|
1871
|
-
MixpanelLib.prototype['set_group']
|
|
1872
|
-
MixpanelLib.prototype['add_group']
|
|
1873
|
-
MixpanelLib.prototype['remove_group']
|
|
1874
|
-
MixpanelLib.prototype['track_with_groups']
|
|
1875
|
-
MixpanelLib.prototype['start_batch_senders']
|
|
1876
|
-
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;
|
|
1877
1994
|
|
|
1878
1995
|
// MixpanelPersistence Exports
|
|
1879
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
|
|