mixpanel-browser 2.48.1 → 2.50.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/.eslintignore +2 -0
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/bower.json +1 -1
- package/build.sh +14 -9
- package/dist/mixpanel-js-wrapper.js +247 -0
- package/dist/mixpanel-js-wrapper.min.js +5 -0
- package/dist/mixpanel-recorder.js +5940 -0
- package/dist/mixpanel-recorder.min.js +24 -0
- package/dist/mixpanel.amd.js +231 -66
- package/dist/mixpanel.cjs.js +230 -65
- package/dist/mixpanel.globals.js +231 -66
- package/dist/mixpanel.min.js +108 -103
- package/dist/mixpanel.umd.js +232 -67
- package/doc/readme.io/javascript-full-api-reference.md +107 -1
- package/package.json +7 -2
- package/src/config.js +1 -1
- package/src/loaders/loader-globals.js +4 -0
- package/src/{loader-module.js → loaders/loader-module.js} +1 -1
- package/src/loaders/mixpanel-js-wrapper.js +143 -0
- package/src/loaders/mixpanel-js-wrapper.md +114 -0
- package/src/mixpanel-core.js +146 -15
- package/src/mixpanel-people.js +0 -1
- package/src/recorder/index.js +153 -0
- package/src/recorder/rollup.config.js +19 -0
- package/src/utils.js +15 -3
- package/src/loader-globals.js +0 -4
- /package/{mixpanel-jslib-snippet.js → src/loaders/mixpanel-jslib-snippet.js} +0 -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.50.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;
|
|
@@ -901,6 +908,7 @@ _.UUID = (function() {
|
|
|
901
908
|
// sending false tracking data
|
|
902
909
|
var BLOCKED_UA_STRS = [
|
|
903
910
|
'ahrefsbot',
|
|
911
|
+
'ahrefssiteaudit',
|
|
904
912
|
'baiduspider',
|
|
905
913
|
'bingbot',
|
|
906
914
|
'bingpreview',
|
|
@@ -1621,7 +1629,14 @@ _.info = {
|
|
|
1621
1629
|
return '';
|
|
1622
1630
|
},
|
|
1623
1631
|
|
|
1624
|
-
|
|
1632
|
+
currentUrl: function() {
|
|
1633
|
+
return win.location.href;
|
|
1634
|
+
},
|
|
1635
|
+
|
|
1636
|
+
properties: function(extra_props) {
|
|
1637
|
+
if (typeof extra_props !== 'object') {
|
|
1638
|
+
extra_props = {};
|
|
1639
|
+
}
|
|
1625
1640
|
return _.extend(_.strip_empty_properties({
|
|
1626
1641
|
'$os': _.info.os(),
|
|
1627
1642
|
'$browser': _.info.browser(userAgent, navigator.vendor, windowOpera),
|
|
@@ -1629,7 +1644,7 @@ _.info = {
|
|
|
1629
1644
|
'$referring_domain': _.info.referringDomain(document$1.referrer),
|
|
1630
1645
|
'$device': _.info.device(userAgent)
|
|
1631
1646
|
}), {
|
|
1632
|
-
'$current_url':
|
|
1647
|
+
'$current_url': _.info.currentUrl(),
|
|
1633
1648
|
'$browser_version': _.info.browserVersion(userAgent, navigator.vendor, windowOpera),
|
|
1634
1649
|
'$screen_height': screen.height,
|
|
1635
1650
|
'$screen_width': screen.width,
|
|
@@ -1637,7 +1652,7 @@ _.info = {
|
|
|
1637
1652
|
'$lib_version': Config.LIB_VERSION,
|
|
1638
1653
|
'$insert_id': cheap_guid(),
|
|
1639
1654
|
'time': _.timestamp() / 1000 // epoch time in seconds
|
|
1640
|
-
});
|
|
1655
|
+
}, _.strip_empty_properties(extra_props));
|
|
1641
1656
|
},
|
|
1642
1657
|
|
|
1643
1658
|
people_properties: function() {
|
|
@@ -1652,10 +1667,10 @@ _.info = {
|
|
|
1652
1667
|
mpPageViewProperties: function() {
|
|
1653
1668
|
return _.strip_empty_properties({
|
|
1654
1669
|
'current_page_title': document$1.title,
|
|
1655
|
-
'current_domain':
|
|
1656
|
-
'current_url_path':
|
|
1657
|
-
'current_url_protocol':
|
|
1658
|
-
'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
|
|
1659
1674
|
});
|
|
1660
1675
|
}
|
|
1661
1676
|
};
|
|
@@ -1693,8 +1708,7 @@ var extract_domain = function(hostname) {
|
|
|
1693
1708
|
return matches ? matches[0] : '';
|
|
1694
1709
|
};
|
|
1695
1710
|
|
|
1696
|
-
var JSONStringify = null;
|
|
1697
|
-
var JSONParse = null;
|
|
1711
|
+
var JSONStringify = null, JSONParse = null;
|
|
1698
1712
|
if (typeof JSON !== 'undefined') {
|
|
1699
1713
|
JSONStringify = JSON.stringify;
|
|
1700
1714
|
JSONParse = JSON.parse;
|
|
@@ -1715,6 +1729,8 @@ _['info']['browser'] = _.info.browser;
|
|
|
1715
1729
|
_['info']['browserVersion'] = _.info.browserVersion;
|
|
1716
1730
|
_['info']['properties'] = _.info.properties;
|
|
1717
1731
|
|
|
1732
|
+
/* eslint camelcase: "off" */
|
|
1733
|
+
|
|
1718
1734
|
/**
|
|
1719
1735
|
* DomTracker Object
|
|
1720
1736
|
* @constructor
|
|
@@ -1864,8 +1880,6 @@ FormTracker.prototype.after_track_handler = function(props, options) {
|
|
|
1864
1880
|
}, 0);
|
|
1865
1881
|
};
|
|
1866
1882
|
|
|
1867
|
-
// eslint-disable-line camelcase
|
|
1868
|
-
|
|
1869
1883
|
var logger$2 = console_with_prefix('lock');
|
|
1870
1884
|
|
|
1871
1885
|
/**
|
|
@@ -2012,8 +2026,6 @@ SharedLock.prototype.withLock = function(lockedCB, errorCB, pid) {
|
|
|
2012
2026
|
}
|
|
2013
2027
|
};
|
|
2014
2028
|
|
|
2015
|
-
// eslint-disable-line camelcase
|
|
2016
|
-
|
|
2017
2029
|
var logger$1 = console_with_prefix('batch');
|
|
2018
2030
|
|
|
2019
2031
|
/**
|
|
@@ -2291,8 +2303,6 @@ RequestQueue.prototype.clear = function() {
|
|
|
2291
2303
|
this.storage.removeItem(this.storageKey);
|
|
2292
2304
|
};
|
|
2293
2305
|
|
|
2294
|
-
// eslint-disable-line camelcase
|
|
2295
|
-
|
|
2296
2306
|
// maximum interval between request retries after exponential backoff
|
|
2297
2307
|
var MAX_RETRY_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
|
|
2298
2308
|
|
|
@@ -2587,6 +2597,19 @@ RequestBatcher.prototype.reportError = function(msg, err) {
|
|
|
2587
2597
|
}
|
|
2588
2598
|
};
|
|
2589
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
|
+
|
|
2590
2613
|
/**
|
|
2591
2614
|
* A function used to track a Mixpanel event (e.g. MixpanelLib.track)
|
|
2592
2615
|
* @callback trackFunction
|
|
@@ -2772,14 +2795,14 @@ function _hasDoNotTrackFlagOn(options) {
|
|
|
2772
2795
|
if (options && options.ignoreDnt) {
|
|
2773
2796
|
return false;
|
|
2774
2797
|
}
|
|
2775
|
-
var win = (options && options.window) ||
|
|
2776
|
-
var nav = win['navigator'] || {};
|
|
2798
|
+
var win$1 = (options && options.window) || win;
|
|
2799
|
+
var nav = win$1['navigator'] || {};
|
|
2777
2800
|
var hasDntOn = false;
|
|
2778
2801
|
|
|
2779
2802
|
_.each([
|
|
2780
2803
|
nav['doNotTrack'], // standard
|
|
2781
2804
|
nav['msDoNotTrack'],
|
|
2782
|
-
win['doNotTrack']
|
|
2805
|
+
win$1['doNotTrack']
|
|
2783
2806
|
], function(dntValue) {
|
|
2784
2807
|
if (_.includes([true, 1, '1', 'yes'], dntValue)) {
|
|
2785
2808
|
hasDntOn = true;
|
|
@@ -2873,6 +2896,8 @@ function _addOptOutCheck(method, getConfigValue) {
|
|
|
2873
2896
|
};
|
|
2874
2897
|
}
|
|
2875
2898
|
|
|
2899
|
+
/* eslint camelcase: "off" */
|
|
2900
|
+
|
|
2876
2901
|
/** @const */ var SET_ACTION = '$set';
|
|
2877
2902
|
/** @const */ var SET_ONCE_ACTION = '$set_once';
|
|
2878
2903
|
/** @const */ var UNSET_ACTION = '$unset';
|
|
@@ -2990,6 +3015,8 @@ var apiActions = {
|
|
|
2990
3015
|
}
|
|
2991
3016
|
};
|
|
2992
3017
|
|
|
3018
|
+
/* eslint camelcase: "off" */
|
|
3019
|
+
|
|
2993
3020
|
/**
|
|
2994
3021
|
* Mixpanel Group Object
|
|
2995
3022
|
* @constructor
|
|
@@ -3158,6 +3185,8 @@ MixpanelGroup.prototype['union'] = MixpanelGroup.prototype.union;
|
|
|
3158
3185
|
MixpanelGroup.prototype['unset'] = MixpanelGroup.prototype.unset;
|
|
3159
3186
|
MixpanelGroup.prototype['toString'] = MixpanelGroup.prototype.toString;
|
|
3160
3187
|
|
|
3188
|
+
/* eslint camelcase: "off" */
|
|
3189
|
+
|
|
3161
3190
|
/**
|
|
3162
3191
|
* Mixpanel People Object
|
|
3163
3192
|
* @constructor
|
|
@@ -3203,7 +3232,6 @@ MixpanelPeople.prototype.set = addOptOutCheckMixpanelPeople(function(prop, to, c
|
|
|
3203
3232
|
data[SET_ACTION] = _.extend(
|
|
3204
3233
|
{},
|
|
3205
3234
|
_.info.people_properties(),
|
|
3206
|
-
this._mixpanel['persistence'].get_referrer_info(),
|
|
3207
3235
|
data[SET_ACTION]
|
|
3208
3236
|
);
|
|
3209
3237
|
return this._send_request(data, callback);
|
|
@@ -3627,6 +3655,8 @@ MixpanelPeople.prototype['clear_charges'] = MixpanelPeople.prototype.clear_charg
|
|
|
3627
3655
|
MixpanelPeople.prototype['delete_user'] = MixpanelPeople.prototype.delete_user;
|
|
3628
3656
|
MixpanelPeople.prototype['toString'] = MixpanelPeople.prototype.toString;
|
|
3629
3657
|
|
|
3658
|
+
/* eslint camelcase: "off" */
|
|
3659
|
+
|
|
3630
3660
|
/*
|
|
3631
3661
|
* Constants
|
|
3632
3662
|
*/
|
|
@@ -4076,6 +4106,8 @@ MixpanelPersistence.prototype.remove_event_timer = function(event_name) {
|
|
|
4076
4106
|
return timestamp;
|
|
4077
4107
|
};
|
|
4078
4108
|
|
|
4109
|
+
/* eslint camelcase: "off" */
|
|
4110
|
+
|
|
4079
4111
|
/*
|
|
4080
4112
|
* Mixpanel JS Library
|
|
4081
4113
|
*
|
|
@@ -4122,7 +4154,7 @@ var NOOP_FUNC = function() {};
|
|
|
4122
4154
|
*/
|
|
4123
4155
|
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
|
|
4124
4156
|
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#withCredentials
|
|
4125
|
-
var USE_XHR = (
|
|
4157
|
+
var USE_XHR = (win.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest());
|
|
4126
4158
|
|
|
4127
4159
|
// IE<10 does not support cross-origin XHR's but script tags
|
|
4128
4160
|
// with defer won't block window.onload; ENQUEUE_REQUESTS
|
|
@@ -4141,7 +4173,8 @@ if (navigator['sendBeacon']) {
|
|
|
4141
4173
|
var DEFAULT_API_ROUTES = {
|
|
4142
4174
|
'track': 'track/',
|
|
4143
4175
|
'engage': 'engage/',
|
|
4144
|
-
'groups': 'groups/'
|
|
4176
|
+
'groups': 'groups/',
|
|
4177
|
+
'record': 'record/'
|
|
4145
4178
|
};
|
|
4146
4179
|
|
|
4147
4180
|
/*
|
|
@@ -4163,10 +4196,12 @@ var DEFAULT_CONFIG = {
|
|
|
4163
4196
|
'cookie_domain': '',
|
|
4164
4197
|
'cookie_name': '',
|
|
4165
4198
|
'loaded': NOOP_FUNC,
|
|
4199
|
+
'mp_loader': null,
|
|
4166
4200
|
'track_marketing': true,
|
|
4167
4201
|
'track_pageview': false,
|
|
4168
4202
|
'skip_first_touch_marketing': false,
|
|
4169
4203
|
'store_google': true,
|
|
4204
|
+
'stop_utm_persistence': false,
|
|
4170
4205
|
'save_referrer': true,
|
|
4171
4206
|
'test': false,
|
|
4172
4207
|
'verbose': false,
|
|
@@ -4191,7 +4226,12 @@ var DEFAULT_CONFIG = {
|
|
|
4191
4226
|
'batch_flush_interval_ms': 5000,
|
|
4192
4227
|
'batch_request_timeout_ms': 90000,
|
|
4193
4228
|
'batch_autostart': true,
|
|
4194
|
-
'hooks': {}
|
|
4229
|
+
'hooks': {},
|
|
4230
|
+
'record_sessions_percent': 0,
|
|
4231
|
+
'record_idle_timeout_ms': 30 * 60 * 1000, // 30 minutes
|
|
4232
|
+
'record_max_ms': MAX_RECORDING_MS,
|
|
4233
|
+
'record_mask_text_selector': '*',
|
|
4234
|
+
'recorder_src': 'https://cdn.mxpnl.com/libs/mixpanel-recorder.min.js'
|
|
4195
4235
|
};
|
|
4196
4236
|
|
|
4197
4237
|
var DOM_LOADED = false;
|
|
@@ -4354,7 +4394,7 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4354
4394
|
});
|
|
4355
4395
|
} else {
|
|
4356
4396
|
this.init_batchers();
|
|
4357
|
-
if (sendBeacon &&
|
|
4397
|
+
if (sendBeacon && win.addEventListener) {
|
|
4358
4398
|
// Before page closes or hides (user tabs away etc), attempt to flush any events
|
|
4359
4399
|
// queued up via navigator.sendBeacon. Since sendBeacon doesn't report success/failure,
|
|
4360
4400
|
// events will not be removed from the persistent store; if the site is loaded again,
|
|
@@ -4371,12 +4411,12 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4371
4411
|
this.request_batchers.events.flush({unloading: true});
|
|
4372
4412
|
}
|
|
4373
4413
|
}, this);
|
|
4374
|
-
|
|
4414
|
+
win.addEventListener('pagehide', function(ev) {
|
|
4375
4415
|
if (ev['persisted']) {
|
|
4376
4416
|
flush_on_unload();
|
|
4377
4417
|
}
|
|
4378
4418
|
});
|
|
4379
|
-
|
|
4419
|
+
win.addEventListener('visibilitychange', function() {
|
|
4380
4420
|
if (document$1['visibilityState'] === 'hidden') {
|
|
4381
4421
|
flush_on_unload();
|
|
4382
4422
|
}
|
|
@@ -4400,8 +4440,44 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4400
4440
|
}, '');
|
|
4401
4441
|
}
|
|
4402
4442
|
|
|
4403
|
-
|
|
4404
|
-
|
|
4443
|
+
var track_pageview_option = this.get_config('track_pageview');
|
|
4444
|
+
if (track_pageview_option) {
|
|
4445
|
+
this._init_url_change_tracking(track_pageview_option);
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4448
|
+
if (this.get_config('record_sessions_percent') > 0 && Math.random() * 100 <= this.get_config('record_sessions_percent')) {
|
|
4449
|
+
this.start_session_recording();
|
|
4450
|
+
}
|
|
4451
|
+
};
|
|
4452
|
+
|
|
4453
|
+
MixpanelLib.prototype.start_session_recording = addOptOutCheckMixpanelLib(function () {
|
|
4454
|
+
if (!win['MutationObserver']) {
|
|
4455
|
+
console.critical('Browser does not support MutationObserver; skipping session recording');
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
|
|
4459
|
+
var handleLoadedRecorder = _.bind(function() {
|
|
4460
|
+
this._recorder = this._recorder || new win['__mp_recorder'](this);
|
|
4461
|
+
this._recorder['startRecording']();
|
|
4462
|
+
}, this);
|
|
4463
|
+
|
|
4464
|
+
if (_.isUndefined(win['__mp_recorder'])) {
|
|
4465
|
+
var scriptEl = document$1.createElement('script');
|
|
4466
|
+
scriptEl.type = 'text/javascript';
|
|
4467
|
+
scriptEl.async = true;
|
|
4468
|
+
scriptEl.onload = handleLoadedRecorder;
|
|
4469
|
+
scriptEl.src = this.get_config('recorder_src');
|
|
4470
|
+
document$1.head.appendChild(scriptEl);
|
|
4471
|
+
} else {
|
|
4472
|
+
handleLoadedRecorder();
|
|
4473
|
+
}
|
|
4474
|
+
});
|
|
4475
|
+
|
|
4476
|
+
MixpanelLib.prototype.stop_session_recording = function () {
|
|
4477
|
+
if (this._recorder) {
|
|
4478
|
+
this._recorder['stopRecording']();
|
|
4479
|
+
} else {
|
|
4480
|
+
console.critical('Session recorder module not loaded');
|
|
4405
4481
|
}
|
|
4406
4482
|
};
|
|
4407
4483
|
|
|
@@ -4410,12 +4486,25 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4410
4486
|
MixpanelLib.prototype._loaded = function() {
|
|
4411
4487
|
this.get_config('loaded')(this);
|
|
4412
4488
|
this._set_default_superprops();
|
|
4489
|
+
this['people'].set_once(this['persistence'].get_referrer_info());
|
|
4490
|
+
|
|
4491
|
+
// The original 'store_google' functionality will be deprecated and the config will be
|
|
4492
|
+
// used to clear previously managed UTM parameters from persistence.
|
|
4493
|
+
// stop_utm_persistence is `false` by default now but will be default `true` in the future.
|
|
4494
|
+
if (this.get_config('store_google') && this.get_config('stop_utm_persistence')) {
|
|
4495
|
+
var utm_params = _.info.campaignParams(null);
|
|
4496
|
+
_.each(utm_params, function(_utm_value, utm_key) {
|
|
4497
|
+
// We need to unregister persisted UTM parameters so old values
|
|
4498
|
+
// are not mixed with the new UTM parameters
|
|
4499
|
+
this.unregister(utm_key);
|
|
4500
|
+
}.bind(this));
|
|
4501
|
+
}
|
|
4413
4502
|
};
|
|
4414
4503
|
|
|
4415
4504
|
// update persistence with info on referrer, UTM params, etc
|
|
4416
4505
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
4417
4506
|
this['persistence'].update_search_keyword(document$1.referrer);
|
|
4418
|
-
if (this.get_config('store_google')) {
|
|
4507
|
+
if (this.get_config('store_google') && !this.get_config('stop_utm_persistence')) {
|
|
4419
4508
|
this.register(_.info.campaignParams());
|
|
4420
4509
|
}
|
|
4421
4510
|
if (this.get_config('save_referrer')) {
|
|
@@ -4453,6 +4542,55 @@ MixpanelLib.prototype._track_dom = function(DomClass, args) {
|
|
|
4453
4542
|
return dt.track.apply(dt, args);
|
|
4454
4543
|
};
|
|
4455
4544
|
|
|
4545
|
+
MixpanelLib.prototype._init_url_change_tracking = function(track_pageview_option) {
|
|
4546
|
+
var previous_tracked_url = '';
|
|
4547
|
+
var tracked = this.track_pageview();
|
|
4548
|
+
if (tracked) {
|
|
4549
|
+
previous_tracked_url = _.info.currentUrl();
|
|
4550
|
+
}
|
|
4551
|
+
|
|
4552
|
+
if (_.include(['full-url', 'url-with-path-and-query-string', 'url-with-path'], track_pageview_option)) {
|
|
4553
|
+
win.addEventListener('popstate', function() {
|
|
4554
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4555
|
+
});
|
|
4556
|
+
win.addEventListener('hashchange', function() {
|
|
4557
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4558
|
+
});
|
|
4559
|
+
var nativePushState = win.history.pushState;
|
|
4560
|
+
if (typeof nativePushState === 'function') {
|
|
4561
|
+
win.history.pushState = function(state, unused, url) {
|
|
4562
|
+
nativePushState.call(win.history, state, unused, url);
|
|
4563
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4564
|
+
};
|
|
4565
|
+
}
|
|
4566
|
+
var nativeReplaceState = win.history.replaceState;
|
|
4567
|
+
if (typeof nativeReplaceState === 'function') {
|
|
4568
|
+
win.history.replaceState = function(state, unused, url) {
|
|
4569
|
+
nativeReplaceState.call(win.history, state, unused, url);
|
|
4570
|
+
win.dispatchEvent(new Event('mp_locationchange'));
|
|
4571
|
+
};
|
|
4572
|
+
}
|
|
4573
|
+
win.addEventListener('mp_locationchange', function() {
|
|
4574
|
+
var current_url = _.info.currentUrl();
|
|
4575
|
+
var should_track = false;
|
|
4576
|
+
if (track_pageview_option === 'full-url') {
|
|
4577
|
+
should_track = current_url !== previous_tracked_url;
|
|
4578
|
+
} else if (track_pageview_option === 'url-with-path-and-query-string') {
|
|
4579
|
+
should_track = current_url.split('#')[0] !== previous_tracked_url.split('#')[0];
|
|
4580
|
+
} else if (track_pageview_option === 'url-with-path') {
|
|
4581
|
+
should_track = current_url.split('#')[0].split('?')[0] !== previous_tracked_url.split('#')[0].split('?')[0];
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4584
|
+
if (should_track) {
|
|
4585
|
+
var tracked = this.track_pageview();
|
|
4586
|
+
if (tracked) {
|
|
4587
|
+
previous_tracked_url = current_url;
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
}.bind(this));
|
|
4591
|
+
}
|
|
4592
|
+
};
|
|
4593
|
+
|
|
4456
4594
|
/**
|
|
4457
4595
|
* _prepare_callback() should be called by callers of _send_request for use
|
|
4458
4596
|
* as the callback argument.
|
|
@@ -4914,6 +5052,13 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
4914
5052
|
? _.info.marketingParams()
|
|
4915
5053
|
: {};
|
|
4916
5054
|
|
|
5055
|
+
if (this._recorder) {
|
|
5056
|
+
var replay_id = this._recorder['replayId'];
|
|
5057
|
+
if (replay_id) {
|
|
5058
|
+
properties['$mp_replay_id'] = replay_id;
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
|
|
4917
5062
|
// note: extend writes to the first object, so lets make sure we
|
|
4918
5063
|
// don't write to the persistence properties object and info
|
|
4919
5064
|
// properties object by passing in a new object
|
|
@@ -4921,7 +5066,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
4921
5066
|
// update properties with pageview info and super-properties
|
|
4922
5067
|
properties = _.extend(
|
|
4923
5068
|
{},
|
|
4924
|
-
_.info.properties(),
|
|
5069
|
+
_.info.properties({'mp_loader': this.get_config('mp_loader')}),
|
|
4925
5070
|
marketing_properties,
|
|
4926
5071
|
this['persistence'].properties(),
|
|
4927
5072
|
this.unpersisted_superprops,
|
|
@@ -5085,10 +5230,9 @@ MixpanelLib.prototype.get_group = function (group_key, group_id) {
|
|
|
5085
5230
|
|
|
5086
5231
|
/**
|
|
5087
5232
|
* Track a default Mixpanel page view event, which includes extra default event properties to
|
|
5088
|
-
* improve page view data.
|
|
5089
|
-
* may be turned on for tracking page loads automatically.
|
|
5233
|
+
* improve page view data.
|
|
5090
5234
|
*
|
|
5091
|
-
* ### Usage
|
|
5235
|
+
* ### Usage:
|
|
5092
5236
|
*
|
|
5093
5237
|
* // track a default $mp_web_page_view event
|
|
5094
5238
|
* mixpanel.track_pageview();
|
|
@@ -5105,6 +5249,23 @@ MixpanelLib.prototype.get_group = function (group_key, group_id) {
|
|
|
5105
5249
|
* // views on different products or internal applications that are considered completely separate
|
|
5106
5250
|
* mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
|
|
5107
5251
|
*
|
|
5252
|
+
* ### Notes:
|
|
5253
|
+
*
|
|
5254
|
+
* The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
|
|
5255
|
+
* may be turned on for tracking page loads automatically.
|
|
5256
|
+
*
|
|
5257
|
+
* // track only page loads
|
|
5258
|
+
* mixpanel.init(PROJECT_TOKEN, {track_pageview: true});
|
|
5259
|
+
*
|
|
5260
|
+
* // track when the URL changes in any manner
|
|
5261
|
+
* mixpanel.init(PROJECT_TOKEN, {track_pageview: 'full-url'});
|
|
5262
|
+
*
|
|
5263
|
+
* // track when the URL changes, ignoring any changes in the hash part
|
|
5264
|
+
* mixpanel.init(PROJECT_TOKEN, {track_pageview: 'url-with-path-and-query-string'});
|
|
5265
|
+
*
|
|
5266
|
+
* // track when the path changes, ignoring any query parameter or hash changes
|
|
5267
|
+
* mixpanel.init(PROJECT_TOKEN, {track_pageview: 'url-with-path'});
|
|
5268
|
+
*
|
|
5108
5269
|
* @param {Object} [properties] An optional set of additional properties to send with the page view event
|
|
5109
5270
|
* @param {Object} [options] Page view tracking options
|
|
5110
5271
|
* @param {String} [options.event_name] - Alternate name for the tracking event
|
|
@@ -5855,7 +6016,7 @@ MixpanelLib.prototype._gdpr_call_func = function(func, options) {
|
|
|
5855
6016
|
/**
|
|
5856
6017
|
* Opt the user in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
5857
6018
|
*
|
|
5858
|
-
* ### Usage
|
|
6019
|
+
* ### Usage:
|
|
5859
6020
|
*
|
|
5860
6021
|
* // opt user in
|
|
5861
6022
|
* mixpanel.opt_in_tracking();
|
|
@@ -5895,7 +6056,7 @@ MixpanelLib.prototype.opt_in_tracking = function(options) {
|
|
|
5895
6056
|
/**
|
|
5896
6057
|
* Opt the user out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
5897
6058
|
*
|
|
5898
|
-
* ### Usage
|
|
6059
|
+
* ### Usage:
|
|
5899
6060
|
*
|
|
5900
6061
|
* // opt user out
|
|
5901
6062
|
* mixpanel.opt_out_tracking();
|
|
@@ -5936,7 +6097,7 @@ MixpanelLib.prototype.opt_out_tracking = function(options) {
|
|
|
5936
6097
|
/**
|
|
5937
6098
|
* Check whether the user has opted in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
5938
6099
|
*
|
|
5939
|
-
* ### Usage
|
|
6100
|
+
* ### Usage:
|
|
5940
6101
|
*
|
|
5941
6102
|
* var has_opted_in = mixpanel.has_opted_in_tracking();
|
|
5942
6103
|
* // use has_opted_in value
|
|
@@ -5953,7 +6114,7 @@ MixpanelLib.prototype.has_opted_in_tracking = function(options) {
|
|
|
5953
6114
|
/**
|
|
5954
6115
|
* Check whether the user has opted out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
5955
6116
|
*
|
|
5956
|
-
* ### Usage
|
|
6117
|
+
* ### Usage:
|
|
5957
6118
|
*
|
|
5958
6119
|
* var has_opted_out = mixpanel.has_opted_out_tracking();
|
|
5959
6120
|
* // use has_opted_out value
|
|
@@ -5970,7 +6131,7 @@ MixpanelLib.prototype.has_opted_out_tracking = function(options) {
|
|
|
5970
6131
|
/**
|
|
5971
6132
|
* Clear the user's opt in/out status of data tracking and cookies/localstorage for this Mixpanel instance
|
|
5972
6133
|
*
|
|
5973
|
-
* ### Usage
|
|
6134
|
+
* ### Usage:
|
|
5974
6135
|
*
|
|
5975
6136
|
* // clear user's opt-in/out status
|
|
5976
6137
|
* mixpanel.clear_opt_in_out_tracking();
|
|
@@ -6047,6 +6208,8 @@ MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remov
|
|
|
6047
6208
|
MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
|
|
6048
6209
|
MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
|
|
6049
6210
|
MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
|
|
6211
|
+
MixpanelLib.prototype['start_session_recording'] = MixpanelLib.prototype.start_session_recording;
|
|
6212
|
+
MixpanelLib.prototype['stop_session_recording'] = MixpanelLib.prototype.stop_session_recording;
|
|
6050
6213
|
MixpanelLib.prototype['DEFAULT_API_ROUTES'] = DEFAULT_API_ROUTES;
|
|
6051
6214
|
|
|
6052
6215
|
// MixpanelPersistence Exports
|
|
@@ -6094,7 +6257,7 @@ var override_mp_init_func = function() {
|
|
|
6094
6257
|
|
|
6095
6258
|
mixpanel_master = instance;
|
|
6096
6259
|
if (init_type === INIT_SNIPPET) {
|
|
6097
|
-
|
|
6260
|
+
win[PRIMARY_INSTANCE_NAME] = mixpanel_master;
|
|
6098
6261
|
}
|
|
6099
6262
|
extend_mp();
|
|
6100
6263
|
}
|
|
@@ -6144,7 +6307,7 @@ var add_dom_loaded_handler = function() {
|
|
|
6144
6307
|
// check to make sure we arn't in a frame
|
|
6145
6308
|
var toplevel = false;
|
|
6146
6309
|
try {
|
|
6147
|
-
toplevel =
|
|
6310
|
+
toplevel = win.frameElement === null;
|
|
6148
6311
|
} catch(e) {
|
|
6149
6312
|
// noop
|
|
6150
6313
|
}
|
|
@@ -6155,7 +6318,7 @@ var add_dom_loaded_handler = function() {
|
|
|
6155
6318
|
}
|
|
6156
6319
|
|
|
6157
6320
|
// fallback handler, always will work
|
|
6158
|
-
_.register_event(
|
|
6321
|
+
_.register_event(win, 'load', dom_loaded_handler, true);
|
|
6159
6322
|
};
|
|
6160
6323
|
|
|
6161
6324
|
function init_as_module() {
|
|
@@ -6169,6 +6332,8 @@ function init_as_module() {
|
|
|
6169
6332
|
return mixpanel_master;
|
|
6170
6333
|
}
|
|
6171
6334
|
|
|
6335
|
+
/* eslint camelcase: "off" */
|
|
6336
|
+
|
|
6172
6337
|
var mixpanel = init_as_module();
|
|
6173
6338
|
|
|
6174
|
-
module.exports = mixpanel;
|
|
6339
|
+
module.exports = mixpanel;
|