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.module.js
CHANGED
|
@@ -4507,7 +4507,7 @@ var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
|
|
|
4507
4507
|
|
|
4508
4508
|
var Config = {
|
|
4509
4509
|
DEBUG: false,
|
|
4510
|
-
LIB_VERSION: '2.
|
|
4510
|
+
LIB_VERSION: '2.59.0'
|
|
4511
4511
|
};
|
|
4512
4512
|
|
|
4513
4513
|
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
|
|
@@ -4519,11 +4519,14 @@ if (typeof(window) === 'undefined') {
|
|
|
4519
4519
|
win = {
|
|
4520
4520
|
navigator: { userAgent: '', onLine: true },
|
|
4521
4521
|
document: {
|
|
4522
|
+
createElement: function() { return {}; },
|
|
4522
4523
|
location: loc,
|
|
4523
4524
|
referrer: ''
|
|
4524
4525
|
},
|
|
4525
4526
|
screen: { width: 0, height: 0 },
|
|
4526
|
-
location: loc
|
|
4527
|
+
location: loc,
|
|
4528
|
+
addEventListener: function() {},
|
|
4529
|
+
removeEventListener: function() {}
|
|
4527
4530
|
};
|
|
4528
4531
|
} else {
|
|
4529
4532
|
win = window;
|
|
@@ -5000,6 +5003,29 @@ var console_with_prefix = function(prefix) {
|
|
|
5000
5003
|
};
|
|
5001
5004
|
|
|
5002
5005
|
|
|
5006
|
+
var safewrap = function(f) {
|
|
5007
|
+
return function() {
|
|
5008
|
+
try {
|
|
5009
|
+
return f.apply(this, arguments);
|
|
5010
|
+
} catch (e) {
|
|
5011
|
+
console$1.critical('Implementation error. Please turn on debug and contact support@mixpanel.com.');
|
|
5012
|
+
if (Config.DEBUG){
|
|
5013
|
+
console$1.critical(e);
|
|
5014
|
+
}
|
|
5015
|
+
}
|
|
5016
|
+
};
|
|
5017
|
+
};
|
|
5018
|
+
|
|
5019
|
+
var safewrapClass = function(klass) {
|
|
5020
|
+
var proto = klass.prototype;
|
|
5021
|
+
for (var func in proto) {
|
|
5022
|
+
if (typeof(proto[func]) === 'function') {
|
|
5023
|
+
proto[func] = safewrap(proto[func]);
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
};
|
|
5027
|
+
|
|
5028
|
+
|
|
5003
5029
|
// UNDERSCORE
|
|
5004
5030
|
// Embed part of the Underscore Library
|
|
5005
5031
|
_.bind = function(func, context) {
|
|
@@ -5778,6 +5804,7 @@ _.UUID = (function() {
|
|
|
5778
5804
|
var BLOCKED_UA_STRS = [
|
|
5779
5805
|
'ahrefsbot',
|
|
5780
5806
|
'ahrefssiteaudit',
|
|
5807
|
+
'amazonbot',
|
|
5781
5808
|
'baiduspider',
|
|
5782
5809
|
'bingbot',
|
|
5783
5810
|
'bingpreview',
|
|
@@ -5787,7 +5814,7 @@ var BLOCKED_UA_STRS = [
|
|
|
5787
5814
|
'pinterest',
|
|
5788
5815
|
'screaming frog',
|
|
5789
5816
|
'yahoo! slurp',
|
|
5790
|
-
'
|
|
5817
|
+
'yandex',
|
|
5791
5818
|
|
|
5792
5819
|
// a whole bunch of goog-specific crawlers
|
|
5793
5820
|
// https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers
|
|
@@ -6907,7 +6934,7 @@ function _addOptOutCheck(method, getConfigValue) {
|
|
|
6907
6934
|
};
|
|
6908
6935
|
}
|
|
6909
6936
|
|
|
6910
|
-
var logger$
|
|
6937
|
+
var logger$5 = console_with_prefix('lock');
|
|
6911
6938
|
|
|
6912
6939
|
/**
|
|
6913
6940
|
* SharedLock: a mutex built on HTML5 localStorage, to ensure that only one browser
|
|
@@ -6960,7 +6987,7 @@ SharedLock.prototype.withLock = function(lockedCB, pid) {
|
|
|
6960
6987
|
|
|
6961
6988
|
var delay = function(cb) {
|
|
6962
6989
|
if (new Date().getTime() - startTime > timeoutMS) {
|
|
6963
|
-
logger$
|
|
6990
|
+
logger$5.error('Timeout waiting for mutex on ' + key + '; clearing lock. [' + i + ']');
|
|
6964
6991
|
storage.removeItem(keyZ);
|
|
6965
6992
|
storage.removeItem(keyY);
|
|
6966
6993
|
loop();
|
|
@@ -7107,7 +7134,7 @@ LocalStorageWrapper.prototype.removeItem = function (key) {
|
|
|
7107
7134
|
}, this));
|
|
7108
7135
|
};
|
|
7109
7136
|
|
|
7110
|
-
var logger$
|
|
7137
|
+
var logger$4 = console_with_prefix('batch');
|
|
7111
7138
|
|
|
7112
7139
|
/**
|
|
7113
7140
|
* RequestQueue: queue for batching API requests with localStorage backup for retries.
|
|
@@ -7134,7 +7161,7 @@ var RequestQueue = function (storageKey, options) {
|
|
|
7134
7161
|
this.lock = new SharedLock(storageKey, { storage: options.sharedLockStorage || window.localStorage });
|
|
7135
7162
|
this.queueStorage.init();
|
|
7136
7163
|
}
|
|
7137
|
-
this.reportError = options.errorReporter || _.bind(logger$
|
|
7164
|
+
this.reportError = options.errorReporter || _.bind(logger$4.error, logger$4);
|
|
7138
7165
|
|
|
7139
7166
|
this.pid = options.pid || null; // pass pid to test out storage lock contention scenarios
|
|
7140
7167
|
|
|
@@ -7464,7 +7491,7 @@ RequestQueue.prototype.clear = function () {
|
|
|
7464
7491
|
// maximum interval between request retries after exponential backoff
|
|
7465
7492
|
var MAX_RETRY_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
|
|
7466
7493
|
|
|
7467
|
-
var logger$
|
|
7494
|
+
var logger$3 = console_with_prefix('batch');
|
|
7468
7495
|
|
|
7469
7496
|
/**
|
|
7470
7497
|
* RequestBatcher: manages the queueing, flushing, retry etc of requests of one
|
|
@@ -7588,7 +7615,7 @@ RequestBatcher.prototype.sendRequestPromise = function(data, options) {
|
|
|
7588
7615
|
*/
|
|
7589
7616
|
RequestBatcher.prototype.flush = function(options) {
|
|
7590
7617
|
if (this.requestInProgress) {
|
|
7591
|
-
logger$
|
|
7618
|
+
logger$3.log('Flush: Request already in progress');
|
|
7592
7619
|
return PromisePolyfill.resolve();
|
|
7593
7620
|
}
|
|
7594
7621
|
|
|
@@ -7765,7 +7792,7 @@ RequestBatcher.prototype.flush = function(options) {
|
|
|
7765
7792
|
if (options.unloading) {
|
|
7766
7793
|
requestOptions.transport = 'sendBeacon';
|
|
7767
7794
|
}
|
|
7768
|
-
logger$
|
|
7795
|
+
logger$3.log('MIXPANEL REQUEST:', dataForRequest);
|
|
7769
7796
|
return this.sendRequestPromise(dataForRequest, requestOptions).then(batchSendCallback);
|
|
7770
7797
|
}, this))
|
|
7771
7798
|
.catch(_.bind(function(err) {
|
|
@@ -7778,7 +7805,7 @@ RequestBatcher.prototype.flush = function(options) {
|
|
|
7778
7805
|
* Log error to global logger and optional user-defined logger.
|
|
7779
7806
|
*/
|
|
7780
7807
|
RequestBatcher.prototype.reportError = function(msg, err) {
|
|
7781
|
-
logger$
|
|
7808
|
+
logger$3.error.apply(logger$3.error, arguments);
|
|
7782
7809
|
if (this.errorReporter) {
|
|
7783
7810
|
try {
|
|
7784
7811
|
if (!(err instanceof Error)) {
|
|
@@ -7786,12 +7813,12 @@ RequestBatcher.prototype.reportError = function(msg, err) {
|
|
|
7786
7813
|
}
|
|
7787
7814
|
this.errorReporter(msg, err);
|
|
7788
7815
|
} catch(err) {
|
|
7789
|
-
logger$
|
|
7816
|
+
logger$3.error(err);
|
|
7790
7817
|
}
|
|
7791
7818
|
}
|
|
7792
7819
|
};
|
|
7793
7820
|
|
|
7794
|
-
var logger$
|
|
7821
|
+
var logger$2 = console_with_prefix('recorder');
|
|
7795
7822
|
var CompressionStream = win['CompressionStream'];
|
|
7796
7823
|
|
|
7797
7824
|
var RECORDER_BATCHER_LIB_CONFIG = {
|
|
@@ -7838,6 +7865,7 @@ var SessionRecording = function(options) {
|
|
|
7838
7865
|
|
|
7839
7866
|
this.seqNo = 0;
|
|
7840
7867
|
this.replayStartTime = null;
|
|
7868
|
+
this.replayStartUrl = null;
|
|
7841
7869
|
this.batchStartUrl = null;
|
|
7842
7870
|
|
|
7843
7871
|
this.idleTimeoutId = null;
|
|
@@ -7871,24 +7899,25 @@ SessionRecording.prototype.get_config = function(configVar) {
|
|
|
7871
7899
|
|
|
7872
7900
|
SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
|
|
7873
7901
|
if (this._stopRecording !== null) {
|
|
7874
|
-
logger$
|
|
7902
|
+
logger$2.log('Recording already in progress, skipping startRecording.');
|
|
7875
7903
|
return;
|
|
7876
7904
|
}
|
|
7877
7905
|
|
|
7878
7906
|
this.recordMaxMs = this.getConfig('record_max_ms');
|
|
7879
7907
|
if (this.recordMaxMs > MAX_RECORDING_MS) {
|
|
7880
7908
|
this.recordMaxMs = MAX_RECORDING_MS;
|
|
7881
|
-
logger$
|
|
7909
|
+
logger$2.critical('record_max_ms cannot be greater than ' + MAX_RECORDING_MS + 'ms. Capping value.');
|
|
7882
7910
|
}
|
|
7883
7911
|
|
|
7884
7912
|
this.recordMinMs = this.getConfig('record_min_ms');
|
|
7885
7913
|
if (this.recordMinMs > MAX_VALUE_FOR_MIN_RECORDING_MS) {
|
|
7886
7914
|
this.recordMinMs = MAX_VALUE_FOR_MIN_RECORDING_MS;
|
|
7887
|
-
logger$
|
|
7915
|
+
logger$2.critical('record_min_ms cannot be greater than ' + MAX_VALUE_FOR_MIN_RECORDING_MS + 'ms. Capping value.');
|
|
7888
7916
|
}
|
|
7889
7917
|
|
|
7890
7918
|
this.replayStartTime = new Date().getTime();
|
|
7891
7919
|
this.batchStartUrl = _.info.currentUrl();
|
|
7920
|
+
this.replayStartUrl = _.info.currentUrl();
|
|
7892
7921
|
|
|
7893
7922
|
if (shouldStopBatcher || this.recordMinMs > 0) {
|
|
7894
7923
|
// the primary case for shouldStopBatcher is when we're starting recording after a reset
|
|
@@ -7925,9 +7954,17 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
|
|
|
7925
7954
|
'blockClass': this.getConfig('record_block_class'),
|
|
7926
7955
|
'blockSelector': blockSelector,
|
|
7927
7956
|
'collectFonts': this.getConfig('record_collect_fonts'),
|
|
7957
|
+
'dataURLOptions': { // canvas image options (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL)
|
|
7958
|
+
'type': 'image/webp',
|
|
7959
|
+
'quality': 0.6
|
|
7960
|
+
},
|
|
7928
7961
|
'maskAllInputs': true,
|
|
7929
7962
|
'maskTextClass': this.getConfig('record_mask_text_class'),
|
|
7930
|
-
'maskTextSelector': this.getConfig('record_mask_text_selector')
|
|
7963
|
+
'maskTextSelector': this.getConfig('record_mask_text_selector'),
|
|
7964
|
+
'recordCanvas': this.getConfig('record_canvas'),
|
|
7965
|
+
'sampling': {
|
|
7966
|
+
'canvas': 15
|
|
7967
|
+
}
|
|
7931
7968
|
});
|
|
7932
7969
|
|
|
7933
7970
|
if (typeof this._stopRecording !== 'function') {
|
|
@@ -8045,6 +8082,7 @@ SessionRecording.prototype._flushEvents = addOptOutCheckMixpanelLib(function (da
|
|
|
8045
8082
|
'replay_id': replayId,
|
|
8046
8083
|
'replay_length_ms': replayLengthMs,
|
|
8047
8084
|
'replay_start_time': this.replayStartTime / 1000,
|
|
8085
|
+
'replay_start_url': this.replayStartUrl,
|
|
8048
8086
|
'seq': this.seqNo
|
|
8049
8087
|
};
|
|
8050
8088
|
var eventsJson = _.JSONEncode(data);
|
|
@@ -8077,18 +8115,18 @@ SessionRecording.prototype._flushEvents = addOptOutCheckMixpanelLib(function (da
|
|
|
8077
8115
|
|
|
8078
8116
|
|
|
8079
8117
|
SessionRecording.prototype.reportError = function(msg, err) {
|
|
8080
|
-
logger$
|
|
8118
|
+
logger$2.error.apply(logger$2.error, arguments);
|
|
8081
8119
|
try {
|
|
8082
8120
|
if (!err && !(msg instanceof Error)) {
|
|
8083
8121
|
msg = new Error(msg);
|
|
8084
8122
|
}
|
|
8085
8123
|
this.getConfig('error_reporter')(msg, err);
|
|
8086
8124
|
} catch(err) {
|
|
8087
|
-
logger$
|
|
8125
|
+
logger$2.error(err);
|
|
8088
8126
|
}
|
|
8089
8127
|
};
|
|
8090
8128
|
|
|
8091
|
-
var logger = console_with_prefix('recorder');
|
|
8129
|
+
var logger$1 = console_with_prefix('recorder');
|
|
8092
8130
|
|
|
8093
8131
|
/**
|
|
8094
8132
|
* Recorder API: manages recordings and exposes methods public to the core Mixpanel library.
|
|
@@ -8101,17 +8139,17 @@ var MixpanelRecorder = function(mixpanelInstance) {
|
|
|
8101
8139
|
|
|
8102
8140
|
MixpanelRecorder.prototype.startRecording = function(shouldStopBatcher) {
|
|
8103
8141
|
if (this.activeRecording && !this.activeRecording.isRrwebStopped()) {
|
|
8104
|
-
logger.log('Recording already in progress, skipping startRecording.');
|
|
8142
|
+
logger$1.log('Recording already in progress, skipping startRecording.');
|
|
8105
8143
|
return;
|
|
8106
8144
|
}
|
|
8107
8145
|
|
|
8108
8146
|
var onIdleTimeout = _.bind(function () {
|
|
8109
|
-
logger.log('Idle timeout reached, restarting recording.');
|
|
8147
|
+
logger$1.log('Idle timeout reached, restarting recording.');
|
|
8110
8148
|
this.resetRecording();
|
|
8111
8149
|
}, this);
|
|
8112
8150
|
|
|
8113
8151
|
var onMaxLengthReached = _.bind(function () {
|
|
8114
|
-
logger.log('Max recording length reached, stopping recording.');
|
|
8152
|
+
logger$1.log('Max recording length reached, stopping recording.');
|
|
8115
8153
|
this.resetRecording();
|
|
8116
8154
|
}, this);
|
|
8117
8155
|
|
|
@@ -8156,6 +8194,689 @@ Object.defineProperty(MixpanelRecorder.prototype, 'replayId', {
|
|
|
8156
8194
|
|
|
8157
8195
|
win['__mp_recorder'] = MixpanelRecorder;
|
|
8158
8196
|
|
|
8197
|
+
// stateless utils
|
|
8198
|
+
|
|
8199
|
+
var EV_CHANGE = 'change';
|
|
8200
|
+
var EV_CLICK = 'click';
|
|
8201
|
+
var EV_HASHCHANGE = 'hashchange';
|
|
8202
|
+
var EV_MP_LOCATION_CHANGE = 'mp_locationchange';
|
|
8203
|
+
var EV_POPSTATE = 'popstate';
|
|
8204
|
+
// TODO scrollend isn't available in Safari: document or polyfill?
|
|
8205
|
+
var EV_SCROLLEND = 'scrollend';
|
|
8206
|
+
var EV_SUBMIT = 'submit';
|
|
8207
|
+
|
|
8208
|
+
var CLICK_EVENT_PROPS = [
|
|
8209
|
+
'clientX', 'clientY',
|
|
8210
|
+
'offsetX', 'offsetY',
|
|
8211
|
+
'pageX', 'pageY',
|
|
8212
|
+
'screenX', 'screenY',
|
|
8213
|
+
'x', 'y'
|
|
8214
|
+
];
|
|
8215
|
+
var OPT_IN_CLASSES = ['mp-include'];
|
|
8216
|
+
var OPT_OUT_CLASSES = ['mp-no-track'];
|
|
8217
|
+
var SENSITIVE_DATA_CLASSES = OPT_OUT_CLASSES.concat(['mp-sensitive']);
|
|
8218
|
+
var TRACKED_ATTRS = [
|
|
8219
|
+
'aria-label', 'aria-labelledby', 'aria-describedby',
|
|
8220
|
+
'href', 'name', 'role', 'title', 'type'
|
|
8221
|
+
];
|
|
8222
|
+
|
|
8223
|
+
var logger = console_with_prefix('autocapture');
|
|
8224
|
+
|
|
8225
|
+
|
|
8226
|
+
function getClasses(el) {
|
|
8227
|
+
var classes = {};
|
|
8228
|
+
var classList = getClassName(el).split(' ');
|
|
8229
|
+
for (var i = 0; i < classList.length; i++) {
|
|
8230
|
+
var cls = classList[i];
|
|
8231
|
+
if (cls) {
|
|
8232
|
+
classes[cls] = true;
|
|
8233
|
+
}
|
|
8234
|
+
}
|
|
8235
|
+
return classes;
|
|
8236
|
+
}
|
|
8237
|
+
|
|
8238
|
+
/*
|
|
8239
|
+
* Get the className of an element, accounting for edge cases where element.className is an object
|
|
8240
|
+
* @param {Element} el - element to get the className of
|
|
8241
|
+
* @returns {string} the element's class
|
|
8242
|
+
*/
|
|
8243
|
+
function getClassName(el) {
|
|
8244
|
+
switch(typeof el.className) {
|
|
8245
|
+
case 'string':
|
|
8246
|
+
return el.className;
|
|
8247
|
+
case 'object': // handle cases where className might be SVGAnimatedString or some other type
|
|
8248
|
+
return el.className.baseVal || el.getAttribute('class') || '';
|
|
8249
|
+
default: // future proof
|
|
8250
|
+
return '';
|
|
8251
|
+
}
|
|
8252
|
+
}
|
|
8253
|
+
|
|
8254
|
+
function getPreviousElementSibling(el) {
|
|
8255
|
+
if (el.previousElementSibling) {
|
|
8256
|
+
return el.previousElementSibling;
|
|
8257
|
+
} else {
|
|
8258
|
+
do {
|
|
8259
|
+
el = el.previousSibling;
|
|
8260
|
+
} while (el && !isElementNode(el));
|
|
8261
|
+
return el;
|
|
8262
|
+
}
|
|
8263
|
+
}
|
|
8264
|
+
|
|
8265
|
+
function getPropertiesFromElement(el) {
|
|
8266
|
+
var props = {
|
|
8267
|
+
'$classes': getClassName(el).split(' '),
|
|
8268
|
+
'$tag_name': el.tagName.toLowerCase()
|
|
8269
|
+
};
|
|
8270
|
+
var elId = el.id;
|
|
8271
|
+
if (elId) {
|
|
8272
|
+
props['$id'] = elId;
|
|
8273
|
+
}
|
|
8274
|
+
|
|
8275
|
+
if (shouldTrackElement(el)) {
|
|
8276
|
+
_.each(TRACKED_ATTRS, function(attr) {
|
|
8277
|
+
if (el.hasAttribute(attr)) {
|
|
8278
|
+
var attrVal = el.getAttribute(attr);
|
|
8279
|
+
if (shouldTrackValue(attrVal)) {
|
|
8280
|
+
props['$attr-' + attr] = attrVal;
|
|
8281
|
+
}
|
|
8282
|
+
}
|
|
8283
|
+
});
|
|
8284
|
+
}
|
|
8285
|
+
|
|
8286
|
+
var nthChild = 1;
|
|
8287
|
+
var nthOfType = 1;
|
|
8288
|
+
var currentElem = el;
|
|
8289
|
+
while (currentElem = getPreviousElementSibling(currentElem)) { // eslint-disable-line no-cond-assign
|
|
8290
|
+
nthChild++;
|
|
8291
|
+
if (currentElem.tagName === el.tagName) {
|
|
8292
|
+
nthOfType++;
|
|
8293
|
+
}
|
|
8294
|
+
}
|
|
8295
|
+
props['$nth_child'] = nthChild;
|
|
8296
|
+
props['$nth_of_type'] = nthOfType;
|
|
8297
|
+
|
|
8298
|
+
return props;
|
|
8299
|
+
}
|
|
8300
|
+
|
|
8301
|
+
function getPropsForDOMEvent(ev, blockSelectors, captureTextContent) {
|
|
8302
|
+
blockSelectors = blockSelectors || [];
|
|
8303
|
+
var props = null;
|
|
8304
|
+
|
|
8305
|
+
var target = typeof ev.target === 'undefined' ? ev.srcElement : ev.target;
|
|
8306
|
+
if (isTextNode(target)) { // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
|
|
8307
|
+
target = target.parentNode;
|
|
8308
|
+
}
|
|
8309
|
+
|
|
8310
|
+
if (shouldTrackDomEvent(target, ev)) {
|
|
8311
|
+
var targetElementList = [target];
|
|
8312
|
+
var curEl = target;
|
|
8313
|
+
while (curEl.parentNode && !isTag(curEl, 'body')) {
|
|
8314
|
+
targetElementList.push(curEl.parentNode);
|
|
8315
|
+
curEl = curEl.parentNode;
|
|
8316
|
+
}
|
|
8317
|
+
|
|
8318
|
+
var elementsJson = [];
|
|
8319
|
+
var href, explicitNoTrack = false;
|
|
8320
|
+
_.each(targetElementList, function(el) {
|
|
8321
|
+
var shouldTrackEl = shouldTrackElement(el);
|
|
8322
|
+
|
|
8323
|
+
// if the element or a parent element is an anchor tag
|
|
8324
|
+
// include the href as a property
|
|
8325
|
+
if (el.tagName.toLowerCase() === 'a') {
|
|
8326
|
+
href = el.getAttribute('href');
|
|
8327
|
+
href = shouldTrackEl && shouldTrackValue(href) && href;
|
|
8328
|
+
}
|
|
8329
|
+
|
|
8330
|
+
// allow users to programmatically prevent tracking of elements by adding classes such as 'mp-no-track'
|
|
8331
|
+
var classes = getClasses(el);
|
|
8332
|
+
_.each(OPT_OUT_CLASSES, function(cls) {
|
|
8333
|
+
if (classes[cls]) {
|
|
8334
|
+
explicitNoTrack = true;
|
|
8335
|
+
}
|
|
8336
|
+
});
|
|
8337
|
+
|
|
8338
|
+
if (!explicitNoTrack) {
|
|
8339
|
+
// programmatically prevent tracking of elements that match CSS selectors
|
|
8340
|
+
_.each(blockSelectors, function(sel) {
|
|
8341
|
+
try {
|
|
8342
|
+
if (el['matches'](sel)) {
|
|
8343
|
+
explicitNoTrack = true;
|
|
8344
|
+
}
|
|
8345
|
+
} catch (err) {
|
|
8346
|
+
logger.critical('Error while checking selector: ' + sel, err);
|
|
8347
|
+
}
|
|
8348
|
+
});
|
|
8349
|
+
}
|
|
8350
|
+
|
|
8351
|
+
elementsJson.push(getPropertiesFromElement(el));
|
|
8352
|
+
}, this);
|
|
8353
|
+
|
|
8354
|
+
if (!explicitNoTrack) {
|
|
8355
|
+
var docElement = document$1['documentElement'];
|
|
8356
|
+
props = {
|
|
8357
|
+
'$event_type': ev.type,
|
|
8358
|
+
'$host': win.location.host,
|
|
8359
|
+
'$pathname': win.location.pathname,
|
|
8360
|
+
'$elements': elementsJson,
|
|
8361
|
+
'$el_attr__href': href,
|
|
8362
|
+
'$viewportHeight': Math.max(docElement['clientHeight'], win['innerHeight'] || 0),
|
|
8363
|
+
'$viewportWidth': Math.max(docElement['clientWidth'], win['innerWidth'] || 0)
|
|
8364
|
+
};
|
|
8365
|
+
|
|
8366
|
+
if (captureTextContent) {
|
|
8367
|
+
elementText = getSafeText(target);
|
|
8368
|
+
if (elementText && elementText.length) {
|
|
8369
|
+
props['$el_text'] = elementText;
|
|
8370
|
+
}
|
|
8371
|
+
}
|
|
8372
|
+
|
|
8373
|
+
if (ev.type === EV_CLICK) {
|
|
8374
|
+
_.each(CLICK_EVENT_PROPS, function(prop) {
|
|
8375
|
+
if (prop in ev) {
|
|
8376
|
+
props['$' + prop] = ev[prop];
|
|
8377
|
+
}
|
|
8378
|
+
});
|
|
8379
|
+
target = guessRealClickTarget(ev);
|
|
8380
|
+
}
|
|
8381
|
+
// prioritize text content from "real" click target if different from original target
|
|
8382
|
+
if (captureTextContent) {
|
|
8383
|
+
var elementText = getSafeText(target);
|
|
8384
|
+
if (elementText && elementText.length) {
|
|
8385
|
+
props['$el_text'] = elementText;
|
|
8386
|
+
}
|
|
8387
|
+
}
|
|
8388
|
+
|
|
8389
|
+
if (target) {
|
|
8390
|
+
var targetProps = getPropertiesFromElement(target);
|
|
8391
|
+
props['$target'] = targetProps;
|
|
8392
|
+
// pull up more props onto main event props
|
|
8393
|
+
props['$el_classes'] = targetProps['$classes'];
|
|
8394
|
+
_.extend(props, _.strip_empty_properties({
|
|
8395
|
+
'$el_id': targetProps['$id'],
|
|
8396
|
+
'$el_tag_name': targetProps['$tag_name']
|
|
8397
|
+
}));
|
|
8398
|
+
}
|
|
8399
|
+
}
|
|
8400
|
+
}
|
|
8401
|
+
|
|
8402
|
+
return props;
|
|
8403
|
+
}
|
|
8404
|
+
|
|
8405
|
+
|
|
8406
|
+
/*
|
|
8407
|
+
* Get the direct text content of an element, protecting against sensitive data collection.
|
|
8408
|
+
* Concats textContent of each of the element's text node children; this avoids potential
|
|
8409
|
+
* collection of sensitive data that could happen if we used element.textContent and the
|
|
8410
|
+
* element had sensitive child elements, since element.textContent includes child content.
|
|
8411
|
+
* Scrubs values that look like they could be sensitive (i.e. cc or ssn number).
|
|
8412
|
+
* @param {Element} el - element to get the text of
|
|
8413
|
+
* @returns {string} the element's direct text content
|
|
8414
|
+
*/
|
|
8415
|
+
function getSafeText(el) {
|
|
8416
|
+
var elText = '';
|
|
8417
|
+
|
|
8418
|
+
if (shouldTrackElement(el) && el.childNodes && el.childNodes.length) {
|
|
8419
|
+
_.each(el.childNodes, function(child) {
|
|
8420
|
+
if (isTextNode(child) && child.textContent) {
|
|
8421
|
+
elText += _.trim(child.textContent)
|
|
8422
|
+
// scrub potentially sensitive values
|
|
8423
|
+
.split(/(\s+)/).filter(shouldTrackValue).join('')
|
|
8424
|
+
// normalize whitespace
|
|
8425
|
+
.replace(/[\r\n]/g, ' ').replace(/[ ]+/g, ' ')
|
|
8426
|
+
// truncate
|
|
8427
|
+
.substring(0, 255);
|
|
8428
|
+
}
|
|
8429
|
+
});
|
|
8430
|
+
}
|
|
8431
|
+
|
|
8432
|
+
return _.trim(elText);
|
|
8433
|
+
}
|
|
8434
|
+
|
|
8435
|
+
function guessRealClickTarget(ev) {
|
|
8436
|
+
var target = ev.target;
|
|
8437
|
+
var composedPath = ev['composedPath']();
|
|
8438
|
+
for (var i = 0; i < composedPath.length; i++) {
|
|
8439
|
+
var node = composedPath[i];
|
|
8440
|
+
if (
|
|
8441
|
+
isTag(node, 'a') ||
|
|
8442
|
+
isTag(node, 'button') ||
|
|
8443
|
+
isTag(node, 'input') ||
|
|
8444
|
+
isTag(node, 'select') ||
|
|
8445
|
+
(node.getAttribute && node.getAttribute('role') === 'button')
|
|
8446
|
+
) {
|
|
8447
|
+
target = node;
|
|
8448
|
+
break;
|
|
8449
|
+
}
|
|
8450
|
+
if (node === target) {
|
|
8451
|
+
break;
|
|
8452
|
+
}
|
|
8453
|
+
}
|
|
8454
|
+
return target;
|
|
8455
|
+
}
|
|
8456
|
+
|
|
8457
|
+
/*
|
|
8458
|
+
* Check whether a DOM node has nodeType Node.ELEMENT_NODE
|
|
8459
|
+
* @param {Node} node - node to check
|
|
8460
|
+
* @returns {boolean} whether node is of the correct nodeType
|
|
8461
|
+
*/
|
|
8462
|
+
function isElementNode(node) {
|
|
8463
|
+
return node && node.nodeType === 1; // Node.ELEMENT_NODE - use integer constant for browser portability
|
|
8464
|
+
}
|
|
8465
|
+
|
|
8466
|
+
/*
|
|
8467
|
+
* Check whether an element is of a given tag type.
|
|
8468
|
+
* Due to potential reference discrepancies (such as the webcomponents.js polyfill),
|
|
8469
|
+
* we want to match tagNames instead of specific references because something like
|
|
8470
|
+
* element === document.body won't always work because element might not be a native
|
|
8471
|
+
* element.
|
|
8472
|
+
* @param {Element} el - element to check
|
|
8473
|
+
* @param {string} tag - tag name (e.g., "div")
|
|
8474
|
+
* @returns {boolean} whether el is of the given tag type
|
|
8475
|
+
*/
|
|
8476
|
+
function isTag(el, tag) {
|
|
8477
|
+
return el && el.tagName && el.tagName.toLowerCase() === tag.toLowerCase();
|
|
8478
|
+
}
|
|
8479
|
+
|
|
8480
|
+
/*
|
|
8481
|
+
* Check whether a DOM node is a TEXT_NODE
|
|
8482
|
+
* @param {Node} node - node to check
|
|
8483
|
+
* @returns {boolean} whether node is of type Node.TEXT_NODE
|
|
8484
|
+
*/
|
|
8485
|
+
function isTextNode(node) {
|
|
8486
|
+
return node && node.nodeType === 3; // Node.TEXT_NODE - use integer constant for browser portability
|
|
8487
|
+
}
|
|
8488
|
+
|
|
8489
|
+
function minDOMApisSupported() {
|
|
8490
|
+
try {
|
|
8491
|
+
var testEl = document$1.createElement('div');
|
|
8492
|
+
return !!testEl['matches'];
|
|
8493
|
+
} catch (err) {
|
|
8494
|
+
return false;
|
|
8495
|
+
}
|
|
8496
|
+
}
|
|
8497
|
+
|
|
8498
|
+
/*
|
|
8499
|
+
* Check whether a DOM event should be "tracked" or if it may contain sensitive data
|
|
8500
|
+
* using a variety of heuristics.
|
|
8501
|
+
* @param {Element} el - element to check
|
|
8502
|
+
* @param {Event} ev - event to check
|
|
8503
|
+
* @returns {boolean} whether the event should be tracked
|
|
8504
|
+
*/
|
|
8505
|
+
function shouldTrackDomEvent(el, ev) {
|
|
8506
|
+
if (!el || isTag(el, 'html') || !isElementNode(el)) {
|
|
8507
|
+
return false;
|
|
8508
|
+
}
|
|
8509
|
+
var tag = el.tagName.toLowerCase();
|
|
8510
|
+
switch (tag) {
|
|
8511
|
+
case 'form':
|
|
8512
|
+
return ev.type === EV_SUBMIT;
|
|
8513
|
+
case 'input':
|
|
8514
|
+
if (['button', 'submit'].indexOf(el.getAttribute('type')) === -1) {
|
|
8515
|
+
return ev.type === EV_CHANGE;
|
|
8516
|
+
} else {
|
|
8517
|
+
return ev.type === EV_CLICK;
|
|
8518
|
+
}
|
|
8519
|
+
case 'select':
|
|
8520
|
+
case 'textarea':
|
|
8521
|
+
return ev.type === EV_CHANGE;
|
|
8522
|
+
default:
|
|
8523
|
+
return ev.type === EV_CLICK;
|
|
8524
|
+
}
|
|
8525
|
+
}
|
|
8526
|
+
|
|
8527
|
+
/*
|
|
8528
|
+
* Check whether a DOM element should be "tracked" or if it may contain sensitive data
|
|
8529
|
+
* using a variety of heuristics.
|
|
8530
|
+
* @param {Element} el - element to check
|
|
8531
|
+
* @returns {boolean} whether the element should be tracked
|
|
8532
|
+
*/
|
|
8533
|
+
function shouldTrackElement(el) {
|
|
8534
|
+
var i;
|
|
8535
|
+
|
|
8536
|
+
for (var curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode) {
|
|
8537
|
+
var classes = getClasses(curEl);
|
|
8538
|
+
for (i = 0; i < SENSITIVE_DATA_CLASSES.length; i++) {
|
|
8539
|
+
if (classes[SENSITIVE_DATA_CLASSES[i]]) {
|
|
8540
|
+
return false;
|
|
8541
|
+
}
|
|
8542
|
+
}
|
|
8543
|
+
}
|
|
8544
|
+
|
|
8545
|
+
var elClasses = getClasses(el);
|
|
8546
|
+
for (i = 0; i < OPT_IN_CLASSES.length; i++) {
|
|
8547
|
+
if (elClasses[OPT_IN_CLASSES[i]]) {
|
|
8548
|
+
return true;
|
|
8549
|
+
}
|
|
8550
|
+
}
|
|
8551
|
+
|
|
8552
|
+
// don't send data from inputs or similar elements since there will always be
|
|
8553
|
+
// a risk of clientside javascript placing sensitive data in attributes
|
|
8554
|
+
if (
|
|
8555
|
+
isTag(el, 'input') ||
|
|
8556
|
+
isTag(el, 'select') ||
|
|
8557
|
+
isTag(el, 'textarea') ||
|
|
8558
|
+
el.getAttribute('contenteditable') === 'true'
|
|
8559
|
+
) {
|
|
8560
|
+
return false;
|
|
8561
|
+
}
|
|
8562
|
+
|
|
8563
|
+
// don't include hidden or password fields
|
|
8564
|
+
var type = el.type || '';
|
|
8565
|
+
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"]
|
|
8566
|
+
switch(type.toLowerCase()) {
|
|
8567
|
+
case 'hidden':
|
|
8568
|
+
return false;
|
|
8569
|
+
case 'password':
|
|
8570
|
+
return false;
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
|
|
8574
|
+
// filter out data from fields that look like sensitive fields
|
|
8575
|
+
var name = el.name || el.id || '';
|
|
8576
|
+
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"]
|
|
8577
|
+
var sensitiveNameRegex = /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i;
|
|
8578
|
+
if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {
|
|
8579
|
+
return false;
|
|
8580
|
+
}
|
|
8581
|
+
}
|
|
8582
|
+
|
|
8583
|
+
return true;
|
|
8584
|
+
}
|
|
8585
|
+
|
|
8586
|
+
|
|
8587
|
+
/*
|
|
8588
|
+
* Check whether a string value should be "tracked" or if it may contain sensitive data
|
|
8589
|
+
* using a variety of heuristics.
|
|
8590
|
+
* @param {string} value - string value to check
|
|
8591
|
+
* @returns {boolean} whether the element should be tracked
|
|
8592
|
+
*/
|
|
8593
|
+
function shouldTrackValue(value) {
|
|
8594
|
+
if (value === null || _.isUndefined(value)) {
|
|
8595
|
+
return false;
|
|
8596
|
+
}
|
|
8597
|
+
|
|
8598
|
+
if (typeof value === 'string') {
|
|
8599
|
+
value = _.trim(value);
|
|
8600
|
+
|
|
8601
|
+
// check to see if input value looks like a credit card number
|
|
8602
|
+
// see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html
|
|
8603
|
+
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}))$/;
|
|
8604
|
+
if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {
|
|
8605
|
+
return false;
|
|
8606
|
+
}
|
|
8607
|
+
|
|
8608
|
+
// check to see if input value looks like a social security number
|
|
8609
|
+
var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/;
|
|
8610
|
+
if (ssnRegex.test(value)) {
|
|
8611
|
+
return false;
|
|
8612
|
+
}
|
|
8613
|
+
}
|
|
8614
|
+
|
|
8615
|
+
return true;
|
|
8616
|
+
}
|
|
8617
|
+
|
|
8618
|
+
var AUTOCAPTURE_CONFIG_KEY = 'autocapture';
|
|
8619
|
+
var LEGACY_PAGEVIEW_CONFIG_KEY = 'track_pageview';
|
|
8620
|
+
|
|
8621
|
+
var PAGEVIEW_OPTION_FULL_URL = 'full-url';
|
|
8622
|
+
var PAGEVIEW_OPTION_URL_WITH_PATH_AND_QUERY_STRING = 'url-with-path-and-query-string';
|
|
8623
|
+
var PAGEVIEW_OPTION_URL_WITH_PATH = 'url-with-path';
|
|
8624
|
+
|
|
8625
|
+
var CONFIG_BLOCK_SELECTORS = 'block_selectors';
|
|
8626
|
+
var CONFIG_BLOCK_URL_REGEXES = 'block_url_regexes';
|
|
8627
|
+
var CONFIG_CAPTURE_TEXT_CONTENT = 'capture_text_content';
|
|
8628
|
+
var CONFIG_TRACK_CLICK = 'click';
|
|
8629
|
+
var CONFIG_TRACK_INPUT = 'input';
|
|
8630
|
+
var CONFIG_TRACK_PAGEVIEW = 'pageview';
|
|
8631
|
+
var CONFIG_TRACK_SCROLL = 'scroll';
|
|
8632
|
+
var CONFIG_TRACK_SUBMIT = 'submit';
|
|
8633
|
+
|
|
8634
|
+
var CONFIG_DEFAULTS = {};
|
|
8635
|
+
CONFIG_DEFAULTS[CONFIG_CAPTURE_TEXT_CONTENT] = false;
|
|
8636
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_CLICK] = true;
|
|
8637
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_INPUT] = true;
|
|
8638
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_PAGEVIEW] = PAGEVIEW_OPTION_FULL_URL;
|
|
8639
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_SCROLL] = true;
|
|
8640
|
+
CONFIG_DEFAULTS[CONFIG_TRACK_SUBMIT] = true;
|
|
8641
|
+
|
|
8642
|
+
var DEFAULT_PROPS = {
|
|
8643
|
+
'$mp_autocapture': true
|
|
8644
|
+
};
|
|
8645
|
+
|
|
8646
|
+
var MP_EV_CLICK = '$mp_click';
|
|
8647
|
+
var MP_EV_INPUT = '$mp_input_change';
|
|
8648
|
+
var MP_EV_SCROLL = '$mp_scroll';
|
|
8649
|
+
var MP_EV_SUBMIT = '$mp_submit';
|
|
8650
|
+
|
|
8651
|
+
/**
|
|
8652
|
+
* Autocapture: manages automatic event tracking
|
|
8653
|
+
* @constructor
|
|
8654
|
+
*/
|
|
8655
|
+
var Autocapture = function(mp) {
|
|
8656
|
+
this.mp = mp;
|
|
8657
|
+
};
|
|
8658
|
+
|
|
8659
|
+
Autocapture.prototype.init = function() {
|
|
8660
|
+
if (!minDOMApisSupported()) {
|
|
8661
|
+
logger.critical('Autocapture unavailable: missing required DOM APIs');
|
|
8662
|
+
return;
|
|
8663
|
+
}
|
|
8664
|
+
|
|
8665
|
+
this.initPageviewTracking();
|
|
8666
|
+
this.initClickTracking();
|
|
8667
|
+
this.initInputTracking();
|
|
8668
|
+
this.initScrollTracking();
|
|
8669
|
+
this.initSubmitTracking();
|
|
8670
|
+
};
|
|
8671
|
+
|
|
8672
|
+
Autocapture.prototype.getFullConfig = function() {
|
|
8673
|
+
var autocaptureConfig = this.mp.get_config(AUTOCAPTURE_CONFIG_KEY);
|
|
8674
|
+
if (!autocaptureConfig) {
|
|
8675
|
+
// Autocapture is completely off
|
|
8676
|
+
return {};
|
|
8677
|
+
} else if (_.isObject(autocaptureConfig)) {
|
|
8678
|
+
return _.extend({}, CONFIG_DEFAULTS, autocaptureConfig);
|
|
8679
|
+
} else {
|
|
8680
|
+
// Autocapture config is non-object truthy value, return default
|
|
8681
|
+
return CONFIG_DEFAULTS;
|
|
8682
|
+
}
|
|
8683
|
+
};
|
|
8684
|
+
|
|
8685
|
+
Autocapture.prototype.getConfig = function(key) {
|
|
8686
|
+
return this.getFullConfig()[key];
|
|
8687
|
+
};
|
|
8688
|
+
|
|
8689
|
+
Autocapture.prototype.currentUrlBlocked = function() {
|
|
8690
|
+
var blockUrlRegexes = this.getConfig(CONFIG_BLOCK_URL_REGEXES) || [];
|
|
8691
|
+
if (!blockUrlRegexes || !blockUrlRegexes.length) {
|
|
8692
|
+
return false;
|
|
8693
|
+
}
|
|
8694
|
+
|
|
8695
|
+
var currentUrl = _.info.currentUrl();
|
|
8696
|
+
for (var i = 0; i < blockUrlRegexes.length; i++) {
|
|
8697
|
+
try {
|
|
8698
|
+
if (currentUrl.match(blockUrlRegexes[i])) {
|
|
8699
|
+
return true;
|
|
8700
|
+
}
|
|
8701
|
+
} catch (err) {
|
|
8702
|
+
logger.critical('Error while checking block URL regex: ' + blockUrlRegexes[i], err);
|
|
8703
|
+
return true;
|
|
8704
|
+
}
|
|
8705
|
+
}
|
|
8706
|
+
return false;
|
|
8707
|
+
};
|
|
8708
|
+
|
|
8709
|
+
Autocapture.prototype.pageviewTrackingConfig = function() {
|
|
8710
|
+
// supports both autocapture config and old track_pageview config
|
|
8711
|
+
if (this.mp.get_config(AUTOCAPTURE_CONFIG_KEY)) {
|
|
8712
|
+
return this.getConfig(CONFIG_TRACK_PAGEVIEW);
|
|
8713
|
+
} else {
|
|
8714
|
+
return this.mp.get_config(LEGACY_PAGEVIEW_CONFIG_KEY);
|
|
8715
|
+
}
|
|
8716
|
+
};
|
|
8717
|
+
|
|
8718
|
+
// helper for event handlers
|
|
8719
|
+
Autocapture.prototype.trackDomEvent = function(ev, mpEventName) {
|
|
8720
|
+
if (this.currentUrlBlocked()) {
|
|
8721
|
+
return;
|
|
8722
|
+
}
|
|
8723
|
+
|
|
8724
|
+
var props = getPropsForDOMEvent(
|
|
8725
|
+
ev,
|
|
8726
|
+
this.getConfig(CONFIG_BLOCK_SELECTORS),
|
|
8727
|
+
this.getConfig(CONFIG_CAPTURE_TEXT_CONTENT)
|
|
8728
|
+
);
|
|
8729
|
+
if (props) {
|
|
8730
|
+
_.extend(props, DEFAULT_PROPS);
|
|
8731
|
+
this.mp.track(mpEventName, props);
|
|
8732
|
+
}
|
|
8733
|
+
};
|
|
8734
|
+
|
|
8735
|
+
Autocapture.prototype.initClickTracking = function() {
|
|
8736
|
+
win.removeEventListener(EV_CLICK, this.listenerClick);
|
|
8737
|
+
|
|
8738
|
+
if (!this.getConfig(CONFIG_TRACK_CLICK)) {
|
|
8739
|
+
return;
|
|
8740
|
+
}
|
|
8741
|
+
logger.log('Initializing click tracking');
|
|
8742
|
+
|
|
8743
|
+
this.listenerClick = win.addEventListener(EV_CLICK, function(ev) {
|
|
8744
|
+
if (!this.getConfig(CONFIG_TRACK_CLICK)) {
|
|
8745
|
+
return;
|
|
8746
|
+
}
|
|
8747
|
+
this.trackDomEvent(ev, MP_EV_CLICK);
|
|
8748
|
+
}.bind(this));
|
|
8749
|
+
};
|
|
8750
|
+
|
|
8751
|
+
Autocapture.prototype.initInputTracking = function() {
|
|
8752
|
+
win.removeEventListener(EV_CHANGE, this.listenerChange);
|
|
8753
|
+
|
|
8754
|
+
if (!this.getConfig(CONFIG_TRACK_INPUT)) {
|
|
8755
|
+
return;
|
|
8756
|
+
}
|
|
8757
|
+
logger.log('Initializing input tracking');
|
|
8758
|
+
|
|
8759
|
+
this.listenerChange = win.addEventListener(EV_CHANGE, function(ev) {
|
|
8760
|
+
if (!this.getConfig(CONFIG_TRACK_INPUT)) {
|
|
8761
|
+
return;
|
|
8762
|
+
}
|
|
8763
|
+
this.trackDomEvent(ev, MP_EV_INPUT);
|
|
8764
|
+
}.bind(this));
|
|
8765
|
+
};
|
|
8766
|
+
|
|
8767
|
+
Autocapture.prototype.initPageviewTracking = function() {
|
|
8768
|
+
win.removeEventListener(EV_POPSTATE, this.listenerPopstate);
|
|
8769
|
+
win.removeEventListener(EV_HASHCHANGE, this.listenerHashchange);
|
|
8770
|
+
win.removeEventListener(EV_MP_LOCATION_CHANGE, this.listenerLocationchange);
|
|
8771
|
+
|
|
8772
|
+
if (!this.pageviewTrackingConfig()) {
|
|
8773
|
+
return;
|
|
8774
|
+
}
|
|
8775
|
+
logger.log('Initializing pageview tracking');
|
|
8776
|
+
|
|
8777
|
+
var previousTrackedUrl = '';
|
|
8778
|
+
var tracked = false;
|
|
8779
|
+
if (!this.currentUrlBlocked()) {
|
|
8780
|
+
tracked = this.mp.track_pageview(DEFAULT_PROPS);
|
|
8781
|
+
}
|
|
8782
|
+
if (tracked) {
|
|
8783
|
+
previousTrackedUrl = _.info.currentUrl();
|
|
8784
|
+
}
|
|
8785
|
+
|
|
8786
|
+
this.listenerPopstate = win.addEventListener(EV_POPSTATE, function() {
|
|
8787
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8788
|
+
});
|
|
8789
|
+
this.listenerHashchange = win.addEventListener(EV_HASHCHANGE, function() {
|
|
8790
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8791
|
+
});
|
|
8792
|
+
var nativePushState = win.history.pushState;
|
|
8793
|
+
if (typeof nativePushState === 'function') {
|
|
8794
|
+
win.history.pushState = function(state, unused, url) {
|
|
8795
|
+
nativePushState.call(win.history, state, unused, url);
|
|
8796
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8797
|
+
};
|
|
8798
|
+
}
|
|
8799
|
+
var nativeReplaceState = win.history.replaceState;
|
|
8800
|
+
if (typeof nativeReplaceState === 'function') {
|
|
8801
|
+
win.history.replaceState = function(state, unused, url) {
|
|
8802
|
+
nativeReplaceState.call(win.history, state, unused, url);
|
|
8803
|
+
win.dispatchEvent(new Event(EV_MP_LOCATION_CHANGE));
|
|
8804
|
+
};
|
|
8805
|
+
}
|
|
8806
|
+
this.listenerLocationchange = win.addEventListener(EV_MP_LOCATION_CHANGE, safewrap(function() {
|
|
8807
|
+
if (this.currentUrlBlocked()) {
|
|
8808
|
+
return;
|
|
8809
|
+
}
|
|
8810
|
+
|
|
8811
|
+
var currentUrl = _.info.currentUrl();
|
|
8812
|
+
var shouldTrack = false;
|
|
8813
|
+
var trackPageviewOption = this.pageviewTrackingConfig();
|
|
8814
|
+
if (trackPageviewOption === PAGEVIEW_OPTION_FULL_URL) {
|
|
8815
|
+
shouldTrack = currentUrl !== previousTrackedUrl;
|
|
8816
|
+
} else if (trackPageviewOption === PAGEVIEW_OPTION_URL_WITH_PATH_AND_QUERY_STRING) {
|
|
8817
|
+
shouldTrack = currentUrl.split('#')[0] !== previousTrackedUrl.split('#')[0];
|
|
8818
|
+
} else if (trackPageviewOption === PAGEVIEW_OPTION_URL_WITH_PATH) {
|
|
8819
|
+
shouldTrack = currentUrl.split('#')[0].split('?')[0] !== previousTrackedUrl.split('#')[0].split('?')[0];
|
|
8820
|
+
}
|
|
8821
|
+
|
|
8822
|
+
if (shouldTrack) {
|
|
8823
|
+
var tracked = this.mp.track_pageview(DEFAULT_PROPS);
|
|
8824
|
+
if (tracked) {
|
|
8825
|
+
previousTrackedUrl = currentUrl;
|
|
8826
|
+
}
|
|
8827
|
+
}
|
|
8828
|
+
}.bind(this)));
|
|
8829
|
+
};
|
|
8830
|
+
|
|
8831
|
+
Autocapture.prototype.initScrollTracking = function() {
|
|
8832
|
+
win.removeEventListener(EV_SCROLLEND, this.listenerScroll);
|
|
8833
|
+
|
|
8834
|
+
if (!this.getConfig(CONFIG_TRACK_SCROLL)) {
|
|
8835
|
+
return;
|
|
8836
|
+
}
|
|
8837
|
+
logger.log('Initializing scroll tracking');
|
|
8838
|
+
|
|
8839
|
+
this.listenerScroll = win.addEventListener(EV_SCROLLEND, safewrap(function() {
|
|
8840
|
+
if (!this.getConfig(CONFIG_TRACK_SCROLL)) {
|
|
8841
|
+
return;
|
|
8842
|
+
}
|
|
8843
|
+
if (this.currentUrlBlocked()) {
|
|
8844
|
+
return;
|
|
8845
|
+
}
|
|
8846
|
+
|
|
8847
|
+
var scrollTop = win.scrollY;
|
|
8848
|
+
var props = _.extend({'$scroll_top': scrollTop}, DEFAULT_PROPS);
|
|
8849
|
+
try {
|
|
8850
|
+
var scrollHeight = document$1.body.scrollHeight;
|
|
8851
|
+
var scrollPercentage = Math.round((scrollTop / (scrollHeight - win.innerHeight)) * 100);
|
|
8852
|
+
props['$scroll_height'] = scrollHeight;
|
|
8853
|
+
props['$scroll_percentage'] = scrollPercentage;
|
|
8854
|
+
} catch (err) {
|
|
8855
|
+
logger.critical('Error while calculating scroll percentage', err);
|
|
8856
|
+
}
|
|
8857
|
+
this.mp.track(MP_EV_SCROLL, props);
|
|
8858
|
+
}.bind(this)));
|
|
8859
|
+
};
|
|
8860
|
+
|
|
8861
|
+
Autocapture.prototype.initSubmitTracking = function() {
|
|
8862
|
+
win.removeEventListener(EV_SUBMIT, this.listenerSubmit);
|
|
8863
|
+
|
|
8864
|
+
if (!this.getConfig(CONFIG_TRACK_SUBMIT)) {
|
|
8865
|
+
return;
|
|
8866
|
+
}
|
|
8867
|
+
logger.log('Initializing submit tracking');
|
|
8868
|
+
|
|
8869
|
+
this.listenerSubmit = win.addEventListener(EV_SUBMIT, function(ev) {
|
|
8870
|
+
if (!this.getConfig(CONFIG_TRACK_SUBMIT)) {
|
|
8871
|
+
return;
|
|
8872
|
+
}
|
|
8873
|
+
this.trackDomEvent(ev, MP_EV_SUBMIT);
|
|
8874
|
+
}.bind(this));
|
|
8875
|
+
};
|
|
8876
|
+
|
|
8877
|
+
// TODO integrate error_reporter from mixpanel instance
|
|
8878
|
+
safewrapClass(Autocapture);
|
|
8879
|
+
|
|
8159
8880
|
/* eslint camelcase: "off" */
|
|
8160
8881
|
|
|
8161
8882
|
/**
|
|
@@ -9575,6 +10296,7 @@ var DEFAULT_CONFIG = {
|
|
|
9575
10296
|
'api_transport': 'XHR',
|
|
9576
10297
|
'api_payload_format': PAYLOAD_TYPE_BASE64,
|
|
9577
10298
|
'app_host': 'https://mixpanel.com',
|
|
10299
|
+
'autocapture': false,
|
|
9578
10300
|
'cdn': 'https://cdn.mxpnl.com',
|
|
9579
10301
|
'cross_site_cookie': false,
|
|
9580
10302
|
'cross_subdomain_cookie': true,
|
|
@@ -9617,6 +10339,7 @@ var DEFAULT_CONFIG = {
|
|
|
9617
10339
|
'hooks': {},
|
|
9618
10340
|
'record_block_class': new RegExp('^(mp-block|fs-exclude|amp-block|rr-block|ph-no-capture)$'),
|
|
9619
10341
|
'record_block_selector': 'img, video',
|
|
10342
|
+
'record_canvas': false,
|
|
9620
10343
|
'record_collect_fonts': false,
|
|
9621
10344
|
'record_idle_timeout_ms': 30 * 60 * 1000, // 30 minutes
|
|
9622
10345
|
'record_mask_text_class': new RegExp('^(mp-mask|fs-mask|amp-mask|rr-mask|ph-mask)$'),
|
|
@@ -9833,10 +10556,8 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
9833
10556
|
}, '');
|
|
9834
10557
|
}
|
|
9835
10558
|
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
this._init_url_change_tracking(track_pageview_option);
|
|
9839
|
-
}
|
|
10559
|
+
this.autocapture = new Autocapture(this);
|
|
10560
|
+
this.autocapture.init();
|
|
9840
10561
|
|
|
9841
10562
|
if (this.get_config('record_sessions_percent') > 0 && Math.random() * 100 <= this.get_config('record_sessions_percent')) {
|
|
9842
10563
|
this.start_session_recording();
|
|
@@ -9961,55 +10682,6 @@ MixpanelLib.prototype._track_dom = function(DomClass, args) {
|
|
|
9961
10682
|
return dt.track.apply(dt, args);
|
|
9962
10683
|
};
|
|
9963
10684
|
|
|
9964
|
-
MixpanelLib.prototype._init_url_change_tracking = function(track_pageview_option) {
|
|
9965
|
-
var previous_tracked_url = '';
|
|
9966
|
-
var tracked = this.track_pageview();
|
|
9967
|
-
if (tracked) {
|
|
9968
|
-
previous_tracked_url = _.info.currentUrl();
|
|
9969
|
-
}
|
|
9970
|
-
|
|
9971
|
-
if (_.include(['full-url', 'url-with-path-and-query-string', 'url-with-path'], track_pageview_option)) {
|
|
9972
|
-
win.addEventListener('popstate', function() {
|
|
9973
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9974
|
-
});
|
|
9975
|
-
win.addEventListener('hashchange', function() {
|
|
9976
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9977
|
-
});
|
|
9978
|
-
var nativePushState = win.history.pushState;
|
|
9979
|
-
if (typeof nativePushState === 'function') {
|
|
9980
|
-
win.history.pushState = function(state, unused, url) {
|
|
9981
|
-
nativePushState.call(win.history, state, unused, url);
|
|
9982
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9983
|
-
};
|
|
9984
|
-
}
|
|
9985
|
-
var nativeReplaceState = win.history.replaceState;
|
|
9986
|
-
if (typeof nativeReplaceState === 'function') {
|
|
9987
|
-
win.history.replaceState = function(state, unused, url) {
|
|
9988
|
-
nativeReplaceState.call(win.history, state, unused, url);
|
|
9989
|
-
win.dispatchEvent(new Event('mp_locationchange'));
|
|
9990
|
-
};
|
|
9991
|
-
}
|
|
9992
|
-
win.addEventListener('mp_locationchange', function() {
|
|
9993
|
-
var current_url = _.info.currentUrl();
|
|
9994
|
-
var should_track = false;
|
|
9995
|
-
if (track_pageview_option === 'full-url') {
|
|
9996
|
-
should_track = current_url !== previous_tracked_url;
|
|
9997
|
-
} else if (track_pageview_option === 'url-with-path-and-query-string') {
|
|
9998
|
-
should_track = current_url.split('#')[0] !== previous_tracked_url.split('#')[0];
|
|
9999
|
-
} else if (track_pageview_option === 'url-with-path') {
|
|
10000
|
-
should_track = current_url.split('#')[0].split('?')[0] !== previous_tracked_url.split('#')[0].split('?')[0];
|
|
10001
|
-
}
|
|
10002
|
-
|
|
10003
|
-
if (should_track) {
|
|
10004
|
-
var tracked = this.track_pageview();
|
|
10005
|
-
if (tracked) {
|
|
10006
|
-
previous_tracked_url = current_url;
|
|
10007
|
-
}
|
|
10008
|
-
}
|
|
10009
|
-
}.bind(this));
|
|
10010
|
-
}
|
|
10011
|
-
};
|
|
10012
|
-
|
|
10013
10685
|
/**
|
|
10014
10686
|
* _prepare_callback() should be called by callers of _send_request for use
|
|
10015
10687
|
* as the callback argument.
|
|
@@ -11267,6 +11939,10 @@ MixpanelLib.prototype.set_config = function(config) {
|
|
|
11267
11939
|
this['persistence'].update_config(this['config']);
|
|
11268
11940
|
}
|
|
11269
11941
|
Config.DEBUG = Config.DEBUG || this.get_config('debug');
|
|
11942
|
+
|
|
11943
|
+
if ('autocapture' in config && this.autocapture) {
|
|
11944
|
+
this.autocapture.init();
|
|
11945
|
+
}
|
|
11270
11946
|
}
|
|
11271
11947
|
};
|
|
11272
11948
|
|