mixpanel-browser 2.49.0 → 2.51.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 +9 -10
- package/build.sh +2 -1
- package/dist/mixpanel-js-wrapper.js +3 -3
- package/dist/mixpanel-js-wrapper.min.js +1 -1
- package/dist/mixpanel-jslib-snippet.min.js +1 -1
- package/dist/mixpanel-jslib-snippet.min.test.js +1 -1
- package/dist/mixpanel-recorder.js +6499 -0
- package/dist/mixpanel-recorder.min.js +38 -0
- package/dist/mixpanel.amd.js +200 -143
- package/dist/mixpanel.cjs.js +199 -142
- package/dist/mixpanel.globals.js +200 -143
- package/dist/mixpanel.min.js +110 -108
- package/dist/mixpanel.umd.js +201 -144
- package/package.json +7 -2
- package/src/config.js +1 -1
- package/src/loaders/mixpanel-jslib-snippet.js +1 -1
- package/src/mixpanel-core.js +98 -39
- package/src/mixpanel-persistence.js +14 -43
- package/src/recorder/index.js +156 -0
- package/src/recorder/rollup.config.js +19 -0
- package/src/utils.js +4 -0
package/dist/mixpanel.cjs.js
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var Config = {
|
|
4
4
|
DEBUG: false,
|
|
5
|
-
LIB_VERSION: '2.
|
|
5
|
+
LIB_VERSION: '2.51.0'
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
/* eslint camelcase: "off", eqeqeq: "off" */
|
|
9
|
+
|
|
8
10
|
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
|
|
9
|
-
var
|
|
11
|
+
var win;
|
|
10
12
|
if (typeof(window) === 'undefined') {
|
|
11
13
|
var loc = {
|
|
12
14
|
hostname: ''
|
|
13
15
|
};
|
|
14
|
-
|
|
16
|
+
win = {
|
|
15
17
|
navigator: { userAgent: '' },
|
|
16
18
|
document: {
|
|
17
19
|
location: loc,
|
|
@@ -21,32 +23,37 @@ if (typeof(window) === 'undefined') {
|
|
|
21
23
|
location: loc
|
|
22
24
|
};
|
|
23
25
|
} else {
|
|
24
|
-
|
|
26
|
+
win = window;
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
// Maximum allowed session recording length
|
|
30
|
+
var MAX_RECORDING_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
31
|
+
|
|
27
32
|
/*
|
|
28
33
|
* Saved references to long variable names, so that closure compiler can
|
|
29
34
|
* minimize file size.
|
|
30
35
|
*/
|
|
31
36
|
|
|
32
|
-
var ArrayProto = Array.prototype
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
var ArrayProto = Array.prototype,
|
|
38
|
+
FuncProto = Function.prototype,
|
|
39
|
+
ObjProto = Object.prototype,
|
|
40
|
+
slice = ArrayProto.slice,
|
|
41
|
+
toString = ObjProto.toString,
|
|
42
|
+
hasOwnProperty = ObjProto.hasOwnProperty,
|
|
43
|
+
windowConsole = win.console,
|
|
44
|
+
navigator = win.navigator,
|
|
45
|
+
document$1 = win.document,
|
|
46
|
+
windowOpera = win.opera,
|
|
47
|
+
screen = win.screen,
|
|
48
|
+
userAgent = navigator.userAgent;
|
|
49
|
+
|
|
50
|
+
var nativeBind = FuncProto.bind,
|
|
51
|
+
nativeForEach = ArrayProto.forEach,
|
|
52
|
+
nativeIndexOf = ArrayProto.indexOf,
|
|
53
|
+
nativeMap = ArrayProto.map,
|
|
54
|
+
nativeIsArray = Array.isArray,
|
|
55
|
+
breaker = {};
|
|
56
|
+
|
|
50
57
|
var _ = {
|
|
51
58
|
trim: function(str) {
|
|
52
59
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
|
@@ -836,8 +843,8 @@ _.UUID = (function() {
|
|
|
836
843
|
var T = function() {
|
|
837
844
|
var time = 1 * new Date(); // cross-browser version of Date.now()
|
|
838
845
|
var ticks;
|
|
839
|
-
if (
|
|
840
|
-
ticks =
|
|
846
|
+
if (win.performance && win.performance.now) {
|
|
847
|
+
ticks = win.performance.now();
|
|
841
848
|
} else {
|
|
842
849
|
// fall back to busy loop
|
|
843
850
|
ticks = 0;
|
|
@@ -1623,7 +1630,7 @@ _.info = {
|
|
|
1623
1630
|
},
|
|
1624
1631
|
|
|
1625
1632
|
currentUrl: function() {
|
|
1626
|
-
return
|
|
1633
|
+
return win.location.href;
|
|
1627
1634
|
},
|
|
1628
1635
|
|
|
1629
1636
|
properties: function(extra_props) {
|
|
@@ -1660,10 +1667,10 @@ _.info = {
|
|
|
1660
1667
|
mpPageViewProperties: function() {
|
|
1661
1668
|
return _.strip_empty_properties({
|
|
1662
1669
|
'current_page_title': document$1.title,
|
|
1663
|
-
'current_domain':
|
|
1664
|
-
'current_url_path':
|
|
1665
|
-
'current_url_protocol':
|
|
1666
|
-
'current_url_search':
|
|
1670
|
+
'current_domain': win.location.hostname,
|
|
1671
|
+
'current_url_path': win.location.pathname,
|
|
1672
|
+
'current_url_protocol': win.location.protocol,
|
|
1673
|
+
'current_url_search': win.location.search
|
|
1667
1674
|
});
|
|
1668
1675
|
}
|
|
1669
1676
|
};
|
|
@@ -1701,8 +1708,7 @@ var extract_domain = function(hostname) {
|
|
|
1701
1708
|
return matches ? matches[0] : '';
|
|
1702
1709
|
};
|
|
1703
1710
|
|
|
1704
|
-
var JSONStringify = null;
|
|
1705
|
-
var JSONParse = null;
|
|
1711
|
+
var JSONStringify = null, JSONParse = null;
|
|
1706
1712
|
if (typeof JSON !== 'undefined') {
|
|
1707
1713
|
JSONStringify = JSON.stringify;
|
|
1708
1714
|
JSONParse = JSON.parse;
|
|
@@ -1723,6 +1729,8 @@ _['info']['browser'] = _.info.browser;
|
|
|
1723
1729
|
_['info']['browserVersion'] = _.info.browserVersion;
|
|
1724
1730
|
_['info']['properties'] = _.info.properties;
|
|
1725
1731
|
|
|
1732
|
+
/* eslint camelcase: "off" */
|
|
1733
|
+
|
|
1726
1734
|
/**
|
|
1727
1735
|
* DomTracker Object
|
|
1728
1736
|
* @constructor
|
|
@@ -1872,8 +1880,6 @@ FormTracker.prototype.after_track_handler = function(props, options) {
|
|
|
1872
1880
|
}, 0);
|
|
1873
1881
|
};
|
|
1874
1882
|
|
|
1875
|
-
// eslint-disable-line camelcase
|
|
1876
|
-
|
|
1877
1883
|
var logger$2 = console_with_prefix('lock');
|
|
1878
1884
|
|
|
1879
1885
|
/**
|
|
@@ -2020,8 +2026,6 @@ SharedLock.prototype.withLock = function(lockedCB, errorCB, pid) {
|
|
|
2020
2026
|
}
|
|
2021
2027
|
};
|
|
2022
2028
|
|
|
2023
|
-
// eslint-disable-line camelcase
|
|
2024
|
-
|
|
2025
2029
|
var logger$1 = console_with_prefix('batch');
|
|
2026
2030
|
|
|
2027
2031
|
/**
|
|
@@ -2299,8 +2303,6 @@ RequestQueue.prototype.clear = function() {
|
|
|
2299
2303
|
this.storage.removeItem(this.storageKey);
|
|
2300
2304
|
};
|
|
2301
2305
|
|
|
2302
|
-
// eslint-disable-line camelcase
|
|
2303
|
-
|
|
2304
2306
|
// maximum interval between request retries after exponential backoff
|
|
2305
2307
|
var MAX_RETRY_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
|
|
2306
2308
|
|
|
@@ -2595,6 +2597,19 @@ RequestBatcher.prototype.reportError = function(msg, err) {
|
|
|
2595
2597
|
}
|
|
2596
2598
|
};
|
|
2597
2599
|
|
|
2600
|
+
/**
|
|
2601
|
+
* GDPR utils
|
|
2602
|
+
*
|
|
2603
|
+
* The General Data Protection Regulation (GDPR) is a regulation in EU law on data protection
|
|
2604
|
+
* and privacy for all individuals within the European Union. It addresses the export of personal
|
|
2605
|
+
* data outside the EU. The GDPR aims primarily to give control back to citizens and residents
|
|
2606
|
+
* over their personal data and to simplify the regulatory environment for international business
|
|
2607
|
+
* by unifying the regulation within the EU.
|
|
2608
|
+
*
|
|
2609
|
+
* This set of utilities is intended to enable opt in/out functionality in the Mixpanel JS SDK.
|
|
2610
|
+
* These functions are used internally by the SDK and are not intended to be publicly exposed.
|
|
2611
|
+
*/
|
|
2612
|
+
|
|
2598
2613
|
/**
|
|
2599
2614
|
* A function used to track a Mixpanel event (e.g. MixpanelLib.track)
|
|
2600
2615
|
* @callback trackFunction
|
|
@@ -2780,14 +2795,14 @@ function _hasDoNotTrackFlagOn(options) {
|
|
|
2780
2795
|
if (options && options.ignoreDnt) {
|
|
2781
2796
|
return false;
|
|
2782
2797
|
}
|
|
2783
|
-
var win = (options && options.window) ||
|
|
2784
|
-
var nav = win['navigator'] || {};
|
|
2798
|
+
var win$1 = (options && options.window) || win;
|
|
2799
|
+
var nav = win$1['navigator'] || {};
|
|
2785
2800
|
var hasDntOn = false;
|
|
2786
2801
|
|
|
2787
2802
|
_.each([
|
|
2788
2803
|
nav['doNotTrack'], // standard
|
|
2789
2804
|
nav['msDoNotTrack'],
|
|
2790
|
-
win['doNotTrack']
|
|
2805
|
+
win$1['doNotTrack']
|
|
2791
2806
|
], function(dntValue) {
|
|
2792
2807
|
if (_.includes([true, 1, '1', 'yes'], dntValue)) {
|
|
2793
2808
|
hasDntOn = true;
|
|
@@ -2881,6 +2896,8 @@ function _addOptOutCheck(method, getConfigValue) {
|
|
|
2881
2896
|
};
|
|
2882
2897
|
}
|
|
2883
2898
|
|
|
2899
|
+
/* eslint camelcase: "off" */
|
|
2900
|
+
|
|
2884
2901
|
/** @const */ var SET_ACTION = '$set';
|
|
2885
2902
|
/** @const */ var SET_ONCE_ACTION = '$set_once';
|
|
2886
2903
|
/** @const */ var UNSET_ACTION = '$unset';
|
|
@@ -2998,6 +3015,8 @@ var apiActions = {
|
|
|
2998
3015
|
}
|
|
2999
3016
|
};
|
|
3000
3017
|
|
|
3018
|
+
/* eslint camelcase: "off" */
|
|
3019
|
+
|
|
3001
3020
|
/**
|
|
3002
3021
|
* Mixpanel Group Object
|
|
3003
3022
|
* @constructor
|
|
@@ -3166,6 +3185,8 @@ MixpanelGroup.prototype['union'] = MixpanelGroup.prototype.union;
|
|
|
3166
3185
|
MixpanelGroup.prototype['unset'] = MixpanelGroup.prototype.unset;
|
|
3167
3186
|
MixpanelGroup.prototype['toString'] = MixpanelGroup.prototype.toString;
|
|
3168
3187
|
|
|
3188
|
+
/* eslint camelcase: "off" */
|
|
3189
|
+
|
|
3169
3190
|
/**
|
|
3170
3191
|
* Mixpanel People Object
|
|
3171
3192
|
* @constructor
|
|
@@ -3634,6 +3655,8 @@ MixpanelPeople.prototype['clear_charges'] = MixpanelPeople.prototype.clear_charg
|
|
|
3634
3655
|
MixpanelPeople.prototype['delete_user'] = MixpanelPeople.prototype.delete_user;
|
|
3635
3656
|
MixpanelPeople.prototype['toString'] = MixpanelPeople.prototype.toString;
|
|
3636
3657
|
|
|
3658
|
+
/* eslint camelcase: "off" */
|
|
3659
|
+
|
|
3637
3660
|
/*
|
|
3638
3661
|
* Constants
|
|
3639
3662
|
*/
|
|
@@ -3689,7 +3712,7 @@ var MixpanelPersistence = function(config) {
|
|
|
3689
3712
|
|
|
3690
3713
|
this.load();
|
|
3691
3714
|
this.update_config(config);
|
|
3692
|
-
this.upgrade(
|
|
3715
|
+
this.upgrade();
|
|
3693
3716
|
this.save();
|
|
3694
3717
|
};
|
|
3695
3718
|
|
|
@@ -3717,49 +3740,12 @@ MixpanelPersistence.prototype.load = function() {
|
|
|
3717
3740
|
}
|
|
3718
3741
|
};
|
|
3719
3742
|
|
|
3720
|
-
MixpanelPersistence.prototype.upgrade = function(
|
|
3721
|
-
var
|
|
3722
|
-
|
|
3723
|
-
old_cookie;
|
|
3724
|
-
|
|
3725
|
-
if (upgrade_from_old_lib) {
|
|
3726
|
-
old_cookie_name = 'mp_super_properties';
|
|
3727
|
-
// Case where they had a custom cookie name before.
|
|
3728
|
-
if (typeof(upgrade_from_old_lib) === 'string') {
|
|
3729
|
-
old_cookie_name = upgrade_from_old_lib;
|
|
3730
|
-
}
|
|
3731
|
-
|
|
3732
|
-
old_cookie = this.storage.parse(old_cookie_name);
|
|
3733
|
-
|
|
3734
|
-
// remove the cookie
|
|
3735
|
-
this.storage.remove(old_cookie_name);
|
|
3736
|
-
this.storage.remove(old_cookie_name, true);
|
|
3737
|
-
|
|
3738
|
-
if (old_cookie) {
|
|
3739
|
-
this['props'] = _.extend(
|
|
3740
|
-
this['props'],
|
|
3741
|
-
old_cookie['all'],
|
|
3742
|
-
old_cookie['events']
|
|
3743
|
-
);
|
|
3744
|
-
}
|
|
3745
|
-
}
|
|
3746
|
-
|
|
3747
|
-
if (!config['cookie_name'] && config['name'] !== 'mixpanel') {
|
|
3748
|
-
// special case to handle people with cookies of the form
|
|
3749
|
-
// mp_TOKEN_INSTANCENAME from the first release of this library
|
|
3750
|
-
old_cookie_name = 'mp_' + config['token'] + '_' + config['name'];
|
|
3751
|
-
old_cookie = this.storage.parse(old_cookie_name);
|
|
3752
|
-
|
|
3753
|
-
if (old_cookie) {
|
|
3754
|
-
this.storage.remove(old_cookie_name);
|
|
3755
|
-
this.storage.remove(old_cookie_name, true);
|
|
3756
|
-
|
|
3757
|
-
// Save the prop values that were in the cookie from before -
|
|
3758
|
-
// this should only happen once as we delete the old one.
|
|
3759
|
-
this.register_once(old_cookie);
|
|
3760
|
-
}
|
|
3761
|
-
}
|
|
3743
|
+
MixpanelPersistence.prototype.upgrade = function() {
|
|
3744
|
+
var old_cookie,
|
|
3745
|
+
old_localstorage;
|
|
3762
3746
|
|
|
3747
|
+
// if transferring from cookie to localStorage or vice-versa, copy existing
|
|
3748
|
+
// super properties over to new storage mode
|
|
3763
3749
|
if (this.storage === _.localStorage) {
|
|
3764
3750
|
old_cookie = _.cookie.parse(this.name);
|
|
3765
3751
|
|
|
@@ -3769,6 +3755,14 @@ MixpanelPersistence.prototype.upgrade = function(config) {
|
|
|
3769
3755
|
if (old_cookie) {
|
|
3770
3756
|
this.register_once(old_cookie);
|
|
3771
3757
|
}
|
|
3758
|
+
} else if (this.storage === _.cookie) {
|
|
3759
|
+
old_localstorage = _.localStorage.parse(this.name);
|
|
3760
|
+
|
|
3761
|
+
_.localStorage.remove(this.name);
|
|
3762
|
+
|
|
3763
|
+
if (old_localstorage) {
|
|
3764
|
+
this.register_once(old_localstorage);
|
|
3765
|
+
}
|
|
3772
3766
|
}
|
|
3773
3767
|
};
|
|
3774
3768
|
|
|
@@ -4083,6 +4077,8 @@ MixpanelPersistence.prototype.remove_event_timer = function(event_name) {
|
|
|
4083
4077
|
return timestamp;
|
|
4084
4078
|
};
|
|
4085
4079
|
|
|
4080
|
+
/* eslint camelcase: "off" */
|
|
4081
|
+
|
|
4086
4082
|
/*
|
|
4087
4083
|
* Mixpanel JS Library
|
|
4088
4084
|
*
|
|
@@ -4129,7 +4125,7 @@ var NOOP_FUNC = function() {};
|
|
|
4129
4125
|
*/
|
|
4130
4126
|
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
|
|
4131
4127
|
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#withCredentials
|
|
4132
|
-
var USE_XHR = (
|
|
4128
|
+
var USE_XHR = (win.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest());
|
|
4133
4129
|
|
|
4134
4130
|
// IE<10 does not support cross-origin XHR's but script tags
|
|
4135
4131
|
// with defer won't block window.onload; ENQUEUE_REQUESTS
|
|
@@ -4148,7 +4144,8 @@ if (navigator['sendBeacon']) {
|
|
|
4148
4144
|
var DEFAULT_API_ROUTES = {
|
|
4149
4145
|
'track': 'track/',
|
|
4150
4146
|
'engage': 'engage/',
|
|
4151
|
-
'groups': 'groups/'
|
|
4147
|
+
'groups': 'groups/',
|
|
4148
|
+
'record': 'record/'
|
|
4152
4149
|
};
|
|
4153
4150
|
|
|
4154
4151
|
/*
|
|
@@ -4175,7 +4172,7 @@ var DEFAULT_CONFIG = {
|
|
|
4175
4172
|
'track_pageview': false,
|
|
4176
4173
|
'skip_first_touch_marketing': false,
|
|
4177
4174
|
'store_google': true,
|
|
4178
|
-
'stop_utm_persistence':
|
|
4175
|
+
'stop_utm_persistence': true,
|
|
4179
4176
|
'save_referrer': true,
|
|
4180
4177
|
'test': false,
|
|
4181
4178
|
'verbose': false,
|
|
@@ -4200,7 +4197,15 @@ var DEFAULT_CONFIG = {
|
|
|
4200
4197
|
'batch_flush_interval_ms': 5000,
|
|
4201
4198
|
'batch_request_timeout_ms': 90000,
|
|
4202
4199
|
'batch_autostart': true,
|
|
4203
|
-
'hooks': {}
|
|
4200
|
+
'hooks': {},
|
|
4201
|
+
'record_block_class': new RegExp('^(mp-block|fs-exclude|amp-block|rr-block|ph-no-capture)$'),
|
|
4202
|
+
'record_block_selector': 'img, video',
|
|
4203
|
+
'record_idle_timeout_ms': 30 * 60 * 1000, // 30 minutes
|
|
4204
|
+
'record_mask_text_class': new RegExp('^(mp-mask|fs-mask|amp-mask|rr-mask|ph-mask)$'),
|
|
4205
|
+
'record_mask_text_selector': '*',
|
|
4206
|
+
'record_max_ms': MAX_RECORDING_MS,
|
|
4207
|
+
'record_sessions_percent': 0,
|
|
4208
|
+
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js'
|
|
4204
4209
|
};
|
|
4205
4210
|
|
|
4206
4211
|
var DOM_LOADED = false;
|
|
@@ -4363,7 +4368,7 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4363
4368
|
});
|
|
4364
4369
|
} else {
|
|
4365
4370
|
this.init_batchers();
|
|
4366
|
-
if (sendBeacon &&
|
|
4371
|
+
if (sendBeacon && win.addEventListener) {
|
|
4367
4372
|
// Before page closes or hides (user tabs away etc), attempt to flush any events
|
|
4368
4373
|
// queued up via navigator.sendBeacon. Since sendBeacon doesn't report success/failure,
|
|
4369
4374
|
// events will not be removed from the persistent store; if the site is loaded again,
|
|
@@ -4380,12 +4385,12 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4380
4385
|
this.request_batchers.events.flush({unloading: true});
|
|
4381
4386
|
}
|
|
4382
4387
|
}, this);
|
|
4383
|
-
|
|
4388
|
+
win.addEventListener('pagehide', function(ev) {
|
|
4384
4389
|
if (ev['persisted']) {
|
|
4385
4390
|
flush_on_unload();
|
|
4386
4391
|
}
|
|
4387
4392
|
});
|
|
4388
|
-
|
|
4393
|
+
win.addEventListener('visibilitychange', function() {
|
|
4389
4394
|
if (document$1['visibilityState'] === 'hidden') {
|
|
4390
4395
|
flush_on_unload();
|
|
4391
4396
|
}
|
|
@@ -4413,6 +4418,52 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4413
4418
|
if (track_pageview_option) {
|
|
4414
4419
|
this._init_url_change_tracking(track_pageview_option);
|
|
4415
4420
|
}
|
|
4421
|
+
|
|
4422
|
+
if (this.get_config('record_sessions_percent') > 0 && Math.random() * 100 <= this.get_config('record_sessions_percent')) {
|
|
4423
|
+
this.start_session_recording();
|
|
4424
|
+
}
|
|
4425
|
+
};
|
|
4426
|
+
|
|
4427
|
+
MixpanelLib.prototype.start_session_recording = addOptOutCheckMixpanelLib(function () {
|
|
4428
|
+
if (!win['MutationObserver']) {
|
|
4429
|
+
console.critical('Browser does not support MutationObserver; skipping session recording');
|
|
4430
|
+
return;
|
|
4431
|
+
}
|
|
4432
|
+
|
|
4433
|
+
var handleLoadedRecorder = _.bind(function() {
|
|
4434
|
+
this._recorder = this._recorder || new win['__mp_recorder'](this);
|
|
4435
|
+
this._recorder['startRecording']();
|
|
4436
|
+
}, this);
|
|
4437
|
+
|
|
4438
|
+
if (_.isUndefined(win['__mp_recorder'])) {
|
|
4439
|
+
var scriptEl = document$1.createElement('script');
|
|
4440
|
+
scriptEl.type = 'text/javascript';
|
|
4441
|
+
scriptEl.async = true;
|
|
4442
|
+
scriptEl.onload = handleLoadedRecorder;
|
|
4443
|
+
scriptEl.src = this.get_config('recorder_src');
|
|
4444
|
+
document$1.head.appendChild(scriptEl);
|
|
4445
|
+
} else {
|
|
4446
|
+
handleLoadedRecorder();
|
|
4447
|
+
}
|
|
4448
|
+
});
|
|
4449
|
+
|
|
4450
|
+
MixpanelLib.prototype.stop_session_recording = function () {
|
|
4451
|
+
if (this._recorder) {
|
|
4452
|
+
this._recorder['stopRecording']();
|
|
4453
|
+
} else {
|
|
4454
|
+
console.critical('Session recorder module not loaded');
|
|
4455
|
+
}
|
|
4456
|
+
};
|
|
4457
|
+
|
|
4458
|
+
MixpanelLib.prototype.get_session_recording_properties = function () {
|
|
4459
|
+
var props = {};
|
|
4460
|
+
if (this._recorder) {
|
|
4461
|
+
var replay_id = this._recorder['replayId'];
|
|
4462
|
+
if (replay_id) {
|
|
4463
|
+
props['$mp_replay_id'] = replay_id;
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
return props;
|
|
4416
4467
|
};
|
|
4417
4468
|
|
|
4418
4469
|
// Private methods
|
|
@@ -4422,9 +4473,8 @@ MixpanelLib.prototype._loaded = function() {
|
|
|
4422
4473
|
this._set_default_superprops();
|
|
4423
4474
|
this['people'].set_once(this['persistence'].get_referrer_info());
|
|
4424
4475
|
|
|
4425
|
-
//
|
|
4426
|
-
//
|
|
4427
|
-
// stop_utm_persistence is `false` by default now but will be default `true` in the future.
|
|
4476
|
+
// `store_google` is now deprecated and previously stored UTM parameters are cleared
|
|
4477
|
+
// from persistence by default.
|
|
4428
4478
|
if (this.get_config('store_google') && this.get_config('stop_utm_persistence')) {
|
|
4429
4479
|
var utm_params = _.info.campaignParams(null);
|
|
4430
4480
|
_.each(utm_params, function(_utm_value, utm_key) {
|
|
@@ -4438,6 +4488,7 @@ MixpanelLib.prototype._loaded = function() {
|
|
|
4438
4488
|
// update persistence with info on referrer, UTM params, etc
|
|
4439
4489
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
4440
4490
|
this['persistence'].update_search_keyword(document$1.referrer);
|
|
4491
|
+
// Registering super properties for UTM persistence by 'store_google' is deprecated.
|
|
4441
4492
|
if (this.get_config('store_google') && !this.get_config('stop_utm_persistence')) {
|
|
4442
4493
|
this.register(_.info.campaignParams());
|
|
4443
4494
|
}
|
|
@@ -4484,27 +4535,27 @@ MixpanelLib.prototype._init_url_change_tracking = function(track_pageview_option
|
|
|
4484
4535
|
}
|
|
4485
4536
|
|
|
4486
4537
|
if (_.include(['full-url', 'url-with-path-and-query-string', 'url-with-path'], track_pageview_option)) {
|
|
4487
|
-
|
|
4488
|
-
|
|
4538
|
+
win.addEventListener('popstate', function() {
|
|
4539
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4489
4540
|
});
|
|
4490
|
-
|
|
4491
|
-
|
|
4541
|
+
win.addEventListener('hashchange', function() {
|
|
4542
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4492
4543
|
});
|
|
4493
|
-
var nativePushState =
|
|
4544
|
+
var nativePushState = win.history.pushState;
|
|
4494
4545
|
if (typeof nativePushState === 'function') {
|
|
4495
|
-
|
|
4496
|
-
nativePushState.call(
|
|
4497
|
-
|
|
4546
|
+
win.history.pushState = function(state, unused, url) {
|
|
4547
|
+
nativePushState.call(win.history, state, unused, url);
|
|
4548
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4498
4549
|
};
|
|
4499
4550
|
}
|
|
4500
|
-
var nativeReplaceState =
|
|
4551
|
+
var nativeReplaceState = win.history.replaceState;
|
|
4501
4552
|
if (typeof nativeReplaceState === 'function') {
|
|
4502
|
-
|
|
4503
|
-
nativeReplaceState.call(
|
|
4504
|
-
|
|
4553
|
+
win.history.replaceState = function(state, unused, url) {
|
|
4554
|
+
nativeReplaceState.call(win.history, state, unused, url);
|
|
4555
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4505
4556
|
};
|
|
4506
4557
|
}
|
|
4507
|
-
|
|
4558
|
+
win.addEventListener('mp_locationchange', function() {
|
|
4508
4559
|
var current_url = _.info.currentUrl();
|
|
4509
4560
|
var should_track = false;
|
|
4510
4561
|
if (track_pageview_option === 'full-url') {
|
|
@@ -4997,6 +5048,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
4997
5048
|
marketing_properties,
|
|
4998
5049
|
this['persistence'].properties(),
|
|
4999
5050
|
this.unpersisted_superprops,
|
|
5051
|
+
this.get_session_recording_properties(),
|
|
5000
5052
|
properties
|
|
5001
5053
|
);
|
|
5002
5054
|
|
|
@@ -6104,38 +6156,41 @@ MixpanelLib.prototype.report_error = function(msg, err) {
|
|
|
6104
6156
|
// EXPORTS (for closure compiler)
|
|
6105
6157
|
|
|
6106
6158
|
// MixpanelLib Exports
|
|
6107
|
-
MixpanelLib.prototype['init']
|
|
6108
|
-
MixpanelLib.prototype['reset']
|
|
6109
|
-
MixpanelLib.prototype['disable']
|
|
6110
|
-
MixpanelLib.prototype['time_event']
|
|
6111
|
-
MixpanelLib.prototype['track']
|
|
6112
|
-
MixpanelLib.prototype['track_links']
|
|
6113
|
-
MixpanelLib.prototype['track_forms']
|
|
6114
|
-
MixpanelLib.prototype['track_pageview']
|
|
6115
|
-
MixpanelLib.prototype['register']
|
|
6116
|
-
MixpanelLib.prototype['register_once']
|
|
6117
|
-
MixpanelLib.prototype['unregister']
|
|
6118
|
-
MixpanelLib.prototype['identify']
|
|
6119
|
-
MixpanelLib.prototype['alias']
|
|
6120
|
-
MixpanelLib.prototype['name_tag']
|
|
6121
|
-
MixpanelLib.prototype['set_config']
|
|
6122
|
-
MixpanelLib.prototype['get_config']
|
|
6123
|
-
MixpanelLib.prototype['get_property']
|
|
6124
|
-
MixpanelLib.prototype['get_distinct_id']
|
|
6125
|
-
MixpanelLib.prototype['toString']
|
|
6126
|
-
MixpanelLib.prototype['opt_out_tracking']
|
|
6127
|
-
MixpanelLib.prototype['opt_in_tracking']
|
|
6128
|
-
MixpanelLib.prototype['has_opted_out_tracking']
|
|
6129
|
-
MixpanelLib.prototype['has_opted_in_tracking']
|
|
6130
|
-
MixpanelLib.prototype['clear_opt_in_out_tracking']
|
|
6131
|
-
MixpanelLib.prototype['get_group']
|
|
6132
|
-
MixpanelLib.prototype['set_group']
|
|
6133
|
-
MixpanelLib.prototype['add_group']
|
|
6134
|
-
MixpanelLib.prototype['remove_group']
|
|
6135
|
-
MixpanelLib.prototype['track_with_groups']
|
|
6136
|
-
MixpanelLib.prototype['start_batch_senders']
|
|
6137
|
-
MixpanelLib.prototype['stop_batch_senders']
|
|
6138
|
-
MixpanelLib.prototype['
|
|
6159
|
+
MixpanelLib.prototype['init'] = MixpanelLib.prototype.init;
|
|
6160
|
+
MixpanelLib.prototype['reset'] = MixpanelLib.prototype.reset;
|
|
6161
|
+
MixpanelLib.prototype['disable'] = MixpanelLib.prototype.disable;
|
|
6162
|
+
MixpanelLib.prototype['time_event'] = MixpanelLib.prototype.time_event;
|
|
6163
|
+
MixpanelLib.prototype['track'] = MixpanelLib.prototype.track;
|
|
6164
|
+
MixpanelLib.prototype['track_links'] = MixpanelLib.prototype.track_links;
|
|
6165
|
+
MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
|
|
6166
|
+
MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
|
|
6167
|
+
MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
|
|
6168
|
+
MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
|
|
6169
|
+
MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
|
|
6170
|
+
MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
|
|
6171
|
+
MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
|
|
6172
|
+
MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
|
|
6173
|
+
MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
|
|
6174
|
+
MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
|
|
6175
|
+
MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
|
|
6176
|
+
MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
|
|
6177
|
+
MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
|
|
6178
|
+
MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
|
|
6179
|
+
MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
|
|
6180
|
+
MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
|
|
6181
|
+
MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
|
|
6182
|
+
MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
|
|
6183
|
+
MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
|
|
6184
|
+
MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
|
|
6185
|
+
MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
|
|
6186
|
+
MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
|
|
6187
|
+
MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
|
|
6188
|
+
MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
|
|
6189
|
+
MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
|
|
6190
|
+
MixpanelLib.prototype['start_session_recording'] = MixpanelLib.prototype.start_session_recording;
|
|
6191
|
+
MixpanelLib.prototype['stop_session_recording'] = MixpanelLib.prototype.stop_session_recording;
|
|
6192
|
+
MixpanelLib.prototype['get_session_recording_properties'] = MixpanelLib.prototype.get_session_recording_properties;
|
|
6193
|
+
MixpanelLib.prototype['DEFAULT_API_ROUTES'] = DEFAULT_API_ROUTES;
|
|
6139
6194
|
|
|
6140
6195
|
// MixpanelPersistence Exports
|
|
6141
6196
|
MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
|
|
@@ -6182,7 +6237,7 @@ var override_mp_init_func = function() {
|
|
|
6182
6237
|
|
|
6183
6238
|
mixpanel_master = instance;
|
|
6184
6239
|
if (init_type === INIT_SNIPPET) {
|
|
6185
|
-
|
|
6240
|
+
win[PRIMARY_INSTANCE_NAME] = mixpanel_master;
|
|
6186
6241
|
}
|
|
6187
6242
|
extend_mp();
|
|
6188
6243
|
}
|
|
@@ -6232,7 +6287,7 @@ var add_dom_loaded_handler = function() {
|
|
|
6232
6287
|
// check to make sure we arn't in a frame
|
|
6233
6288
|
var toplevel = false;
|
|
6234
6289
|
try {
|
|
6235
|
-
toplevel =
|
|
6290
|
+
toplevel = win.frameElement === null;
|
|
6236
6291
|
} catch(e) {
|
|
6237
6292
|
// noop
|
|
6238
6293
|
}
|
|
@@ -6243,7 +6298,7 @@ var add_dom_loaded_handler = function() {
|
|
|
6243
6298
|
}
|
|
6244
6299
|
|
|
6245
6300
|
// fallback handler, always will work
|
|
6246
|
-
_.register_event(
|
|
6301
|
+
_.register_event(win, 'load', dom_loaded_handler, true);
|
|
6247
6302
|
};
|
|
6248
6303
|
|
|
6249
6304
|
function init_as_module() {
|
|
@@ -6257,6 +6312,8 @@ function init_as_module() {
|
|
|
6257
6312
|
return mixpanel_master;
|
|
6258
6313
|
}
|
|
6259
6314
|
|
|
6315
|
+
/* eslint camelcase: "off" */
|
|
6316
|
+
|
|
6260
6317
|
var mixpanel = init_as_module();
|
|
6261
6318
|
|
|
6262
|
-
module.exports = mixpanel;
|
|
6319
|
+
module.exports = mixpanel;
|