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
|
@@ -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,19 +224,13 @@ 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();
|
|
219
231
|
}
|
|
220
232
|
};
|
|
221
233
|
|
|
222
|
-
MixpanelPersistence.prototype.update_campaign_params = function() {
|
|
223
|
-
if (!this.campaign_params_saved) {
|
|
224
|
-
this.register_once(_.info.campaignParams());
|
|
225
|
-
this.campaign_params_saved = true;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
234
|
MixpanelPersistence.prototype.update_search_keyword = function(referrer) {
|
|
230
235
|
this.register(_.info.searchInfo(referrer));
|
|
231
236
|
};
|
|
@@ -246,19 +251,6 @@ MixpanelPersistence.prototype.get_referrer_info = function() {
|
|
|
246
251
|
});
|
|
247
252
|
};
|
|
248
253
|
|
|
249
|
-
// safely fills the passed in object with stored properties,
|
|
250
|
-
// does not override any properties defined in both
|
|
251
|
-
// returns the passed in object
|
|
252
|
-
MixpanelPersistence.prototype.safe_merge = function(props) {
|
|
253
|
-
_.each(this['props'], function(val, prop) {
|
|
254
|
-
if (!(prop in props)) {
|
|
255
|
-
props[prop] = val;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
return props;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
254
|
MixpanelPersistence.prototype.update_config = function(config) {
|
|
263
255
|
this.default_expiry = this.expire_days = config['cookie_expiration'];
|
|
264
256
|
this.set_disabled(config['disable_persistence']);
|
|
@@ -402,7 +394,7 @@ MixpanelPersistence.prototype._add_to_people_queue = function(queue, data) {
|
|
|
402
394
|
};
|
|
403
395
|
|
|
404
396
|
MixpanelPersistence.prototype._pop_from_people_queue = function(queue, data) {
|
|
405
|
-
var q = this.
|
|
397
|
+
var q = this['props'][this._get_queue_key(queue)];
|
|
406
398
|
if (!_.isUndefined(q)) {
|
|
407
399
|
_.each(data, function(v, k) {
|
|
408
400
|
if (queue === APPEND_ACTION || queue === REMOVE_ACTION) {
|
|
@@ -418,11 +410,13 @@ MixpanelPersistence.prototype._pop_from_people_queue = function(queue, data) {
|
|
|
418
410
|
delete q[k];
|
|
419
411
|
}
|
|
420
412
|
}, this);
|
|
421
|
-
|
|
422
|
-
this.save();
|
|
423
413
|
}
|
|
424
414
|
};
|
|
425
415
|
|
|
416
|
+
MixpanelPersistence.prototype.load_queue = function(queue) {
|
|
417
|
+
return this.load_prop(this._get_queue_key(queue));
|
|
418
|
+
};
|
|
419
|
+
|
|
426
420
|
MixpanelPersistence.prototype._get_queue_key = function(queue) {
|
|
427
421
|
if (queue === SET_ACTION) {
|
|
428
422
|
return SET_QUEUE_KEY;
|
|
@@ -443,25 +437,21 @@ MixpanelPersistence.prototype._get_queue_key = function(queue) {
|
|
|
443
437
|
}
|
|
444
438
|
};
|
|
445
439
|
|
|
446
|
-
MixpanelPersistence.prototype._get_queue = function(queue) {
|
|
447
|
-
return this['props'][this._get_queue_key(queue)];
|
|
448
|
-
};
|
|
449
440
|
MixpanelPersistence.prototype._get_or_create_queue = function(queue, default_val) {
|
|
450
441
|
var key = this._get_queue_key(queue);
|
|
451
442
|
default_val = _.isUndefined(default_val) ? {} : default_val;
|
|
452
|
-
|
|
453
443
|
return this['props'][key] || (this['props'][key] = default_val);
|
|
454
444
|
};
|
|
455
445
|
|
|
456
446
|
MixpanelPersistence.prototype.set_event_timer = function(event_name, timestamp) {
|
|
457
|
-
var timers = this
|
|
447
|
+
var timers = this.load_prop(EVENT_TIMERS_KEY) || {};
|
|
458
448
|
timers[event_name] = timestamp;
|
|
459
449
|
this['props'][EVENT_TIMERS_KEY] = timers;
|
|
460
450
|
this.save();
|
|
461
451
|
};
|
|
462
452
|
|
|
463
453
|
MixpanelPersistence.prototype.remove_event_timer = function(event_name) {
|
|
464
|
-
var timers = this
|
|
454
|
+
var timers = this.load_prop(EVENT_TIMERS_KEY) || {};
|
|
465
455
|
var timestamp = timers[event_name];
|
|
466
456
|
if (!_.isUndefined(timestamp)) {
|
|
467
457
|
delete this['props'][EVENT_TIMERS_KEY][event_name];
|
package/src/utils.js
CHANGED
|
@@ -830,20 +830,24 @@ _.utf8Encode = function(string) {
|
|
|
830
830
|
|
|
831
831
|
_.UUID = (function() {
|
|
832
832
|
|
|
833
|
-
// Time
|
|
834
|
-
// 1*new Date() is a cross browser version of Date.now()
|
|
833
|
+
// Time-based entropy
|
|
835
834
|
var T = function() {
|
|
836
|
-
var
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
835
|
+
var time = 1 * new Date(); // cross-browser version of Date.now()
|
|
836
|
+
var ticks;
|
|
837
|
+
if (win.performance && win.performance.now) {
|
|
838
|
+
ticks = win.performance.now();
|
|
839
|
+
} else {
|
|
840
|
+
// fall back to busy loop
|
|
841
|
+
ticks = 0;
|
|
842
|
+
|
|
843
|
+
// this while loop figures how many browser ticks go by
|
|
844
|
+
// before 1*new Date() returns a new number, ie the amount
|
|
845
|
+
// of ticks that go by per millisecond
|
|
846
|
+
while (time == 1 * new Date()) {
|
|
847
|
+
ticks++;
|
|
848
|
+
}
|
|
844
849
|
}
|
|
845
|
-
|
|
846
|
-
return d.toString(16) + i.toString(16);
|
|
850
|
+
return time.toString(16) + Math.floor(ticks).toString(16);
|
|
847
851
|
};
|
|
848
852
|
|
|
849
853
|
// Math.Random entropy
|
|
@@ -898,6 +902,7 @@ var BLOCKED_UA_STRS = [
|
|
|
898
902
|
'baiduspider',
|
|
899
903
|
'bingbot',
|
|
900
904
|
'bingpreview',
|
|
905
|
+
'chrome-lighthouse',
|
|
901
906
|
'facebookexternal',
|
|
902
907
|
'petalbot',
|
|
903
908
|
'pinterest',
|
|
@@ -1410,21 +1415,42 @@ _.dom_query = (function() {
|
|
|
1410
1415
|
};
|
|
1411
1416
|
})();
|
|
1412
1417
|
|
|
1418
|
+
var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
|
|
1419
|
+
var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
|
|
1420
|
+
|
|
1413
1421
|
_.info = {
|
|
1414
|
-
campaignParams: function() {
|
|
1415
|
-
var
|
|
1416
|
-
kw = '',
|
|
1422
|
+
campaignParams: function(default_value) {
|
|
1423
|
+
var kw = '',
|
|
1417
1424
|
params = {};
|
|
1418
|
-
_.each(
|
|
1425
|
+
_.each(CAMPAIGN_KEYWORDS, function(kwkey) {
|
|
1419
1426
|
kw = _.getQueryParam(document.URL, kwkey);
|
|
1420
1427
|
if (kw.length) {
|
|
1421
1428
|
params[kwkey] = kw;
|
|
1429
|
+
} else if (default_value !== undefined) {
|
|
1430
|
+
params[kwkey] = default_value;
|
|
1422
1431
|
}
|
|
1423
1432
|
});
|
|
1424
1433
|
|
|
1425
1434
|
return params;
|
|
1426
1435
|
},
|
|
1427
1436
|
|
|
1437
|
+
clickParams: function() {
|
|
1438
|
+
var id = '',
|
|
1439
|
+
params = {};
|
|
1440
|
+
_.each(CLICK_IDS, function(idkey) {
|
|
1441
|
+
id = _.getQueryParam(document.URL, idkey);
|
|
1442
|
+
if (id.length) {
|
|
1443
|
+
params[idkey] = id;
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
return params;
|
|
1448
|
+
},
|
|
1449
|
+
|
|
1450
|
+
marketingParams: function() {
|
|
1451
|
+
return _.extend(_.info.campaignParams(), _.info.clickParams());
|
|
1452
|
+
},
|
|
1453
|
+
|
|
1428
1454
|
searchEngine: function(referrer) {
|
|
1429
1455
|
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
|
|
1430
1456
|
return 'google';
|
|
@@ -1621,12 +1647,13 @@ _.info = {
|
|
|
1621
1647
|
});
|
|
1622
1648
|
},
|
|
1623
1649
|
|
|
1624
|
-
|
|
1650
|
+
mpPageViewProperties: function() {
|
|
1625
1651
|
return _.strip_empty_properties({
|
|
1626
|
-
'
|
|
1627
|
-
'
|
|
1628
|
-
'
|
|
1629
|
-
'
|
|
1652
|
+
'current_page_title': document.title,
|
|
1653
|
+
'current_domain': win.location.hostname,
|
|
1654
|
+
'current_url_path': win.location.pathname,
|
|
1655
|
+
'current_url_protocol': win.location.protocol,
|
|
1656
|
+
'current_url_search': win.location.search
|
|
1630
1657
|
});
|
|
1631
1658
|
}
|
|
1632
1659
|
};
|