mixpanel-browser 2.57.1 → 2.59.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 +8 -0
- package/dist/mixpanel-core.cjs.js +721 -56
- package/dist/mixpanel-recorder.js +19 -4
- package/dist/mixpanel-recorder.min.js +2 -2
- package/dist/mixpanel-recorder.min.js.map +1 -1
- package/dist/mixpanel-with-async-recorder.cjs.js +721 -56
- package/dist/mixpanel.amd.js +752 -76
- package/dist/mixpanel.cjs.js +752 -76
- package/dist/mixpanel.globals.js +721 -56
- package/dist/mixpanel.min.js +134 -122
- package/dist/mixpanel.module.js +752 -76
- package/dist/mixpanel.umd.js +752 -76
- package/package.json +1 -1
- package/src/autocapture/index.js +271 -0
- package/src/autocapture/utils.js +434 -0
- package/src/config.js +1 -1
- package/src/mixpanel-core.js +9 -53
- package/src/recorder/session-recording.js +12 -1
- package/src/utils.js +27 -1
- package/src/window.js +4 -1
package/dist/mixpanel.umd.js
CHANGED
|
@@ -4513,7 +4513,7 @@
|
|
|
4513
4513
|
|
|
4514
4514
|
var Config = {
|
|
4515
4515
|
DEBUG: false,
|
|
4516
|
-
LIB_VERSION: '2.
|
|
4516
|
+
LIB_VERSION: '2.59.0'
|
|
4517
4517
|
};
|
|
4518
4518
|
|
|
4519
4519
|
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
|
|
@@ -4525,11 +4525,14 @@
|
|
|
4525
4525
|
win = {
|
|
4526
4526
|
navigator: { userAgent: '', onLine: true },
|
|
4527
4527
|
document: {
|
|
4528
|
+
createElement: function() { return {}; },
|
|
4528
4529
|
location: loc,
|
|
4529
4530
|
referrer: ''
|
|
4530
4531
|
},
|
|
4531
4532
|
screen: { width: 0, height: 0 },
|
|
4532
|
-
location: loc
|
|
4533
|
+
location: loc,
|
|
4534
|
+
addEventListener: function() {},
|
|
4535
|
+
removeEventListener: function() {}
|
|
4533
4536
|
};
|
|
4534
4537
|
} else {
|
|
4535
4538
|
win = window;
|
|
@@ -5006,6 +5009,29 @@
|
|
|
5006
5009
|
};
|
|
5007
5010
|
|
|
5008
5011
|
|
|
5012
|
+
var safewrap = function(f) {
|
|
5013
|
+
return function() {
|
|
5014
|
+
try {
|
|
5015
|
+
return f.apply(this, arguments);
|
|
5016
|
+
} catch (e) {
|
|
5017
|
+
console$1.critical('Implementation error. Please turn on debug and contact support@mixpanel.com.');
|
|
5018
|
+
if (Config.DEBUG){
|
|
5019
|
+
console$1.critical(e);
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
};
|
|
5023
|
+
};
|
|
5024
|
+
|
|
5025
|
+
var safewrapClass = function(klass) {
|
|
5026
|
+
var proto = klass.prototype;
|
|
5027
|
+
for (var func in proto) {
|
|
5028
|
+
if (typeof(proto[func]) === 'function') {
|
|
5029
|
+
proto[func] = safewrap(proto[func]);
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
};
|
|
5033
|
+
|
|
5034
|
+
|
|
5009
5035
|
// UNDERSCORE
|
|
5010
5036
|
// Embed part of the Underscore Library
|
|
5011
5037
|
_.bind = function(func, context) {
|
|
@@ -5784,6 +5810,7 @@
|
|
|
5784
5810
|
var BLOCKED_UA_STRS = [
|
|
5785
5811
|
'ahrefsbot',
|
|
5786
5812
|
'ahrefssiteaudit',
|
|
5813
|
+
'amazonbot',
|
|
5787
5814
|
'baiduspider',
|
|
5788
5815
|
'bingbot',
|
|
5789
5816
|
'bingpreview',
|
|
@@ -5793,7 +5820,7 @@
|
|
|
5793
5820
|
'pinterest',
|
|
5794
5821
|
'screaming frog',
|
|
5795
5822
|
'yahoo! slurp',
|
|
5796
|
-
'
|
|
5823
|
+
'yandex',
|
|
5797
5824
|
|
|
5798
5825
|
// a whole bunch of goog-specific crawlers
|
|
5799
5826
|
// https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers
|
|
@@ -6913,7 +6940,7 @@
|
|
|
6913
6940
|
};
|
|
6914
6941
|
}
|
|
6915
6942
|
|
|
6916
|
-
var logger$
|
|
6943
|
+
var logger$5 = console_with_prefix('lock');
|
|
6917
6944
|
|
|
6918
6945
|
/**
|
|
6919
6946
|
* SharedLock: a mutex built on HTML5 localStorage, to ensure that only one browser
|
|
@@ -6966,7 +6993,7 @@
|
|
|
6966
6993
|
|
|
6967
6994
|
var delay = function(cb) {
|
|
6968
6995
|
if (new Date().getTime() - startTime > timeoutMS) {
|
|
6969
|
-
logger$
|
|
6996
|
+
logger$5.error('Timeout waiting for mutex on ' + key + '; clearing lock. [' + i + ']');
|
|
6970
6997
|
storage.removeItem(keyZ);
|
|
6971
6998
|
storage.removeItem(keyY);
|
|
6972
6999
|
loop();
|
|
@@ -7113,7 +7140,7 @@
|
|
|
7113
7140
|
}, this));
|
|
7114
7141
|
};
|
|
7115
7142
|
|
|
7116
|
-
var logger$
|
|
7143
|
+
var logger$4 = console_with_prefix('batch');
|
|
7117
7144
|
|
|
7118
7145
|
/**
|
|
7119
7146
|
* RequestQueue: queue for batching API requests with localStorage backup for retries.
|
|
@@ -7140,7 +7167,7 @@
|
|
|
7140
7167
|
this.lock = new SharedLock(storageKey, { storage: options.sharedLockStorage || window.localStorage });
|
|
7141
7168
|
this.queueStorage.init();
|
|
7142
7169
|
}
|
|
7143
|
-
this.reportError = options.errorReporter || _.bind(logger$
|
|
7170
|
+
this.reportError = options.errorReporter || _.bind(logger$4.error, logger$4);
|
|
7144
7171
|
|
|
7145
7172
|
this.pid = options.pid || null; // pass pid to test out storage lock contention scenarios
|
|
7146
7173
|
|
|
@@ -7470,7 +7497,7 @@
|
|
|
7470
7497
|
// maximum interval between request retries after exponential backoff
|
|
7471
7498
|
var MAX_RETRY_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
|
|
7472
7499
|
|
|
7473
|
-
var logger$
|
|
7500
|
+
var logger$3 = console_with_prefix('batch');
|
|
7474
7501
|
|
|
7475
7502
|
/**
|
|
7476
7503
|
* RequestBatcher: manages the queueing, flushing, retry etc of requests of one
|
|
@@ -7594,7 +7621,7 @@
|
|
|
7594
7621
|
*/
|
|
7595
7622
|
RequestBatcher.prototype.flush = function(options) {
|
|
7596
7623
|
if (this.requestInProgress) {
|
|
7597
|
-
logger$
|
|
7624
|
+
logger$3.log('Flush: Request already in progress');
|
|
7598
7625
|
return PromisePolyfill.resolve();
|
|
7599
7626
|
}
|
|
7600
7627
|
|
|
@@ -7771,7 +7798,7 @@
|
|
|
7771
7798
|
if (options.unloading) {
|
|
7772
7799
|
requestOptions.transport = 'sendBeacon';
|
|
7773
7800
|
}
|
|
7774
|
-
logger$
|
|
7801
|
+
logger$3.log('MIXPANEL REQUEST:', dataForRequest);
|
|
7775
7802
|
return this.sendRequestPromise(dataForRequest, requestOptions).then(batchSendCallback);
|
|
7776
7803
|
}, this))
|
|
7777
7804
|
.catch(_.bind(function(err) {
|
|
@@ -7784,7 +7811,7 @@
|
|
|
7784
7811
|
* Log error to global logger and optional user-defined logger.
|
|
7785
7812
|
*/
|
|
7786
7813
|
RequestBatcher.prototype.reportError = function(msg, err) {
|
|
7787
|
-
logger$
|
|
7814
|
+
logger$3.error.apply(logger$3.error, arguments);
|
|
7788
7815
|
if (this.errorReporter) {
|
|
7789
7816
|
try {
|
|
7790
7817
|
if (!(err instanceof Error)) {
|
|
@@ -7792,12 +7819,12 @@
|
|
|
7792
7819
|
}
|
|
7793
7820
|
this.errorReporter(msg, err);
|
|
7794
7821
|
} catch(err) {
|
|
7795
|
-
logger$
|
|
7822
|
+
logger$3.error(err);
|
|
7796
7823
|
}
|
|
7797
7824
|
}
|
|
7798
7825
|
};
|
|
7799
7826
|
|
|
7800
|
-
var logger$
|
|
7827
|
+
var logger$2 = console_with_prefix('recorder');
|
|
7801
7828
|
var CompressionStream = win['CompressionStream'];
|
|
7802
7829
|
|
|
7803
7830
|
var RECORDER_BATCHER_LIB_CONFIG = {
|
|
@@ -7844,6 +7871,7 @@
|
|
|
7844
7871
|
|
|
7845
7872
|
this.seqNo = 0;
|
|
7846
7873
|
this.replayStartTime = null;
|
|
7874
|
+
this.replayStartUrl = null;
|
|
7847
7875
|
this.batchStartUrl = null;
|
|
7848
7876
|
|
|
7849
7877
|
this.idleTimeoutId = null;
|
|
@@ -7877,24 +7905,25 @@
|
|
|
7877
7905
|
|
|
7878
7906
|
SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
|
|
7879
7907
|
if (this._stopRecording !== null) {
|
|
7880
|
-
logger$
|
|
7908
|
+
logger$2.log('Recording already in progress, skipping startRecording.');
|
|
7881
7909
|
return;
|
|
7882
7910
|
}
|
|
7883
7911
|
|
|
7884
7912
|
this.recordMaxMs = this.getConfig('record_max_ms');
|
|
7885
7913
|
if (this.recordMaxMs > MAX_RECORDING_MS) {
|
|
7886
7914
|
this.recordMaxMs = MAX_RECORDING_MS;
|
|
7887
|
-
logger$
|
|
7915
|
+
logger$2.critical('record_max_ms cannot be greater than ' + MAX_RECORDING_MS + 'ms. Capping value.');
|
|
7888
7916
|
}
|
|
7889
7917
|
|
|
7890
7918
|
this.recordMinMs = this.getConfig('record_min_ms');
|
|
7891
7919
|
if (this.recordMinMs > MAX_VALUE_FOR_MIN_RECORDING_MS) {
|
|
7892
7920
|
this.recordMinMs = MAX_VALUE_FOR_MIN_RECORDING_MS;
|
|
7893
|
-
logger$
|
|
7921
|
+
logger$2.critical('record_min_ms cannot be greater than ' + MAX_VALUE_FOR_MIN_RECORDING_MS + 'ms. Capping value.');
|
|
7894
7922
|
}
|
|
7895
7923
|
|
|
7896
7924
|
this.replayStartTime = new Date().getTime();
|
|
7897
7925
|
this.batchStartUrl = _.info.currentUrl();
|
|
7926
|
+
this.replayStartUrl = _.info.currentUrl();
|
|
7898
7927
|
|
|
7899
7928
|
if (shouldStopBatcher || this.recordMinMs > 0) {
|
|
7900
7929
|
// the primary case for shouldStopBatcher is when we're starting recording after a reset
|
|
@@ -7931,9 +7960,17 @@
|
|
|
7931
7960
|
'blockClass': this.getConfig('record_block_class'),
|
|
7932
7961
|
'blockSelector': blockSelector,
|
|
7933
7962
|
'collectFonts': this.getConfig('record_collect_fonts'),
|
|
7963
|
+
'dataURLOptions': { // canvas image options (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL)
|
|
7964
|
+
'type': 'image/webp',
|
|
7965
|
+
'quality': 0.6
|
|
7966
|
+
},
|
|
7934
7967
|
'maskAllInputs': true,
|
|
7935
7968
|
'maskTextClass': this.getConfig('record_mask_text_class'),
|
|
7936
|
-
'maskTextSelector': this.getConfig('record_mask_text_selector')
|
|
7969
|
+
'maskTextSelector': this.getConfig('record_mask_text_selector'),
|
|
7970
|
+
'recordCanvas': this.getConfig('record_canvas'),
|
|
7971
|
+
'sampling': {
|
|
7972
|
+
'canvas': 15
|
|
7973
|
+
}
|
|
7937
7974
|
});
|
|
7938
7975
|
|
|
7939
7976
|
if (typeof this._stopRecording !== 'function') {
|
|
@@ -8051,6 +8088,7 @@
|
|
|
8051
8088
|
'replay_id': replayId,
|
|
8052
8089
|
'replay_length_ms': replayLengthMs,
|
|
8053
8090
|
'replay_start_time': this.replayStartTime / 1000,
|
|
8091
|
+
'replay_start_url': this.replayStartUrl,
|
|
8054
8092
|
'seq': this.seqNo
|
|
8055
8093
|
};
|
|
8056
8094
|
var eventsJson = _.JSONEncode(data);
|
|
@@ -8083,18 +8121,18 @@
|
|
|
8083
8121
|
|
|
8084
8122
|
|
|
8085
8123
|
SessionRecording.prototype.reportError = function(msg, err) {
|
|
8086
|
-
logger$
|
|
8124
|
+
logger$2.error.apply(logger$2.error, arguments);
|
|
8087
8125
|
try {
|
|
8088
8126
|
if (!err && !(msg instanceof Error)) {
|
|
8089
8127
|
msg = new Error(msg);
|
|
8090
8128
|
}
|
|
8091
8129
|
this.getConfig('error_reporter')(msg, err);
|
|
8092
8130
|
} catch(err) {
|
|
8093
|
-
logger$
|
|
8131
|
+
logger$2.error(err);
|
|
8094
8132
|
}
|
|
8095
8133
|
};
|
|
8096
8134
|
|
|
8097
|
-
var logger = console_with_prefix('recorder');
|
|
8135
|
+
var logger$1 = console_with_prefix('recorder');
|
|
8098
8136
|
|
|
8099
8137
|
/**
|
|
8100
8138
|
* Recorder API: manages recordings and exposes methods public to the core Mixpanel library.
|
|
@@ -8107,17 +8145,17 @@
|
|
|
8107
8145
|
|
|
8108
8146
|
MixpanelRecorder.prototype.startRecording = function(shouldStopBatcher) {
|
|
8109
8147
|
if (this.activeRecording && !this.activeRecording.isRrwebStopped()) {
|
|
8110
|
-
logger.log('Recording already in progress, skipping startRecording.');
|
|
8148
|
+
logger$1.log('Recording already in progress, skipping startRecording.');
|
|
8111
8149
|
return;
|
|
8112
8150
|
}
|
|
8113
8151
|
|
|
8114
8152
|
var onIdleTimeout = _.bind(function () {
|
|
8115
|
-
logger.log('Idle timeout reached, restarting recording.');
|
|
8153
|
+
logger$1.log('Idle timeout reached, restarting recording.');
|
|
8116
8154
|
this.resetRecording();
|
|
8117
8155
|
}, this);
|
|
8118
8156
|
|
|
8119
8157
|
var onMaxLengthReached = _.bind(function () {
|
|
8120
|
-
logger.log('Max recording length reached, stopping recording.');
|
|
8158
|
+
logger$1.log('Max recording length reached, stopping recording.');
|
|
8121
8159
|
this.resetRecording();
|
|
8122
8160
|
}, this);
|
|
8123
8161
|
|
|
@@ -8162,6 +8200,689 @@
|
|
|
8162
8200
|
|
|
8163
8201
|
win['__mp_recorder'] = MixpanelRecorder;
|
|
8164
8202
|
|
|
8203
|
+
// stateless utils
|
|
8204
|
+
|
|
8205
|
+
var EV_CHANGE = 'change';
|
|
8206
|
+
var EV_CLICK = 'click';
|
|
8207
|
+
var EV_HASHCHANGE = 'hashchange';
|
|
8208
|
+
var EV_MP_LOCATION_CHANGE = 'mp_locationchange';
|
|
8209
|
+
var EV_POPSTATE = 'popstate';
|
|
8210
|
+
// TODO scrollend isn't available in Safari: document or polyfill?
|
|
8211
|
+
var EV_SCROLLEND = 'scrollend';
|
|
8212
|
+
var EV_SUBMIT = 'submit';
|
|
8213
|
+
|
|
8214
|
+
var CLICK_EVENT_PROPS = [
|
|
8215
|
+
'clientX', 'clientY',
|
|
8216
|
+
'offsetX', 'offsetY',
|
|
8217
|
+
'pageX', 'pageY',
|
|
8218
|
+
'screenX', 'screenY',
|
|
8219
|
+
'x', 'y'
|
|
8220
|
+
];
|
|
8221
|
+
var OPT_IN_CLASSES = ['mp-include'];
|
|
8222
|
+
var OPT_OUT_CLASSES = ['mp-no-track'];
|
|
8223
|
+
var SENSITIVE_DATA_CLASSES = OPT_OUT_CLASSES.concat(['mp-sensitive']);
|
|
8224
|
+
var TRACKED_ATTRS = [
|
|
8225
|
+
'aria-label', 'aria-labelledby', 'aria-describedby',
|
|
8226
|
+
'href', 'name', 'role', 'title', 'type'
|
|
8227
|
+
];
|
|
8228
|
+
|
|
8229
|
+
var logger = console_with_prefix('autocapture');
|
|
8230
|
+
|
|
8231
|
+
|
|
8232
|
+
function getClasses(el) {
|
|
8233
|
+
var classes = {};
|
|
8234
|
+
var classList = getClassName(el).split(' ');
|
|
8235
|
+
for (var i = 0; i < classList.length; i++) {
|
|
8236
|
+
var cls = classList[i];
|
|
8237
|
+
if (cls) {
|
|
8238
|
+
classes[cls] = true;
|
|
8239
|
+
}
|
|
8240
|
+
}
|
|
8241
|
+
return classes;
|
|
8242
|
+
}
|
|
8243
|
+
|
|
8244
|
+
/*
|
|
8245
|
+
* Get the className of an element, accounting for edge cases where element.className is an object
|
|
8246
|
+
* @param {Element} el - element to get the className of
|
|
8247
|
+
* @returns {string} the element's class
|
|
8248
|
+
*/
|
|
8249
|
+
function getClassName(el) {
|
|
8250
|
+
switch(typeof el.className) {
|
|
8251
|
+
case 'string':
|
|
8252
|
+
return el.className;
|
|
8253
|
+
case 'object': // handle cases where className might be SVGAnimatedString or some other type
|
|
8254
|
+
return el.className.baseVal || el.getAttribute('class') || '';
|
|
8255
|
+
default: // future proof
|
|
8256
|
+
return '';
|
|
8257
|
+
}
|
|
8258
|
+
}
|
|
8259
|
+
|
|
8260
|
+
function getPreviousElementSibling(el) {
|
|
8261
|
+
if (el.previousElementSibling) {
|
|
8262
|
+
return el.previousElementSibling;
|
|
8263
|
+
} else {
|
|
8264
|
+
do {
|
|
8265
|
+
el = el.previousSibling;
|
|
8266
|
+
} while (el && !isElementNode(el));
|
|
8267
|
+
return el;
|
|
8268
|
+
}
|
|
8269
|
+
}
|
|
8270
|
+
|
|
8271
|
+
function getPropertiesFromElement(el) {
|
|
8272
|
+
var props = {
|
|
8273
|
+
'$classes': getClassName(el).split(' '),
|
|
8274
|
+
'$tag_name': el.tagName.toLowerCase()
|
|
8275
|
+
};
|
|
8276
|
+
var elId = el.id;
|
|
8277
|
+
if (elId) {
|
|
8278
|
+
props['$id'] = elId;
|
|
8279
|
+
}
|
|
8280
|
+
|
|
8281
|
+
if (shouldTrackElement(el)) {
|
|
8282
|
+
_.each(TRACKED_ATTRS, function(attr) {
|
|
8283
|
+
if (el.hasAttribute(attr)) {
|
|
8284
|
+
var attrVal = el.getAttribute(attr);
|
|
8285
|
+
if (shouldTrackValue(attrVal)) {
|
|
8286
|
+
props['$attr-' + attr] = attrVal;
|
|
8287
|
+
}
|
|
8288
|
+
}
|
|
8289
|
+
});
|
|
8290
|
+
}
|
|
8291
|
+
|
|
8292
|
+
var nthChild = 1;
|
|
8293
|
+
var nthOfType = 1;
|
|
8294
|
+
var currentElem = el;
|
|
8295
|
+
while (currentElem = getPreviousElementSibling(currentElem)) { // eslint-disable-line no-cond-assign
|
|
8296
|
+
nthChild++;
|
|
8297
|
+
if (currentElem.tagName === el.tagName) {
|
|
8298
|
+
nthOfType++;
|
|
8299
|
+
}
|
|
8300
|
+
}
|
|
8301
|
+
props['$nth_child'] = nthChild;
|
|
8302
|
+
props['$nth_of_type'] = nthOfType;
|
|
8303
|
+
|
|
8304
|
+
return props;
|
|
8305
|
+
}
|
|
8306
|
+
|
|
8307
|
+
function getPropsForDOMEvent(ev, blockSelectors, captureTextContent) {
|
|
8308
|
+
blockSelectors = blockSelectors || [];
|
|
8309
|
+
var props = null;
|
|
8310
|
+
|
|
8311
|
+
var target = typeof ev.target === 'undefined' ? ev.srcElement : ev.target;
|
|
8312
|
+
if (isTextNode(target)) { // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
|
|
8313
|
+
target = target.parentNode;
|
|
8314
|
+
}
|
|
8315
|
+
|
|
8316
|
+
if (shouldTrackDomEvent(target, ev)) {
|
|
8317
|
+
var targetElementList = [target];
|
|
8318
|
+
var curEl = target;
|
|
8319
|
+
while (curEl.parentNode && !isTag(curEl, 'body')) {
|
|
8320
|
+
targetElementList.push(curEl.parentNode);
|
|
8321
|
+
curEl = curEl.parentNode;
|
|
8322
|
+
}
|
|
8323
|
+
|
|
8324
|
+
var elementsJson = [];
|
|
8325
|
+
var href, explicitNoTrack = false;
|
|
8326
|
+
_.each(targetElementList, function(el) {
|
|
8327
|
+
var shouldTrackEl = shouldTrackElement(el);
|
|
8328
|
+
|
|
8329
|
+
// if the element or a parent element is an anchor tag
|
|
8330
|
+
// include the href as a property
|
|
8331
|
+
if (el.tagName.toLowerCase() === 'a') {
|
|
8332
|
+
href = el.getAttribute('href');
|
|
8333
|
+
href = shouldTrackEl && shouldTrackValue(href) && href;
|
|
8334
|
+
}
|
|
8335
|
+
|
|
8336
|
+
// allow users to programmatically prevent tracking of elements by adding classes such as 'mp-no-track'
|
|
8337
|
+
var classes = getClasses(el);
|
|
8338
|
+
_.each(OPT_OUT_CLASSES, function(cls) {
|
|
8339
|
+
if (classes[cls]) {
|
|
8340
|
+
explicitNoTrack = true;
|
|
8341
|
+
}
|
|
8342
|
+
});
|
|
8343
|
+
|
|
8344
|
+
if (!explicitNoTrack) {
|
|
8345
|
+
// programmatically prevent tracking of elements that match CSS selectors
|
|
8346
|
+
_.each(blockSelectors, function(sel) {
|
|
8347
|
+
try {
|
|
8348
|
+
if (el['matches'](sel)) {
|
|
8349
|
+
explicitNoTrack = true;
|
|
8350
|
+
}
|
|
8351
|
+
} catch (err) {
|
|
8352
|
+
logger.critical('Error while checking selector: ' + sel, err);
|
|
8353
|
+
}
|
|
8354
|
+
});
|
|
8355
|
+
}
|
|
8356
|
+
|
|
8357
|
+
elementsJson.push(getPropertiesFromElement(el));
|
|
8358
|
+
}, this);
|
|
8359
|
+
|
|
8360
|
+
if (!explicitNoTrack) {
|
|
8361
|
+
var docElement = document$1['documentElement'];
|
|
8362
|
+
props = {
|
|
8363
|
+
'$event_type': ev.type,
|
|
8364
|
+
'$host': win.location.host,
|
|
8365
|
+
'$pathname': win.location.pathname,
|
|
8366
|
+
'$elements': elementsJson,
|
|
8367
|
+
'$el_attr__href': href,
|
|
8368
|
+
'$viewportHeight': Math.max(docElement['clientHeight'], win['innerHeight'] || 0),
|
|
8369
|
+
'$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0)
|
|
8370
|
+
};
|
|
8371
|
+
|
|
8372
|
+
if (captureTextContent) {
|
|
8373
|
+
elementText = getSafeText(target);
|
|
8374
|
+
if (elementText && elementText.length) {
|
|
8375
|
+
props['$el_text'] = elementText;
|
|
8376
|
+
}
|
|
8377
|
+
}
|
|
8378
|
+
|
|
8379
|
+
if (ev.type === EV_CLICK) {
|
|
8380
|
+
_.each(CLICK_EVENT_PROPS, function(prop) {
|
|
8381
|
+
if (prop in ev) {
|
|
8382
|
+
props['$' + prop] = ev[prop];
|
|
8383
|
+
}
|
|
8384
|
+
});
|
|
8385
|
+
target = guessRealClickTarget(ev);
|
|
8386
|
+
}
|
|
8387
|
+
// prioritize text content from "real" click target if different from original target
|
|
8388
|
+
if (captureTextContent) {
|
|
8389
|
+
var elementText = getSafeText(target);
|
|
8390
|
+
if (elementText && elementText.length) {
|
|
8391
|
+
props['$el_text'] = elementText;
|
|
8392
|
+
}
|
|
8393
|
+
}
|
|
8394
|
+
|
|
8395
|
+
if (target) {
|
|
8396
|
+
var targetProps = getPropertiesFromElement(target);
|
|
8397
|
+
props['$target'] = targetProps;
|
|
8398
|
+
// pull up more props onto main event props
|
|
8399
|
+
props['$el_classes'] = targetProps['$classes'];
|
|
8400
|
+
_.extend(props, _.strip_empty_properties({
|
|
8401
|
+
'$el_id': targetProps['$id'],
|
|
8402
|
+
'$el_tag_name': targetProps['$tag_name']
|
|
8403
|
+
}));
|
|
8404
|
+
}
|
|
8405
|
+
}
|
|
8406
|
+
}
|
|
8407
|
+
|
|
8408
|
+
return props;
|
|
8409
|
+
}
|
|
8410
|
+
|
|
8411
|
+
|
|
8412
|
+
/*
|
|
8413
|
+
* Get the direct text content of an element, protecting against sensitive data collection.
|
|
8414
|
+
* Concats textContent of each of the element's text node children; this avoids potential
|
|
8415
|
+
* collection of sensitive data that could happen if we used element.textContent and the
|
|
8416
|
+
* element had sensitive child elements, since element.textContent includes child content.
|
|
8417
|
+
* Scrubs values that look like they could be sensitive (i.e. cc or ssn number).
|
|
8418
|
+
* @param {Element} el - element to get the text of
|
|
8419
|
+
* @returns {string} the element's direct text content
|
|
8420
|
+
*/
|
|
8421
|
+
function getSafeText(el) {
|
|
8422
|
+
var elText = '';
|
|
8423
|
+
|
|
8424
|
+
if (shouldTrackElement(el) && el.childNodes && el.childNodes.length) {
|
|
8425
|
+
_.each(el.childNodes, function(child) {
|
|
8426
|
+
if (isTextNode(child) && child.textContent) {
|
|
8427
|
+
elText += _.trim(child.textContent)
|
|
8428
|
+
// scrub potentially sensitive values
|
|
8429
|
+
.split(/(\s+)/).filter(shouldTrackValue).join('')
|
|
8430
|
+
// normalize whitespace
|
|
8431
|
+
.replace(/[\r\n]/g, ' ').replace(/[ ]+/g, ' ')
|
|
8432
|
+
// truncate
|
|
8433
|
+
.substring(0, 255);
|
|
8434
|
+
}
|
|
8435
|
+
});
|
|
8436
|
+
}
|
|
8437
|
+
|
|
8438
|
+
return _.trim(elText);
|
|
8439
|
+
}
|
|
8440
|
+
|
|
8441
|
+
function guessRealClickTarget(ev) {
|
|
8442
|
+
var target = ev.target;
|
|
8443
|
+
var composedPath = ev['composedPath']();
|
|
8444
|
+
for (var i = 0; i < composedPath.length; i++) {
|
|
8445
|
+
var node = composedPath[i];
|
|
8446
|
+
if (
|
|
8447
|
+
isTag(node, 'a') ||
|
|
8448
|
+
isTag(node, 'button') ||
|
|
8449
|
+
isTag(node, 'input') ||
|
|
8450
|
+
isTag(node, 'select') ||
|
|
8451
|
+
(node.getAttribute && node.getAttribute('role') === 'button')
|
|
8452
|
+
) {
|
|
8453
|
+
target = node;
|
|
8454
|
+
break;
|
|
8455
|
+
}
|
|
8456
|
+
if (node === target) {
|
|
8457
|
+
break;
|
|
8458
|
+
}
|
|
8459
|
+
}
|
|
8460
|
+
return target;
|
|
8461
|
+
}
|
|
8462
|
+
|
|
8463
|
+
/*
|
|
8464
|
+
* Check whether a DOM node has nodeType Node.ELEMENT_NODE
|
|
8465
|
+
* @param {Node} node - node to check
|
|
8466
|
+
* @returns {boolean} whether node is of the correct nodeType
|
|
8467
|
+
*/
|
|
8468
|
+
function isElementNode(node) {
|
|
8469
|
+
return node && node.nodeType === 1; // Node.ELEMENT_NODE - use integer constant for browser portability
|
|
8470
|
+
}
|
|
8471
|
+
|
|
8472
|
+
/*
|
|
8473
|
+
* Check whether an element is of a given tag type.
|
|
8474
|
+
* Due to potential reference discrepancies (such as the webcomponents.js polyfill),
|
|
8475
|
+
* we want to match tagNames instead of specific references because something like
|
|
8476
|
+
* element === document.body won't always work because element might not be a native
|
|
8477
|
+
* element.
|
|
8478
|
+
* @param {Element} el - element to check
|
|
8479
|
+
* @param {string} tag - tag name (e.g., "div")
|
|
8480
|
+
* @returns {boolean} whether el is of the given tag type
|
|
8481
|
+
*/
|
|
8482
|
+
function isTag(el, tag) {
|
|
8483
|
+
return el && el.tagName && el.tagName.toLowerCase() === tag.toLowerCase();
|
|
8484
|
+
}
|
|
8485
|
+
|
|
8486
|
+
/*
|
|
8487
|
+
* Check whether a DOM node is a TEXT_NODE
|
|
8488
|
+
* @param {Node} node - node to check
|
|
8489
|
+
* @returns {boolean} whether node is of type Node.TEXT_NODE
|
|
8490
|
+
*/
|
|
8491
|
+
function isTextNode(node) {
|
|
8492
|
+
return node && node.nodeType === 3; // Node.TEXT_NODE - use integer constant for browser portability
|
|
8493
|
+
}
|
|
8494
|
+
|
|
8495
|
+
function minDOMApisSupported() {
|
|
8496
|
+
try {
|
|
8497
|
+
var testEl = document$1.createElement('div');
|
|
8498
|
+
return !!testEl['matches'];
|
|
8499
|
+
} catch (err) {
|
|
8500
|
+
return false;
|
|
8501
|
+
}
|
|
8502
|
+
}
|
|
8503
|
+
|
|
8504
|
+
/*
|
|
8505
|
+
* Check whether a DOM event should be "tracked" or if it may contain sensitive data
|
|
8506
|
+
* using a variety of heuristics.
|
|
8507
|
+
* @param {Element} el - element to check
|
|
8508
|
+
* @param {Event} ev - event to check
|
|
8509
|
+
* @returns {boolean} whether the event should be tracked
|
|
8510
|
+
*/
|
|
8511
|
+
function shouldTrackDomEvent(el, ev) {
|
|
8512
|
+
if (!el || isTag(el, 'html') || !isElementNode(el)) {
|
|
8513
|
+
return false;
|
|
8514
|
+
}
|
|
8515
|
+
var tag = el.tagName.toLowerCase();
|
|
8516
|
+
switch (tag) {
|
|
8517
|
+
case 'form':
|
|
8518
|
+
return ev.type === EV_SUBMIT;
|
|
8519
|
+
case 'input':
|
|
8520
|
+
if (['button', 'submit'].indexOf(el.getAttribute('type')) === -1) {
|
|
8521
|
+
return ev.type === EV_CHANGE;
|
|
8522
|
+
} else {
|
|
8523
|
+
return ev.type === EV_CLICK;
|
|
8524
|
+
}
|
|
8525
|
+
case 'select':
|
|
8526
|
+
case 'textarea':
|
|
8527
|
+
return ev.type === EV_CHANGE;
|
|
8528
|
+
default:
|
|
8529
|
+
return ev.type === EV_CLICK;
|
|
8530
|
+
}
|
|
8531
|
+
}
|
|
8532
|
+
|
|
8533
|
+
/*
|
|
8534
|
+
* Check whether a DOM element should be "tracked" or if it may contain sensitive data
|
|
8535
|
+
* using a variety of heuristics.
|
|
8536
|
+
* @param {Element} el - element to check
|
|
8537
|
+
* @returns {boolean} whether the element should be tracked
|
|
8538
|
+
*/
|
|
8539
|
+
function shouldTrackElement(el) {
|
|
8540
|
+
var i;
|
|
8541
|
+
|
|
8542
|
+
for (var curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode) {
|
|
8543
|
+
var classes = getClasses(curEl);
|
|
8544
|
+
for (i = 0; i < SENSITIVE_DATA_CLASSES.length; i++) {
|
|
8545
|
+
if (classes[SENSITIVE_DATA_CLASSES[i]]) {
|
|
8546
|
+
return false;
|
|
8547
|
+
}
|
|
8548
|
+
}
|
|
8549
|
+
}
|
|
8550
|
+
|
|
8551
|
+
var elClasses = getClasses(el);
|
|
8552
|
+
for (i = 0; i < OPT_IN_CLASSES.length; i++) {
|
|
8553
|
+
if (elClasses[OPT_IN_CLASSES[i]]) {
|
|
8554
|
+
return true;
|
|
8555
|
+
}
|
|
8556
|
+
}
|
|
8557
|
+
|
|
8558
|
+
// don't send data from inputs or similar elements since there will always be
|
|
8559
|
+
// a risk of clientside javascript placing sensitive data in attributes
|
|
8560
|
+
if (
|
|
8561
|
+
isTag(el, 'input') ||
|
|
8562
|
+
isTag(el, 'select') ||
|
|
8563
|
+
isTag(el, 'textarea') ||
|
|
8564
|
+
el.getAttribute('contenteditable') === 'true'
|
|
8565
|
+
) {
|
|
8566
|
+
return false;
|
|
8567
|
+
}
|
|
8568
|
+
|
|
8569
|
+
// don't include hidden or password fields
|
|
8570
|
+
var type = el.type || '';
|
|
8571
|
+
if (typeof type === 'string') { // it's possible for el.type to be a DOM element if el is a form with a child input[name="type"]
|
|
8572
|
+
switch(type.toLowerCase()) {
|
|
8573
|
+
case 'hidden':
|
|
8574
|
+
return false;
|
|
8575
|
+
case 'password':
|
|
8576
|
+
return false;
|
|
8577
|
+
}
|
|
8578
|
+
}
|
|
8579
|
+
|
|
8580
|
+
// filter out data from fields that look like sensitive fields
|
|
8581
|
+
var name = el.name || el.id || '';
|
|
8582
|
+
if (typeof name === 'string') { // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name="name"]
|
|
8583
|
+
var sensitiveNameRegex = /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i;
|
|
8584
|
+
if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {
|
|
8585
|
+
return false;
|
|
8586
|
+
}
|
|
8587
|
+
}
|
|
8588
|
+
|
|
8589
|
+
return true;
|
|
8590
|
+
}
|
|
8591
|
+
|
|
8592
|
+
|
|
8593
|
+
/*
|
|
8594
|
+
* Check whether a string value should be "tracked" or if it may contain sensitive data
|
|
8595
|
+
* using a variety of heuristics.
|
|
8596
|
+
* @param {string} value - string value to check
|
|
8597
|
+
* @returns {boolean} whether the element should be tracked
|
|
8598
|
+
*/
|
|
8599
|
+
function shouldTrackValue(value) {
|
|
8600
|
+
if (value === null || _.isUndefined(value)) {
|
|
8601
|
+
return false;
|
|
8602
|
+
}
|
|
8603
|
+
|
|
8604
|
+
if (typeof value === 'string') {
|
|
8605
|
+
value = _.trim(value);
|
|
8606
|
+
|
|
8607
|
+
// check to see if input value looks like a credit card number
|
|
8608
|
+
// see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html
|
|
8609
|
+
var ccRegex = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/;
|
|
8610
|
+
if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {
|
|
8611
|
+
return false;
|
|
8612
|
+
}
|
|
8613
|
+
|
|
8614
|
+
// check to see if input value looks like a social security number
|
|
8615
|
+
var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/;
|
|
8616
|
+
if (ssnRegex.test(value)) {
|
|
8617
|
+
return false;
|
|
8618
|
+
}
|
|
8619
|
+
}
|
|
8620
|
+
|
|
8621
|
+
return true;
|
|
8622
|
+
}
|
|
8623
|
+
|
|
8624
|
+
var AUTOCAPTURE_CONFIG_KEY = 'autocapture';
|
|
8625
|
+
var LEGACY_PAGEVIEW_CONFIG_KEY = 'track_pageview';
|
|
8626
|
+
|
|
8627
|
+
var PAGEVIEW_OPTION_FULL_URL = 'full-url';
|
|
8628
|
+
var PAGEVIEW_OPTION_URL_WITH_PATH_AND_QUERY_STRING = 'url-with-path-and-query-string';
|
|
8629
|
+
var PAGEVIEW_OPTION_URL_WITH_PATH = 'url-with-path';
|
|
8630
|
+
|
|
8631
|
+
var CONFIG_BLOCK_SELECTORS = 'block_selectors';
|
|
8632
|
+
var CONFIG_BLOCK_URL_REGEXES = 'block_url_regexes';
|
|
8633
|
+
var CONFIG_CAPTURE_TEXT_CONTENT = 'capture_text_content';
|
|
8634
|
+
var CONFIG_TRACK_CLICK = 'click';
|
|
8635
|
+
var CONFIG_TRACK_INPUT = 'input';
|
|
8636
|
+
var CONFIG_TRACK_PAGEVIEW = 'pageview';
|
|
8637
|
+
var CONFIG_TRACK_SCROLL = 'scroll';
|
|
8638
|
+
var CONFIG_TRACK_SUBMIT = 'submit';
|
|
8639
|
+
|
|
8640
|
+
var CONFIG_DEFAULTS = {};
|
|
8641
|
+
CONFIG_DEFAULTS[CONFIG_CAPTURE_TEXT_CONTENT] = false;
|
|
8642
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_CLICK] = true;
|
|
8643
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_INPUT] = true;
|
|
8644
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_PAGEVIEW] = PAGEVIEW_OPTION_FULL_URL;
|
|
8645
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_SCROLL] = true;
|
|
8646
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_SUBMIT] = true;
|
|
8647
|
+
|
|
8648
|
+
var DEFAULT_PROPS = {
|
|
8649
|
+
'$mp_autocapture': true
|
|
8650
|
+
};
|
|
8651
|
+
|
|
8652
|
+
var MP_EV_CLICK = '$mp_click';
|
|
8653
|
+
var MP_EV_INPUT = '$mp_input_change';
|
|
8654
|
+
var MP_EV_SCROLL = '$mp_scroll';
|
|
8655
|
+
var MP_EV_SUBMIT = '$mp_submit';
|
|
8656
|
+
|
|
8657
|
+
/**
|
|
8658
|
+
* Autocapture: manages automatic event tracking
|
|
8659
|
+
* @constructor
|
|
8660
|
+
*/
|
|
8661
|
+
var Autocapture = function(mp) {
|
|
8662
|
+
this.mp = mp;
|
|
8663
|
+
};
|
|
8664
|
+
|
|
8665
|
+
Autocapture.prototype.init = function() {
|
|
8666
|
+
if (!minDOMApisSupported()) {
|
|
8667
|
+
logger.critical('Autocapture unavailable: missing required DOM APIs');
|
|
8668
|
+
return;
|
|
8669
|
+
}
|
|
8670
|
+
|
|
8671
|
+
this.initPageviewTracking();
|
|
8672
|
+
this.initClickTracking();
|
|
8673
|
+
this.initInputTracking();
|
|
8674
|
+
this.initScrollTracking();
|
|
8675
|
+
this.initSubmitTracking();
|
|
8676
|
+
};
|
|
8677
|
+
|
|
8678
|
+
Autocapture.prototype.getFullConfig = function() {
|
|
8679
|
+
var autocaptureConfig = this.mp.get_config(AUTOCAPTURE_CONFIG_KEY);
|
|
8680
|
+
if (!autocaptureConfig) {
|
|
8681
|
+
// Autocapture is completely off
|
|
8682
|
+
return {};
|
|
8683
|
+
} else if (_.isObject(autocaptureConfig)) {
|
|
8684
|
+
return _.extend({}, CONFIG_DEFAULTS, autocaptureConfig);
|
|
8685
|
+
} else {
|
|
8686
|
+
// Autocapture config is non-object truthy value, return default
|
|
8687
|
+
return CONFIG_DEFAULTS;
|
|
8688
|
+
}
|
|
8689
|
+
};
|
|
8690
|
+
|
|
8691
|
+
Autocapture.prototype.getConfig = function(key) {
|
|
8692
|
+
return this.getFullConfig()[key];
|
|
8693
|
+
};
|
|
8694
|
+
|
|
8695
|
+
Autocapture.prototype.currentUrlBlocked = function() {
|
|
8696
|
+
var blockUrlRegexes = this.getConfig(CONFIG_BLOCK_URL_REGEXES) || [];
|
|
8697
|
+
if (!blockUrlRegexes || !blockUrlRegexes.length) {
|
|
8698
|
+
return false;
|
|
8699
|
+
}
|
|
8700
|
+
|
|
8701
|
+
var currentUrl = _.info.currentUrl();
|
|
8702
|
+
for (var i = 0; i < blockUrlRegexes.length; i++) {
|
|
8703
|
+
try {
|
|
8704
|
+
if (currentUrl.match(blockUrlRegexes[i])) {
|
|
8705
|
+
return true;
|
|
8706
|
+
}
|
|
8707
|
+
} catch (err) {
|
|
8708
|
+
logger.critical('Error while checking block URL regex: ' + blockUrlRegexes[i], err);
|
|
8709
|
+
return true;
|
|
8710
|
+
}
|
|
8711
|
+
}
|
|
8712
|
+
return false;
|
|
8713
|
+
};
|
|
8714
|
+
|
|
8715
|
+
Autocapture.prototype.pageviewTrackingConfig = function() {
|
|
8716
|
+
// supports both autocapture config and old track_pageview config
|
|
8717
|
+
if (this.mp.get_config(AUTOCAPTURE_CONFIG_KEY)) {
|
|
8718
|
+
return this.getConfig(CONFIG_TRACK_PAGEVIEW);
|
|
8719
|
+
} else {
|
|
8720
|
+
return this.mp.get_config(LEGACY_PAGEVIEW_CONFIG_KEY);
|
|
8721
|
+
}
|
|
8722
|
+
};
|
|
8723
|
+
|
|
8724
|
+
// helper for event handlers
|
|
8725
|
+
Autocapture.prototype.trackDomEvent = function(ev, mpEventName) {
|
|
8726
|
+
if (this.currentUrlBlocked()) {
|
|
8727
|
+
return;
|
|
8728
|
+
}
|
|
8729
|
+
|
|
8730
|
+
var props = getPropsForDOMEvent(
|
|
8731
|
+
ev,
|
|
8732
|
+
this.getConfig(CONFIG_BLOCK_SELECTORS),
|
|
8733
|
+
this.getConfig(CONFIG_CAPTURE_TEXT_CONTENT)
|
|
8734
|
+
);
|
|
8735
|
+
if (props) {
|
|
8736
|
+
_.extend(props, DEFAULT_PROPS);
|
|
8737
|
+
this.mp.track(mpEventName, props);
|
|
8738
|
+
}
|
|
8739
|
+
};
|
|
8740
|
+
|
|
8741
|
+
Autocapture.prototype.initClickTracking = function() {
|
|
8742
|
+
win.removeEventListener(EV_CLICK, this.listenerClick);
|
|
8743
|
+
|
|
8744
|
+
if (!this.getConfig(CONFIG_TRACK_CLICK)) {
|
|
8745
|
+
return;
|
|
8746
|
+
}
|
|
8747
|
+
logger.log('Initializing click tracking');
|
|
8748
|
+
|
|
8749
|
+
this.listenerClick = win.addEventListener(EV_CLICK, function(ev) {
|
|
8750
|
+
if (!this.getConfig(CONFIG_TRACK_CLICK)) {
|
|
8751
|
+
return;
|
|
8752
|
+
}
|
|
8753
|
+
this.trackDomEvent(ev, MP_EV_CLICK);
|
|
8754
|
+
}.bind(this));
|
|
8755
|
+
};
|
|
8756
|
+
|
|
8757
|
+
Autocapture.prototype.initInputTracking = function() {
|
|
8758
|
+
win.removeEventListener(EV_CHANGE, this.listenerChange);
|
|
8759
|
+
|
|
8760
|
+
if (!this.getConfig(CONFIG_TRACK_INPUT)) {
|
|
8761
|
+
return;
|
|
8762
|
+
}
|
|
8763
|
+
logger.log('Initializing input tracking');
|
|
8764
|
+
|
|
8765
|
+
this.listenerChange = win.addEventListener(EV_CHANGE, function(ev) {
|
|
8766
|
+
if (!this.getConfig(CONFIG_TRACK_INPUT)) {
|
|
8767
|
+
return;
|
|
8768
|
+
}
|
|
8769
|
+
this.trackDomEvent(ev, MP_EV_INPUT);
|
|
8770
|
+
}.bind(this));
|
|
8771
|
+
};
|
|
8772
|
+
|
|
8773
|
+
Autocapture.prototype.initPageviewTracking = function() {
|
|
8774
|
+
win.removeEventListener(EV_POPSTATE, this.listenerPopstate);
|
|
8775
|
+
win.removeEventListener(EV_HASHCHANGE, this.listenerHashchange);
|
|
8776
|
+
win.removeEventListener(EV_MP_LOCATION_CHANGE, this.listenerLocationchange);
|
|
8777
|
+
|
|
8778
|
+
if (!this.pageviewTrackingConfig()) {
|
|
8779
|
+
return;
|
|
8780
|
+
}
|
|
8781
|
+
logger.log('Initializing pageview tracking');
|
|
8782
|
+
|
|
8783
|
+
var previousTrackedUrl = '';
|
|
8784
|
+
var tracked = false;
|
|
8785
|
+
if (!this.currentUrlBlocked()) {
|
|
8786
|
+
tracked = this.mp.track_pageview(DEFAULT_PROPS);
|
|
8787
|
+
}
|
|
8788
|
+
if (tracked) {
|
|
8789
|
+
previousTrackedUrl = _.info.currentUrl();
|
|
8790
|
+
}
|
|
8791
|
+
|
|
8792
|
+
this.listenerPopstate = win.addEventListener(EV_POPSTATE, function() {
|
|
8793
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8794
|
+
});
|
|
8795
|
+
this.listenerHashchange = win.addEventListener(EV_HASHCHANGE, function() {
|
|
8796
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8797
|
+
});
|
|
8798
|
+
var nativePushState = win.history.pushState;
|
|
8799
|
+
if (typeof nativePushState === 'function') {
|
|
8800
|
+
win.history.pushState = function(state, unused, url) {
|
|
8801
|
+
nativePushState.call(win.history, state, unused, url);
|
|
8802
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8803
|
+
};
|
|
8804
|
+
}
|
|
8805
|
+
var nativeReplaceState = win.history.replaceState;
|
|
8806
|
+
if (typeof nativeReplaceState === 'function') {
|
|
8807
|
+
win.history.replaceState = function(state, unused, url) {
|
|
8808
|
+
nativeReplaceState.call(win.history, state, unused, url);
|
|
8809
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8810
|
+
};
|
|
8811
|
+
}
|
|
8812
|
+
this.listenerLocationchange = win.addEventListener(EV_MP_LOCATION_CHANGE, safewrap(function() {
|
|
8813
|
+
if (this.currentUrlBlocked()) {
|
|
8814
|
+
return;
|
|
8815
|
+
}
|
|
8816
|
+
|
|
8817
|
+
var currentUrl = _.info.currentUrl();
|
|
8818
|
+
var shouldTrack = false;
|
|
8819
|
+
var trackPageviewOption = this.pageviewTrackingConfig();
|
|
8820
|
+
if (trackPageviewOption === PAGEVIEW_OPTION_FULL_URL) {
|
|
8821
|
+
shouldTrack = currentUrl !== previousTrackedUrl;
|
|
8822
|
+
} else if (trackPageviewOption === PAGEVIEW_OPTION_URL_WITH_PATH_AND_QUERY_STRING) {
|
|
8823
|
+
shouldTrack = currentUrl.split('#')[0] !== previousTrackedUrl.split('#')[0];
|
|
8824
|
+
} else if (trackPageviewOption === PAGEVIEW_OPTION_URL_WITH_PATH) {
|
|
8825
|
+
shouldTrack = currentUrl.split('#')[0].split('?')[0] !== previousTrackedUrl.split('#')[0].split('?')[0];
|
|
8826
|
+
}
|
|
8827
|
+
|
|
8828
|
+
if (shouldTrack) {
|
|
8829
|
+
var tracked = this.mp.track_pageview(DEFAULT_PROPS);
|
|
8830
|
+
if (tracked) {
|
|
8831
|
+
previousTrackedUrl = currentUrl;
|
|
8832
|
+
}
|
|
8833
|
+
}
|
|
8834
|
+
}.bind(this)));
|
|
8835
|
+
};
|
|
8836
|
+
|
|
8837
|
+
Autocapture.prototype.initScrollTracking = function() {
|
|
8838
|
+
win.removeEventListener(EV_SCROLLEND, this.listenerScroll);
|
|
8839
|
+
|
|
8840
|
+
if (!this.getConfig(CONFIG_TRACK_SCROLL)) {
|
|
8841
|
+
return;
|
|
8842
|
+
}
|
|
8843
|
+
logger.log('Initializing scroll tracking');
|
|
8844
|
+
|
|
8845
|
+
this.listenerScroll = win.addEventListener(EV_SCROLLEND, safewrap(function() {
|
|
8846
|
+
if (!this.getConfig(CONFIG_TRACK_SCROLL)) {
|
|
8847
|
+
return;
|
|
8848
|
+
}
|
|
8849
|
+
if (this.currentUrlBlocked()) {
|
|
8850
|
+
return;
|
|
8851
|
+
}
|
|
8852
|
+
|
|
8853
|
+
var scrollTop = win.scrollY;
|
|
8854
|
+
var props = _.extend({'$scroll_top': scrollTop}, DEFAULT_PROPS);
|
|
8855
|
+
try {
|
|
8856
|
+
var scrollHeight = document$1.body.scrollHeight;
|
|
8857
|
+
var scrollPercentage = Math.round((scrollTop / (scrollHeight - win.innerHeight)) * 100);
|
|
8858
|
+
props['$scroll_height'] = scrollHeight;
|
|
8859
|
+
props['$scroll_percentage'] = scrollPercentage;
|
|
8860
|
+
} catch (err) {
|
|
8861
|
+
logger.critical('Error while calculating scroll percentage', err);
|
|
8862
|
+
}
|
|
8863
|
+
this.mp.track(MP_EV_SCROLL, props);
|
|
8864
|
+
}.bind(this)));
|
|
8865
|
+
};
|
|
8866
|
+
|
|
8867
|
+
Autocapture.prototype.initSubmitTracking = function() {
|
|
8868
|
+
win.removeEventListener(EV_SUBMIT, this.listenerSubmit);
|
|
8869
|
+
|
|
8870
|
+
if (!this.getConfig(CONFIG_TRACK_SUBMIT)) {
|
|
8871
|
+
return;
|
|
8872
|
+
}
|
|
8873
|
+
logger.log('Initializing submit tracking');
|
|
8874
|
+
|
|
8875
|
+
this.listenerSubmit = win.addEventListener(EV_SUBMIT, function(ev) {
|
|
8876
|
+
if (!this.getConfig(CONFIG_TRACK_SUBMIT)) {
|
|
8877
|
+
return;
|
|
8878
|
+
}
|
|
8879
|
+
this.trackDomEvent(ev, MP_EV_SUBMIT);
|
|
8880
|
+
}.bind(this));
|
|
8881
|
+
};
|
|
8882
|
+
|
|
8883
|
+
// TODO integrate error_reporter from mixpanel instance
|
|
8884
|
+
safewrapClass(Autocapture);
|
|
8885
|
+
|
|
8165
8886
|
/* eslint camelcase: "off" */
|
|
8166
8887
|
|
|
8167
8888
|
/**
|
|
@@ -9581,6 +10302,7 @@
|
|
|
9581
10302
|
'api_transport': 'XHR',
|
|
9582
10303
|
'api_payload_format': PAYLOAD_TYPE_BASE64,
|
|
9583
10304
|
'app_host': 'https://mixpanel.com',
|
|
10305
|
+
'autocapture': false,
|
|
9584
10306
|
'cdn': 'https://cdn.mxpnl.com',
|
|
9585
10307
|
'cross_site_cookie': false,
|
|
9586
10308
|
'cross_subdomain_cookie': true,
|
|
@@ -9623,6 +10345,7 @@
|
|
|
9623
10345
|
'hooks': {},
|
|
9624
10346
|
'record_block_class': new RegExp('^(mp-block|fs-exclude|amp-block|rr-block|ph-no-capture)$'),
|
|
9625
10347
|
'record_block_selector': 'img, video',
|
|
10348
|
+
'record_canvas': false,
|
|
9626
10349
|
'record_collect_fonts': false,
|
|
9627
10350
|
'record_idle_timeout_ms': 30 * 60 * 1000, // 30 minutes
|
|
9628
10351
|
'record_mask_text_class': new RegExp('^(mp-mask|fs-mask|amp-mask|rr-mask|ph-mask)$'),
|
|
@@ -9839,10 +10562,8 @@
|
|
|
9839
10562
|
}, '');
|
|
9840
10563
|
}
|
|
9841
10564
|
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
this._init_url_change_tracking(track_pageview_option);
|
|
9845
|
-
}
|
|
10565
|
+
this.autocapture = new Autocapture(this);
|
|
10566
|
+
this.autocapture.init();
|
|
9846
10567
|
|
|
9847
10568
|
if (this.get_config('record_sessions_percent') > 0 && Math.random() * 100 <= this.get_config('record_sessions_percent')) {
|
|
9848
10569
|
this.start_session_recording();
|
|
@@ -9967,55 +10688,6 @@
|
|
|
9967
10688
|
return dt.track.apply(dt, args);
|
|
9968
10689
|
};
|
|
9969
10690
|
|
|
9970
|
-
MixpanelLib.prototype._init_url_change_tracking = function(track_pageview_option) {
|
|
9971
|
-
var previous_tracked_url = '';
|
|
9972
|
-
var tracked = this.track_pageview();
|
|
9973
|
-
if (tracked) {
|
|
9974
|
-
previous_tracked_url = _.info.currentUrl();
|
|
9975
|
-
}
|
|
9976
|
-
|
|
9977
|
-
if (_.include(['full-url', 'url-with-path-and-query-string', 'url-with-path'], track_pageview_option)) {
|
|
9978
|
-
win.addEventListener('popstate', function() {
|
|
9979
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9980
|
-
});
|
|
9981
|
-
win.addEventListener('hashchange', function() {
|
|
9982
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9983
|
-
});
|
|
9984
|
-
var nativePushState = win.history.pushState;
|
|
9985
|
-
if (typeof nativePushState === 'function') {
|
|
9986
|
-
win.history.pushState = function(state, unused, url) {
|
|
9987
|
-
nativePushState.call(win.history, state, unused, url);
|
|
9988
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9989
|
-
};
|
|
9990
|
-
}
|
|
9991
|
-
var nativeReplaceState = win.history.replaceState;
|
|
9992
|
-
if (typeof nativeReplaceState === 'function') {
|
|
9993
|
-
win.history.replaceState = function(state, unused, url) {
|
|
9994
|
-
nativeReplaceState.call(win.history, state, unused, url);
|
|
9995
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9996
|
-
};
|
|
9997
|
-
}
|
|
9998
|
-
win.addEventListener('mp_locationchange', function() {
|
|
9999
|
-
var current_url = _.info.currentUrl();
|
|
10000
|
-
var should_track = false;
|
|
10001
|
-
if (track_pageview_option === 'full-url') {
|
|
10002
|
-
should_track = current_url !== previous_tracked_url;
|
|
10003
|
-
} else if (track_pageview_option === 'url-with-path-and-query-string') {
|
|
10004
|
-
should_track = current_url.split('#')[0] !== previous_tracked_url.split('#')[0];
|
|
10005
|
-
} else if (track_pageview_option === 'url-with-path') {
|
|
10006
|
-
should_track = current_url.split('#')[0].split('?')[0] !== previous_tracked_url.split('#')[0].split('?')[0];
|
|
10007
|
-
}
|
|
10008
|
-
|
|
10009
|
-
if (should_track) {
|
|
10010
|
-
var tracked = this.track_pageview();
|
|
10011
|
-
if (tracked) {
|
|
10012
|
-
previous_tracked_url = current_url;
|
|
10013
|
-
}
|
|
10014
|
-
}
|
|
10015
|
-
}.bind(this));
|
|
10016
|
-
}
|
|
10017
|
-
};
|
|
10018
|
-
|
|
10019
10691
|
/**
|
|
10020
10692
|
* _prepare_callback() should be called by callers of _send_request for use
|
|
10021
10693
|
* as the callback argument.
|
|
@@ -11273,6 +11945,10 @@
|
|
|
11273
11945
|
this['persistence'].update_config(this['config']);
|
|
11274
11946
|
}
|
|
11275
11947
|
Config.DEBUG = Config.DEBUG || this.get_config('debug');
|
|
11948
|
+
|
|
11949
|
+
if ('autocapture' in config && this.autocapture) {
|
|
11950
|
+
this.autocapture.init();
|
|
11951
|
+
}
|
|
11276
11952
|
}
|
|
11277
11953
|
};
|
|
11278
11954
|
|