@usermaven/sdk-js 1.1.2 → 1.1.4

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.
@@ -326,13 +326,26 @@ var getCookies = function (useCache) {
326
326
  cookieParsingCache = res;
327
327
  return res;
328
328
  };
329
+ // Methods partially borrowed from quirksmode.org/js/cookies.html
329
330
  var getCookie = function (name) {
330
331
  if (!name) {
331
332
  return null;
332
333
  }
333
- return (decodeURIComponent(requireWindow().document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" +
334
- encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") +
335
- "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null);
334
+ try {
335
+ var nameEQ = name + '=';
336
+ var ca = requireWindow().document.cookie.split(';');
337
+ for (var i = 0; i < ca.length; i++) {
338
+ var c = ca[i];
339
+ while (c.charAt(0) == ' ') {
340
+ c = c.substring(1, c.length);
341
+ }
342
+ if (c.indexOf(nameEQ) === 0) {
343
+ return decodeURIComponent(c.substring(nameEQ.length, c.length));
344
+ }
345
+ }
346
+ }
347
+ catch (err) { }
348
+ return null;
336
349
  };
337
350
  var setCookie = function (name, value, opts) {
338
351
  if (opts === void 0) { opts = {}; }
@@ -976,6 +989,106 @@ var RageClick = /** @class */ (function () {
976
989
  return RageClick;
977
990
  }());
978
991
 
992
+ /**
993
+ * Scroll extension to add scroll get scroll depth in percentage
994
+ */
995
+ var ScrollDepth = /** @class */ (function () {
996
+ function ScrollDepth(instance) {
997
+ this.instance = instance;
998
+ this.lastScrollDepth = 0;
999
+ this.canSend = true;
1000
+ this.documentElement = document.documentElement;
1001
+ }
1002
+ /**
1003
+ * Track scroll depth
1004
+ * @description this function will be called on every scroll event to track scroll depth
1005
+ */
1006
+ ScrollDepth.prototype.track = function () {
1007
+ var scrollDepth = this.getScrollDepth();
1008
+ // If scroll depth is greater than last scroll depth, then update last scroll depth
1009
+ // We are doing this to only get the maximum scroll depth
1010
+ if (scrollDepth > this.lastScrollDepth) {
1011
+ this.lastScrollDepth = scrollDepth;
1012
+ this.canSend = true;
1013
+ }
1014
+ };
1015
+ /**
1016
+ * Send scroll depth event
1017
+ * @description this function will be when we want to send scroll depth event e.g. on page visibility change
1018
+ */
1019
+ ScrollDepth.prototype.send = function (eventType) {
1020
+ if (eventType === void 0) { eventType = "$scroll"; }
1021
+ if (!this.canSend || !this.lastScrollDepth) {
1022
+ return;
1023
+ }
1024
+ // Creating payload
1025
+ var props = {
1026
+ percent: this.lastScrollDepth,
1027
+ window_height: this.getWindowHeight(),
1028
+ document_height: this.getDocumentHeight(),
1029
+ scroll_distance: this.getScrollDistance()
1030
+ };
1031
+ // Sending event
1032
+ this.instance.capture(eventType, props);
1033
+ // Setting canSend to false, for avoiding sending multiple events
1034
+ this.canSend = false;
1035
+ };
1036
+ /**
1037
+ * Core method to get scroll depth
1038
+ */
1039
+ ScrollDepth.prototype.getScrollDepth = function () {
1040
+ try {
1041
+ // Get the height of the window and the document body
1042
+ var winHeight = this.getWindowHeight();
1043
+ var docHeight = this.getDocumentHeight();
1044
+ // Get the current scroll position and the length of the track
1045
+ var scrollTop = this.getScrollDistance();
1046
+ var trackLength = docHeight - winHeight;
1047
+ // Calculate the scroll depth as a percentage
1048
+ return Math.floor(scrollTop / trackLength * 100);
1049
+ }
1050
+ catch (e) {
1051
+ return 0;
1052
+ }
1053
+ };
1054
+ /**
1055
+ * Core method to get window height
1056
+ */
1057
+ ScrollDepth.prototype.getWindowHeight = function () {
1058
+ try {
1059
+ return window.innerHeight || this.documentElement.clientHeight ||
1060
+ document.body.clientHeight || 0;
1061
+ }
1062
+ catch (e) {
1063
+ return 0;
1064
+ }
1065
+ };
1066
+ /**
1067
+ * Core method to get document height
1068
+ */
1069
+ ScrollDepth.prototype.getDocumentHeight = function () {
1070
+ try {
1071
+ return Math.max(document.body.scrollHeight || 0, this.documentElement.scrollHeight || 0, document.body.offsetHeight || 0, this.documentElement.offsetHeight || 0, document.body.clientHeight || 0, this.documentElement.clientHeight || 0);
1072
+ }
1073
+ catch (e) {
1074
+ return 0;
1075
+ }
1076
+ };
1077
+ /**
1078
+ * Core method to get scroll distance
1079
+ */
1080
+ ScrollDepth.prototype.getScrollDistance = function () {
1081
+ try {
1082
+ return window.scrollY || window.pageYOffset || document.body.scrollTop ||
1083
+ this.documentElement.scrollTop || 0;
1084
+ }
1085
+ catch (e) {
1086
+ return 0;
1087
+ }
1088
+ };
1089
+ return ScrollDepth;
1090
+ }());
1091
+
979
1092
  var autocapture = {
980
1093
  _initializedTokens: [],
981
1094
  _previousElementSibling: function (el) {
@@ -1085,6 +1198,16 @@ var autocapture = {
1085
1198
  // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
1086
1199
  target = (target.parentNode || null);
1087
1200
  }
1201
+ // If type is 'scroll', track the scroll depth
1202
+ if (e.type === 'scroll') {
1203
+ this.scrollDepth.track();
1204
+ return true;
1205
+ }
1206
+ // If type is visibilitychange and the page is about to be hidden, send a scroll depth event
1207
+ if ((e.type === 'visibilitychange' && document.visibilityState === 'hidden') || e.type === 'popstate') {
1208
+ this.scrollDepth.send();
1209
+ return true;
1210
+ }
1088
1211
  if (e.type === 'click' && e instanceof MouseEvent) {
1089
1212
  (_a = this.rageclicks) === null || _a === void 0 ? void 0 : _a.click(e.clientX, e.clientY, new Date().getTime());
1090
1213
  }
@@ -1147,13 +1270,18 @@ var autocapture = {
1147
1270
  _register_event(document, 'submit', handler, false, true);
1148
1271
  _register_event(document, 'change', handler, false, true);
1149
1272
  _register_event(document, 'click', handler, false, true);
1273
+ _register_event(document, 'visibilitychange', handler, false, true);
1274
+ _register_event(document, 'scroll', handler, false, true);
1275
+ _register_event(window, 'popstate', handler, false, true);
1150
1276
  },
1151
1277
  _customProperties: [],
1152
1278
  rageclicks: null,
1279
+ scrollDepth: null,
1153
1280
  opts: {},
1154
1281
  init: function (instance, opts) {
1155
1282
  var _this = this;
1156
1283
  this.rageclicks = new RageClick(instance);
1284
+ this.scrollDepth = new ScrollDepth(instance);
1157
1285
  this.opts = opts;
1158
1286
  if (!(document && document.body)) {
1159
1287
  console.debug('document not ready yet, trying again in 500 milliseconds...');
@@ -1193,8 +1321,8 @@ _safewrap_instance_methods(autocapture);
1193
1321
 
1194
1322
  var VERSION_INFO = {
1195
1323
  env: 'production',
1196
- date: '2022-10-07T08:04:30.209Z',
1197
- version: '1.1.2'
1324
+ date: '2022-12-16T16:54:52.442Z',
1325
+ version: '1.1.4'
1198
1326
  };
1199
1327
  var USERMAVEN_VERSION = "".concat(VERSION_INFO.version, "/").concat(VERSION_INFO.env, "@").concat(VERSION_INFO.date);
1200
1328
  var MAX_AGE_TEN_YEARS = 31622400 * 10;
@@ -1268,11 +1396,13 @@ var CookiePersistence = /** @class */ (function () {
1268
1396
  var NoPersistence = /** @class */ (function () {
1269
1397
  function NoPersistence() {
1270
1398
  }
1271
- NoPersistence.prototype.save = function (props) { };
1399
+ NoPersistence.prototype.save = function (props) {
1400
+ };
1272
1401
  NoPersistence.prototype.restore = function () {
1273
1402
  return undefined;
1274
1403
  };
1275
- NoPersistence.prototype.delete = function () { };
1404
+ NoPersistence.prototype.delete = function () {
1405
+ };
1276
1406
  return NoPersistence;
1277
1407
  }());
1278
1408
  var defaultCompatMode = false;
@@ -1484,7 +1614,8 @@ var envs = {
1484
1614
  empty: function () { return emptyEnv; },
1485
1615
  };
1486
1616
  var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1487
- if (handler === void 0) { handler = function (code, body) { }; }
1617
+ if (handler === void 0) { handler = function (code, body) {
1618
+ }; }
1488
1619
  var req = new window.XMLHttpRequest();
1489
1620
  return new Promise(function (resolve, reject) {
1490
1621
  req.onerror = function (e) {
@@ -1515,7 +1646,8 @@ var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1515
1646
  };
1516
1647
  var fetchTransport = function (fetch) {
1517
1648
  return function (url, jsonPayload, additionalHeaders, handler) {
1518
- if (handler === void 0) { handler = function (code, body) { }; }
1649
+ if (handler === void 0) { handler = function (code, body) {
1650
+ }; }
1519
1651
  return __awaiter(void 0, void 0, void 0, function () {
1520
1652
  var res, e_1, resJson, text, contentType, e_2;
1521
1653
  var _a, _b;
@@ -1837,7 +1969,14 @@ var UsermavenClientImpl = /** @class */ (function () {
1837
1969
  return;
1838
1970
  }
1839
1971
  }
1840
- var e = this.makeEvent(type, this.compatMode ? "eventn" : "usermaven", payload || {});
1972
+ var p = payload || {};
1973
+ // All custom events and scroll event will have event_attributes
1974
+ if (type !== "$autocapture" && type !== "user_identify" && type !== "pageview") {
1975
+ p = {
1976
+ event_attributes: payload,
1977
+ };
1978
+ }
1979
+ var e = this.makeEvent(type, this.compatMode ? "eventn" : "usermaven", p);
1841
1980
  return this.sendJson(e);
1842
1981
  };
1843
1982
  UsermavenClientImpl.prototype.init = function (options) {
@@ -2081,17 +2220,17 @@ var UsermavenClientImpl = /** @class */ (function () {
2081
2220
  }
2082
2221
  };
2083
2222
  /**
2084
- * Capture an event. This is the most important and
2085
- * frequently used usermaven function.
2086
- *
2087
- * ### Usage:
2088
- * usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
2089
- *
2090
- * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
2091
- * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
2092
- * @param {Object} [options] Optional configuration for this capture request.
2093
- * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
2094
- */
2223
+ * Capture an event. This is the most important and
2224
+ * frequently used usermaven function.
2225
+ *
2226
+ * ### Usage:
2227
+ * usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
2228
+ *
2229
+ * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
2230
+ * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
2231
+ * @param {Object} [options] Optional configuration for this capture request.
2232
+ * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
2233
+ */
2095
2234
  UsermavenClientImpl.prototype.capture = function (event_name, properties) {
2096
2235
  var _a, _b;
2097
2236
  if (properties === void 0) { properties = {}; }
@@ -2116,12 +2255,16 @@ var UsermavenClientImpl = /** @class */ (function () {
2116
2255
  this.track("$autocapture", data.properties);
2117
2256
  // this.track(data.event, data.properties)
2118
2257
  }
2258
+ // send event if the event is $scroll
2259
+ if (event_name === '$scroll') {
2260
+ this.track(event_name, data.properties);
2261
+ }
2119
2262
  };
2120
2263
  UsermavenClientImpl.prototype._calculate_event_properties = function (event_name, event_properties) {
2121
2264
  var _a, _b;
2122
2265
  // set defaults
2123
2266
  var properties = event_properties || {};
2124
- if (event_name === '$snapshot') {
2267
+ if (event_name === '$snapshot' || event_name === '$scroll') {
2125
2268
  return properties;
2126
2269
  }
2127
2270
  if (_isArray(this.propertyBlacklist)) {
@@ -322,13 +322,26 @@ var getCookies = function (useCache) {
322
322
  cookieParsingCache = res;
323
323
  return res;
324
324
  };
325
+ // Methods partially borrowed from quirksmode.org/js/cookies.html
325
326
  var getCookie = function (name) {
326
327
  if (!name) {
327
328
  return null;
328
329
  }
329
- return (decodeURIComponent(requireWindow().document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" +
330
- encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") +
331
- "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null);
330
+ try {
331
+ var nameEQ = name + '=';
332
+ var ca = requireWindow().document.cookie.split(';');
333
+ for (var i = 0; i < ca.length; i++) {
334
+ var c = ca[i];
335
+ while (c.charAt(0) == ' ') {
336
+ c = c.substring(1, c.length);
337
+ }
338
+ if (c.indexOf(nameEQ) === 0) {
339
+ return decodeURIComponent(c.substring(nameEQ.length, c.length));
340
+ }
341
+ }
342
+ }
343
+ catch (err) { }
344
+ return null;
332
345
  };
333
346
  var setCookie = function (name, value, opts) {
334
347
  if (opts === void 0) { opts = {}; }
@@ -972,6 +985,106 @@ var RageClick = /** @class */ (function () {
972
985
  return RageClick;
973
986
  }());
974
987
 
988
+ /**
989
+ * Scroll extension to add scroll get scroll depth in percentage
990
+ */
991
+ var ScrollDepth = /** @class */ (function () {
992
+ function ScrollDepth(instance) {
993
+ this.instance = instance;
994
+ this.lastScrollDepth = 0;
995
+ this.canSend = true;
996
+ this.documentElement = document.documentElement;
997
+ }
998
+ /**
999
+ * Track scroll depth
1000
+ * @description this function will be called on every scroll event to track scroll depth
1001
+ */
1002
+ ScrollDepth.prototype.track = function () {
1003
+ var scrollDepth = this.getScrollDepth();
1004
+ // If scroll depth is greater than last scroll depth, then update last scroll depth
1005
+ // We are doing this to only get the maximum scroll depth
1006
+ if (scrollDepth > this.lastScrollDepth) {
1007
+ this.lastScrollDepth = scrollDepth;
1008
+ this.canSend = true;
1009
+ }
1010
+ };
1011
+ /**
1012
+ * Send scroll depth event
1013
+ * @description this function will be when we want to send scroll depth event e.g. on page visibility change
1014
+ */
1015
+ ScrollDepth.prototype.send = function (eventType) {
1016
+ if (eventType === void 0) { eventType = "$scroll"; }
1017
+ if (!this.canSend || !this.lastScrollDepth) {
1018
+ return;
1019
+ }
1020
+ // Creating payload
1021
+ var props = {
1022
+ percent: this.lastScrollDepth,
1023
+ window_height: this.getWindowHeight(),
1024
+ document_height: this.getDocumentHeight(),
1025
+ scroll_distance: this.getScrollDistance()
1026
+ };
1027
+ // Sending event
1028
+ this.instance.capture(eventType, props);
1029
+ // Setting canSend to false, for avoiding sending multiple events
1030
+ this.canSend = false;
1031
+ };
1032
+ /**
1033
+ * Core method to get scroll depth
1034
+ */
1035
+ ScrollDepth.prototype.getScrollDepth = function () {
1036
+ try {
1037
+ // Get the height of the window and the document body
1038
+ var winHeight = this.getWindowHeight();
1039
+ var docHeight = this.getDocumentHeight();
1040
+ // Get the current scroll position and the length of the track
1041
+ var scrollTop = this.getScrollDistance();
1042
+ var trackLength = docHeight - winHeight;
1043
+ // Calculate the scroll depth as a percentage
1044
+ return Math.floor(scrollTop / trackLength * 100);
1045
+ }
1046
+ catch (e) {
1047
+ return 0;
1048
+ }
1049
+ };
1050
+ /**
1051
+ * Core method to get window height
1052
+ */
1053
+ ScrollDepth.prototype.getWindowHeight = function () {
1054
+ try {
1055
+ return window.innerHeight || this.documentElement.clientHeight ||
1056
+ document.body.clientHeight || 0;
1057
+ }
1058
+ catch (e) {
1059
+ return 0;
1060
+ }
1061
+ };
1062
+ /**
1063
+ * Core method to get document height
1064
+ */
1065
+ ScrollDepth.prototype.getDocumentHeight = function () {
1066
+ try {
1067
+ return Math.max(document.body.scrollHeight || 0, this.documentElement.scrollHeight || 0, document.body.offsetHeight || 0, this.documentElement.offsetHeight || 0, document.body.clientHeight || 0, this.documentElement.clientHeight || 0);
1068
+ }
1069
+ catch (e) {
1070
+ return 0;
1071
+ }
1072
+ };
1073
+ /**
1074
+ * Core method to get scroll distance
1075
+ */
1076
+ ScrollDepth.prototype.getScrollDistance = function () {
1077
+ try {
1078
+ return window.scrollY || window.pageYOffset || document.body.scrollTop ||
1079
+ this.documentElement.scrollTop || 0;
1080
+ }
1081
+ catch (e) {
1082
+ return 0;
1083
+ }
1084
+ };
1085
+ return ScrollDepth;
1086
+ }());
1087
+
975
1088
  var autocapture = {
976
1089
  _initializedTokens: [],
977
1090
  _previousElementSibling: function (el) {
@@ -1081,6 +1194,16 @@ var autocapture = {
1081
1194
  // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
1082
1195
  target = (target.parentNode || null);
1083
1196
  }
1197
+ // If type is 'scroll', track the scroll depth
1198
+ if (e.type === 'scroll') {
1199
+ this.scrollDepth.track();
1200
+ return true;
1201
+ }
1202
+ // If type is visibilitychange and the page is about to be hidden, send a scroll depth event
1203
+ if ((e.type === 'visibilitychange' && document.visibilityState === 'hidden') || e.type === 'popstate') {
1204
+ this.scrollDepth.send();
1205
+ return true;
1206
+ }
1084
1207
  if (e.type === 'click' && e instanceof MouseEvent) {
1085
1208
  (_a = this.rageclicks) === null || _a === void 0 ? void 0 : _a.click(e.clientX, e.clientY, new Date().getTime());
1086
1209
  }
@@ -1143,13 +1266,18 @@ var autocapture = {
1143
1266
  _register_event(document, 'submit', handler, false, true);
1144
1267
  _register_event(document, 'change', handler, false, true);
1145
1268
  _register_event(document, 'click', handler, false, true);
1269
+ _register_event(document, 'visibilitychange', handler, false, true);
1270
+ _register_event(document, 'scroll', handler, false, true);
1271
+ _register_event(window, 'popstate', handler, false, true);
1146
1272
  },
1147
1273
  _customProperties: [],
1148
1274
  rageclicks: null,
1275
+ scrollDepth: null,
1149
1276
  opts: {},
1150
1277
  init: function (instance, opts) {
1151
1278
  var _this = this;
1152
1279
  this.rageclicks = new RageClick(instance);
1280
+ this.scrollDepth = new ScrollDepth(instance);
1153
1281
  this.opts = opts;
1154
1282
  if (!(document && document.body)) {
1155
1283
  console.debug('document not ready yet, trying again in 500 milliseconds...');
@@ -1189,8 +1317,8 @@ _safewrap_instance_methods(autocapture);
1189
1317
 
1190
1318
  var VERSION_INFO = {
1191
1319
  env: 'production',
1192
- date: '2022-10-07T08:04:30.209Z',
1193
- version: '1.1.2'
1320
+ date: '2022-12-16T16:54:52.442Z',
1321
+ version: '1.1.4'
1194
1322
  };
1195
1323
  var USERMAVEN_VERSION = "".concat(VERSION_INFO.version, "/").concat(VERSION_INFO.env, "@").concat(VERSION_INFO.date);
1196
1324
  var MAX_AGE_TEN_YEARS = 31622400 * 10;
@@ -1264,11 +1392,13 @@ var CookiePersistence = /** @class */ (function () {
1264
1392
  var NoPersistence = /** @class */ (function () {
1265
1393
  function NoPersistence() {
1266
1394
  }
1267
- NoPersistence.prototype.save = function (props) { };
1395
+ NoPersistence.prototype.save = function (props) {
1396
+ };
1268
1397
  NoPersistence.prototype.restore = function () {
1269
1398
  return undefined;
1270
1399
  };
1271
- NoPersistence.prototype.delete = function () { };
1400
+ NoPersistence.prototype.delete = function () {
1401
+ };
1272
1402
  return NoPersistence;
1273
1403
  }());
1274
1404
  var defaultCompatMode = false;
@@ -1480,7 +1610,8 @@ var envs = {
1480
1610
  empty: function () { return emptyEnv; },
1481
1611
  };
1482
1612
  var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1483
- if (handler === void 0) { handler = function (code, body) { }; }
1613
+ if (handler === void 0) { handler = function (code, body) {
1614
+ }; }
1484
1615
  var req = new window.XMLHttpRequest();
1485
1616
  return new Promise(function (resolve, reject) {
1486
1617
  req.onerror = function (e) {
@@ -1511,7 +1642,8 @@ var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1511
1642
  };
1512
1643
  var fetchTransport = function (fetch) {
1513
1644
  return function (url, jsonPayload, additionalHeaders, handler) {
1514
- if (handler === void 0) { handler = function (code, body) { }; }
1645
+ if (handler === void 0) { handler = function (code, body) {
1646
+ }; }
1515
1647
  return __awaiter(void 0, void 0, void 0, function () {
1516
1648
  var res, e_1, resJson, text, contentType, e_2;
1517
1649
  var _a, _b;
@@ -1833,7 +1965,14 @@ var UsermavenClientImpl = /** @class */ (function () {
1833
1965
  return;
1834
1966
  }
1835
1967
  }
1836
- var e = this.makeEvent(type, this.compatMode ? "eventn" : "usermaven", payload || {});
1968
+ var p = payload || {};
1969
+ // All custom events and scroll event will have event_attributes
1970
+ if (type !== "$autocapture" && type !== "user_identify" && type !== "pageview") {
1971
+ p = {
1972
+ event_attributes: payload,
1973
+ };
1974
+ }
1975
+ var e = this.makeEvent(type, this.compatMode ? "eventn" : "usermaven", p);
1837
1976
  return this.sendJson(e);
1838
1977
  };
1839
1978
  UsermavenClientImpl.prototype.init = function (options) {
@@ -2077,17 +2216,17 @@ var UsermavenClientImpl = /** @class */ (function () {
2077
2216
  }
2078
2217
  };
2079
2218
  /**
2080
- * Capture an event. This is the most important and
2081
- * frequently used usermaven function.
2082
- *
2083
- * ### Usage:
2084
- * usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
2085
- *
2086
- * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
2087
- * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
2088
- * @param {Object} [options] Optional configuration for this capture request.
2089
- * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
2090
- */
2219
+ * Capture an event. This is the most important and
2220
+ * frequently used usermaven function.
2221
+ *
2222
+ * ### Usage:
2223
+ * usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
2224
+ *
2225
+ * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
2226
+ * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
2227
+ * @param {Object} [options] Optional configuration for this capture request.
2228
+ * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
2229
+ */
2091
2230
  UsermavenClientImpl.prototype.capture = function (event_name, properties) {
2092
2231
  var _a, _b;
2093
2232
  if (properties === void 0) { properties = {}; }
@@ -2112,12 +2251,16 @@ var UsermavenClientImpl = /** @class */ (function () {
2112
2251
  this.track("$autocapture", data.properties);
2113
2252
  // this.track(data.event, data.properties)
2114
2253
  }
2254
+ // send event if the event is $scroll
2255
+ if (event_name === '$scroll') {
2256
+ this.track(event_name, data.properties);
2257
+ }
2115
2258
  };
2116
2259
  UsermavenClientImpl.prototype._calculate_event_properties = function (event_name, event_properties) {
2117
2260
  var _a, _b;
2118
2261
  // set defaults
2119
2262
  var properties = event_properties || {};
2120
- if (event_name === '$snapshot') {
2263
+ if (event_name === '$snapshot' || event_name === '$scroll') {
2121
2264
  return properties;
2122
2265
  }
2123
2266
  if (_isArray(this.propertyBlacklist)) {
package/dist/web/lib.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{c(r.next(e))}catch(e){o(e)}}function s(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function r(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}function i(e){let t=!!globalThis.window;return!t&&e&&c().warn(e),t}function o(e){if(!i())throw new Error(e||"window' is not available. Seems like this code runs outside browser environment. It shouldn't happen");return window}var a={DEBUG:{name:"DEBUG",severity:10},INFO:{name:"INFO",severity:100},WARN:{name:"WARN",severity:1e3},ERROR:{name:"ERROR",severity:1e4},NONE:{name:"NONE",severity:1e4}},s=null;function c(){return s||(s=u())}function u(e){var t=i()&&window.__eventNLogLevel,n=a.WARN;if(t){var o=a[t.toUpperCase()];o&&o>0&&(n=o)}else e&&(n=e);var s={minLogLevel:n};return Object.values(a).forEach((function(e){var t=e.name,i=e.severity;s[t.toLowerCase()]=function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];if(i>=n.severity&&e.length>0){var a=e[0],s=e.splice(1),c="[J-".concat(t,"] ").concat(a);"DEBUG"===t||"INFO"===t?console.log.apply(console,r([c],s,!1)):"WARN"===t?console.warn.apply(console,r([c],s,!1)):console.error.apply(console,r([c],s,!1))}}})),function(e,t){if(i()){var n=window;n.__usermavenDebug||(n.__usermavenDebug={}),n.__usermavenDebug[e]=t}}("logger",s),s}function l(e,t,n){var r;void 0===n&&(n={});var i=e+"="+encodeURIComponent(t);if(i+="; Path="+(null!==(r=n.path)&&void 0!==r?r:"/"),n.maxAge&&(i+="; Max-Age="+Math.floor(n.maxAge)),n.domain&&(i+="; Domain="+n.domain),n.expires&&(i+="; Expires="+n.expires.toUTCString()),n.httpOnly&&(i+="; HttpOnly"),n.secure&&(i+="; Secure"),n.sameSite)switch("string"==typeof n.sameSite?n.sameSite.toLowerCase():n.sameSite){case!0:i+="; SameSite=Strict";break;case"lax":i+="; SameSite=Lax";break;case"strict":i+="; SameSite=Strict";break;case"none":i+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return i}var p;function d(e){if(!e)return{};for(var t={},n=e.split(";"),r=0;r<n.length;r++){var i=n[r],o=i.indexOf("=");o>0&&(t[i.substr(r>0?1:0,r>0?o-1:o)]=i.substr(o+1))}return t}function h(e,t){return Array.from(e.attributes).forEach((function(e){t.setAttribute(e.nodeName,e.nodeValue)}))}function f(e,t){e.innerHTML=t;var n,r=e.getElementsByTagName("script");for(n=r.length-1;n>=0;n--){var i=r[n],o=document.createElement("script");h(i,o),i.innerHTML&&(o.innerHTML=i.innerHTML),o.setAttribute("data-usermaven-tag-id",e.id),document.getElementsByTagName("head")[0].appendChild(o),r[n].parentNode.removeChild(r[n])}}var m=function(e){return e&&decodeURIComponent(o().document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},v=function(e,t,n){void 0===n&&(n={}),o().document.cookie=l(e,t,n)},g=function(e,t){void 0===t&&(t="/"),document.cookie=e+"= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"+(t?"; path = "+t:"")},y=function(){return Math.random().toString(36).substring(2,12)},_=function(){return Math.random().toString(36).substring(2,7)},b={utm_source:"source",utm_medium:"medium",utm_campaign:"campaign",utm_term:"term",utm_content:"content"},w={gclid:!0,fbclid:!0,dclid:!0};var k=function(){function e(){this.queue=[]}return e.prototype.flush=function(){var e=this.queue;return this.queue=[],e},e.prototype.push=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=this.queue).push.apply(e,t)},e}(),P=function(){function e(e){this.key=e}return e.prototype.flush=function(){var e=this.get();return e.length&&this.set([]),e},e.prototype.push=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this.get();n.push.apply(n,e),this.set(n)},e.prototype.set=function(e){localStorage.setItem(this.key,JSON.stringify(e))},e.prototype.get=function(){var e=localStorage.getItem(this.key);return null!==e&&""!==e?JSON.parse(e):[]},e}(),x=Object.prototype,S=x.toString,N=x.hasOwnProperty,A=Array.prototype.forEach,C=Array.isArray,E={},O=C||function(e){return"[object Array]"===S.call(e)};function I(e,t,n){if(Array.isArray(e))if(A&&e.forEach===A)e.forEach(t,n);else if("length"in e&&e.length===+e.length)for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r)===E)return}var T=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function j(e,t,n){if(null!=e)if(A&&Array.isArray(e)&&e.forEach===A)e.forEach(t,n);else if("length"in e&&e.length===+e.length){for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r)===E)return}else for(var o in e)if(N.call(e,o)&&t.call(n,e[o],o)===E)return}var $=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return I(t,(function(t){for(var n in t)void 0!==t[n]&&(e[n]=t[n])})),e};function F(e,t){return-1!==e.indexOf(t)}var U=function(e){try{return/^\s*\bfunction\b/.test(e)}catch(e){return!1}},D=function(e){return void 0===e},M=function(){function e(t){return t&&(t.preventDefault=e.preventDefault,t.stopPropagation=e.stopPropagation),t}return e.preventDefault=function(){this.returnValue=!1},e.stopPropagation=function(){this.cancelBubble=!0},function(t,n,r,i,o){if(t)if(t.addEventListener&&!i)t.addEventListener(n,r,!!o);else{var a="on"+n,s=t[a];t[a]=function(t,n,r){return function(i){if(i=i||e(window.event)){var o,a=!0;U(r)&&(o=r(i));var s=n.call(t,i);return!1!==o&&!1!==s||(a=!1),a}}}(t,r,s)}else c().error("No valid element provided to register_event")}}(),L=function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return e.apply(this,t)}catch(e){c().error("Implementation error. Please turn on debug and contact support@usermaven.com.",e)}}},z="undefined"!=typeof Symbol?Symbol("__deepCircularCopyInProgress__"):"__deepCircularCopyInProgress__";function R(e,t,n){return e!==Object(e)?t?t(e,n):e:e[z]?void 0:(e[z]=!0,O(e)?(r=[],I(e,(function(e){r.push(R(e,t))}))):(r={},j(e,(function(e,n){n!==z&&(r[n]=R(e,t,n))}))),delete e[z],r);var r}var H=["$performance_raw"];function q(e,t){return R(e,(function(e,n){return n&&H.indexOf(n)>-1?e:"string"==typeof e&&null!==t?e.slice(0,t):e}))}function J(e){switch(typeof e.className){case"string":return e.className;case"object":return("baseVal"in e.className?e.className.baseVal:null)||e.getAttribute("class")||"";default:return""}}function B(e){var t="";return X(e)&&!Y(e)&&e.childNodes&&e.childNodes.length&&j(e.childNodes,(function(e){Q(e)&&e.textContent&&(t+=T(e.textContent).split(/(\s+)/).filter(Z).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))})),T(t)}function V(e){return!!e&&1===e.nodeType}function K(e,t){return!!e&&!!e.tagName&&e.tagName.toLowerCase()===t.toLowerCase()}function Q(e){return!!e&&3===e.nodeType}function G(e){return!!e&&11===e.nodeType}var W=["a","button","form","input","select","textarea","label"];function X(e){for(var t=e;t.parentNode&&!K(t,"body");t=t.parentNode){var n=J(t).split(" ");if(F(n,"ph-sensitive")||F(n,"ph-no-capture"))return!1}if(F(J(e).split(" "),"ph-include"))return!0;var r=e.type||"";if("string"==typeof r)switch(r.toLowerCase()){case"hidden":case"password":return!1}var i=e.name||e.id||"";if("string"==typeof i){if(/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(i.replace(/[^a-zA-Z0-9]/g,"")))return!1}return!0}function Y(e){return!!(K(e,"input")&&!["button","checkbox","submit","reset"].includes(e.type)||K(e,"select")||K(e,"textarea")||"true"===e.getAttribute("contenteditable"))}function Z(e){if(null===e||D(e))return!1;if("string"==typeof e){e=T(e);if(/^(?:(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}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0}var ee=function(){function e(e,t){void 0===t&&(t=!1),this.clicks=[],this.instance=e,this.enabled=t}return e.prototype.click=function(e,t,n){if(this.enabled){var r=this.clicks[this.clicks.length-1];r&&Math.abs(e-r.x)+Math.abs(t-r.y)<30&&n-r.timestamp<1e3?(this.clicks.push({x:e,y:t,timestamp:n}),3===this.clicks.length&&this.instance.capture("$rageclick")):this.clicks=[{x:e,y:t,timestamp:n}]}},e}(),te={_initializedTokens:[],_previousElementSibling:function(e){if(e.previousElementSibling)return e.previousElementSibling;var t=e;do{t=t.previousSibling}while(t&&!V(t));return t},_getPropertiesFromElement:function(e,t,n){var r=e.tagName.toLowerCase(),i={tag_name:r};W.indexOf(r)>-1&&!n&&(i.$el_text=B(e));var o=J(e);o.length>0&&(i.classes=o.split(" ").filter((function(e){return""!==e}))),j(e.attributes,(function(n){var r;Y(e)&&-1===["name","id","class"].indexOf(n.name)||!t&&Z(n.value)&&("string"!=typeof(r=n.name)||"_ngcontent"!==r.substring(0,10)&&"_nghost"!==r.substring(0,7))&&(i["attr__"+n.name]=n.value)}));for(var a=1,s=1,c=e;c=this._previousElementSibling(c);)a++,c.tagName===e.tagName&&s++;return i.nth_child=a,i.nth_of_type=s,i},_getDefaultProperties:function(e){return{$event_type:e,$ce_version:1}},_extractCustomPropertyValue:function(e){var t=[];return j(document.querySelectorAll(e.css_selector),(function(e){var n;["input","select"].indexOf(e.tagName.toLowerCase())>-1?n=e.value:e.textContent&&(n=e.textContent),Z(n)&&t.push(n)})),t.join(", ")},_getCustomProperties:function(e){var t=this,n={};return j(this._customProperties,(function(r){j(r.event_selectors,(function(i){j(document.querySelectorAll(i),(function(i){F(e,i)&&X(i)&&(n[r.name]=t._extractCustomPropertyValue(r))}))}))})),n},_getEventTarget:function(e){var t;return void 0===e.target?e.srcElement||null:(null===(t=e.target)||void 0===t?void 0:t.shadowRoot)?e.composedPath()[0]||null:e.target||null},_captureEvent:function(e,t,n){var r,i=this,o=this._getEventTarget(e);if(Q(o)&&(o=o.parentNode||null),"click"===e.type&&e instanceof MouseEvent&&(null===(r=this.rageclicks)||void 0===r||r.click(e.clientX,e.clientY,(new Date).getTime())),o&&function(e,t){if(!e||K(e,"html")||!V(e))return!1;for(var n=!1,r=[e],i=!0,o=e;o.parentNode&&!K(o,"body");)if(G(o.parentNode))r.push(o.parentNode.host),o=o.parentNode.host;else{if(!(i=o.parentNode||!1))break;if(W.indexOf(i.tagName.toLowerCase())>-1)n=!0;else{var a=window.getComputedStyle(i);a&&"pointer"===a.getPropertyValue("cursor")&&(n=!0)}r.push(i),o=i}var s=window.getComputedStyle(e);if(s&&"pointer"===s.getPropertyValue("cursor")&&"click"===t.type)return!0;var c=e.tagName.toLowerCase();switch(c){case"html":return!1;case"form":return"submit"===t.type;case"input":case"select":case"textarea":return"change"===t.type||"click"===t.type;default:return n?"click"===t.type:"click"===t.type&&(W.indexOf(c)>-1||"true"===e.getAttribute("contenteditable"))}}(o,e)){for(var a=[o],s=o;s.parentNode&&!K(s,"body");)G(s.parentNode)?(a.push(s.parentNode.host),s=s.parentNode.host):(a.push(s.parentNode),s=s.parentNode);var c,u=[],l=!1;if(j(a,(function(e){var t=X(e);"a"===e.tagName.toLowerCase()&&(c=e.getAttribute("href"),c=t&&Z(c)&&c),F(J(e).split(" "),"ph-no-capture")&&(l=!0),u.push(i._getPropertiesFromElement(e,null==n?void 0:n.mask_all_element_attributes,null==n?void 0:n.mask_all_text))})),(null==n?void 0:n.mask_all_text)||(u[0].$el_text=B(o)),c&&(u[0].attr__href=c),l)return!1;var p=$(this._getDefaultProperties(e.type),{$elements:u},this._getCustomProperties(a));return t.capture("$autocapture",p),!0}},_navigate:function(e){window.location.href=e},_addDomEventHandlers:function(e,t){var n=this,r=function(r){r=r||window.event,n._captureEvent(r,e,t)};M(document,"submit",r,!1,!0),M(document,"change",r,!1,!0),M(document,"click",r,!1,!0)},_customProperties:[],rageclicks:null,opts:{},init:function(e,t){var n=this;if(this.rageclicks=new ee(e),this.opts=t,!document||!document.body)return console.debug("document not ready yet, trying again in 500 milliseconds..."),void setTimeout((function(){n.readyAutocapture(e,t)}),500);this.readyAutocapture(e,t)},readyAutocapture:function(e,t){this._addDomEventHandlers(e,t)},enabledForProject:function(e,t,n){if(!e)return!0;t=D(t)?10:t,n=D(n)?10:n;for(var r=0,i=0;i<e.length;i++)r+=e.charCodeAt(i);return r%t<n},isBrowserSupported:function(){return U(document.querySelectorAll)}};!function(e){for(var t in e)"function"==typeof e[t]&&(e[t]=e[t].bind(e))}(te),function(e){for(var t in e)"function"==typeof e[t]&&(e[t]=L(e[t]))}(te);var ne="__buildEnv__",re="__buildDate__",ie="".concat("__buildVersion__","/").concat(ne,"@").concat(re),oe=316224e3,ae=function(e,t){c().debug("Sending beacon",t);var n=new Blob([t],{type:"text/plain"});return navigator.sendBeacon(e,n),Promise.resolve()};var se=function(e,t){return console.debug("Jitsu client tried to send payload to ".concat(e),function(e){if("string"==typeof e)try{return JSON.stringify(JSON.parse(e),null,2)}catch(t){return e}}(t)),Promise.resolve()};function ce(e,t){void 0===t&&(t=void 0),""!=(t=null!=t?t:window.location.pathname)&&"/"!=t&&(g(e,t),ce(e,t.slice(0,t.lastIndexOf("/"))))}var ue=function(){function e(e,t){this.cookieDomain=e,this.cookieName=t}return e.prototype.save=function(e){v(this.cookieName,JSON.stringify(e),{domain:this.cookieDomain,secure:"http:"!==document.location.protocol,maxAge:oe})},e.prototype.restore=function(){ce(this.cookieName);var e=m(this.cookieName);if(e)try{var t=JSON.parse(decodeURIComponent(e));return"object"!=typeof t?void c().warn("Can't restore value of ".concat(this.cookieName,"@").concat(this.cookieDomain,", expected to be object, but found ").concat("object"!=typeof t,": ").concat(t,". Ignoring")):t}catch(t){return void c().error("Failed to decode JSON from "+e,t)}},e.prototype.delete=function(){g(this.cookieName)},e}(),le=function(){function e(){}return e.prototype.save=function(e){},e.prototype.restore=function(){},e.prototype.delete=function(){},e}();var pe={getSourceIp:function(){},describeClient:function(){return{referer:document.referrer,url:window.location.href,page_title:document.title,doc_path:document.location.pathname,doc_host:document.location.hostname,doc_search:window.location.search,screen_resolution:screen.width+"x"+screen.height,vp_size:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)+"x"+Math.max(document.documentElement.clientHeight||0,window.innerHeight||0),user_agent:navigator.userAgent,user_language:navigator.language,doc_encoding:document.characterSet}},getAnonymousId:function(e){var t=e.name,n=e.domain;ce(t);var r=m(t);if(r)return c().debug("Existing user id",r),r;var i=y();return c().debug("New user id",i),v(t,i,{domain:n,secure:"http:"!==document.location.protocol,maxAge:oe}),i}};var de={getSourceIp:function(){},describeClient:function(){return{}},getAnonymousId:function(){return""}},he=function(){return pe},fe=function(){return de},me=function(e,t,n,r){void 0===r&&(r=function(e,t){});var i=new window.XMLHttpRequest;return new Promise((function(o,a){i.onerror=function(e){c().error("Failed to send",t,e),r(-1,{}),a(new Error("Failed to send JSON. See console logs"))},i.onload=function(){200!==i.status?(r(i.status,{}),c().warn("Failed to send data to ".concat(e," (#").concat(i.status," - ").concat(i.statusText,")"),t),a(new Error("Failed to send JSON. Error code: ".concat(i.status,". See logs for details")))):r(i.status,i.responseText),o()},i.open("POST",e),i.setRequestHeader("Content-Type","application/json"),Object.entries(n||{}).forEach((function(e){var t=e[0],n=e[1];return i.setRequestHeader(t,n)})),i.send(t),c().debug("sending json",t)}))},ve=function(){function r(){this.userProperties={},this.permanentProperties={globalProps:{},propsPerEvent:{}},this.cookieDomain="",this.trackingHost="",this.idCookieName="",this.randomizeUrl=!1,this.apiKey="",this.initialized=!1,this._3pCookies={},this.cookiePolicy="keep",this.ipPolicy="keep",this.beaconApi=!1,this.transport=me,this.customHeaders=function(){return{}},this.queue=new k,this.maxSendAttempts=4,this.retryTimeout=[500,1e12],this.flushing=!1,this.attempt=1,this.propertyBlacklist=[],this.__autocapture_enabled=!1}return r.prototype.get_config=function(e){return this.config?this.config[e]:null},r.prototype.id=function(t,n){return this.userProperties=e(e({},this.userProperties),t),c().debug("Usermaven user identified",t),this.userIdPersistence?this.userIdPersistence.save(t):c().warn("Id() is called before initialization"),n?Promise.resolve():this.track("user_identify",{})},r.prototype.rawTrack=function(e){return this.sendJson(e)},r.prototype.makeEvent=function(t,n,r){var o,a=r.env,s=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(r,["env"]);a||(a=i()?he():fe()),this.restoreId();var c=this.getCtx(a),u=e(e({},this.permanentProperties.globalProps),null!==(o=this.permanentProperties.propsPerEvent[t])&&void 0!==o?o:{}),l=e({api_key:this.apiKey,src:n,event_type:t},s),p=a.getSourceIp();return p&&(l.source_ip=p),this.compatMode?e(e(e({},u),{eventn_ctx:c}),l):e(e(e({},u),c),l)},r.prototype._send3p=function(e,t,n){var r="3rdparty";n&&""!==n&&(r=n);var i=this.makeEvent(r,e,{src_payload:t});return this.sendJson(i)},r.prototype.sendJson=function(e){return t(this,void 0,Promise,(function(){return n(this,(function(t){switch(t.label){case 0:return this.maxSendAttempts>1?(this.queue.push([e,0]),this.scheduleFlush(0),[3,3]):[3,1];case 1:return[4,this.doSendJson(e)];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))},r.prototype.doSendJson=function(e){var t=this,n="keep"!==this.cookiePolicy?"&cookie_policy=".concat(this.cookiePolicy):"",r="keep"!==this.ipPolicy?"&ip_policy=".concat(this.ipPolicy):"",o=i()?"/api/v1/event":"/api/v1/s2s/event",a="".concat(this.trackingHost).concat(o,"?token=").concat(this.apiKey).concat(n).concat(r);this.randomizeUrl&&(a="".concat(this.trackingHost,"/api.").concat(_(),"?p_").concat(_(),"=").concat(this.apiKey).concat(n).concat(r));var s=JSON.stringify(e);return c().debug("Sending payload to ".concat(a),s),this.transport(a,s,this.customHeaders(),(function(e,n){return t.postHandle(e,n)}))},r.prototype.scheduleFlush=function(e){var t=this;if(!this.flushing){if(this.flushing=!0,void 0===e){var n=Math.random()+1,r=Math.pow(2,this.attempt++);e=Math.min(this.retryTimeout[0]*n*r,this.retryTimeout[1])}c().debug("Scheduling event queue flush in ".concat(e," ms.")),setTimeout((function(){return t.flush()}),e)}},r.prototype.flush=function(){return t(this,void 0,Promise,(function(){var e,t,r=this;return n(this,(function(n){switch(n.label){case 0:if(i()&&!window.navigator.onLine&&(this.flushing=!1,this.scheduleFlush()),e=this.queue.flush(),this.flushing=!1,0===e.length)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.doSendJson(e.map((function(e){return e[0]})))];case 2:return n.sent(),this.attempt=1,c().debug("Successfully flushed ".concat(e.length," events from queue")),[3,4];case 3:return n.sent(),(e=e.map((function(e){return[e[0],e[1]+1]})).filter((function(e){return!(e[1]>=r.maxSendAttempts)||(c().error("Dropping queued event after ".concat(e[1]," attempts since max send attempts ").concat(r.maxSendAttempts," reached. See logs for details")),!1)}))).length>0?((t=this.queue).push.apply(t,e),this.scheduleFlush()):this.attempt=1,[3,4];case 4:return[2]}}))}))},r.prototype.postHandle=function(e,t){if("strict"===this.cookiePolicy||"comply"===this.cookiePolicy){if(200===e){var n=t;if("string"==typeof t&&(n=JSON.parse(t)),!n.delete_cookie)return}this.userIdPersistence.delete(),this.propsPersistance.delete(),g(this.idCookieName)}if(200===e){n=t;if("string"==typeof t&&t.length>0){var r=(n=JSON.parse(t)).jitsu_sdk_extras;if(r&&r.length>0)if(i())for(var o=0,a=r;o<a.length;o++){var s=a[o],u=s.type,l=s.id,p=s.value;if("tag"===u){var d=document.createElement("div");d.id=l,f(d,p),d.childElementCount>0&&document.body.appendChild(d)}}else c().error("Tags destination supported only in browser environment")}}},r.prototype.getCtx=function(t){var n=new Date,r=t.describeClient()||{},i=this.userProperties.company||{};delete this.userProperties.company;var o,a,s=e(e({event_id:"",user:e({anonymous_id:"strict"!==this.cookiePolicy?t.getAnonymousId({name:this.idCookieName,domain:this.cookieDomain}):""},this.userProperties),ids:this._getIds(),utc_time:(o=n.toISOString(),a=o.split(".")[1],a?a.length>=7?o:o.slice(0,-1)+"0".repeat(7-a.length)+"Z":o),local_tz_offset:n.getTimezoneOffset()},r),function(e){var t={utm:{},click_id:{}};for(var n in e)if(e.hasOwnProperty(n)){var r=e[n],i=b[n];i?t.utm[i]=r:w[n]&&(t.click_id[n]=r)}return t}(function(e){if(!e)return{};for(var t=e.length>0&&"?"===e.charAt(0)?e.substring(1):e,n={},r=("?"===t[0]?t.substr(1):t).split("&"),i=0;i<r.length;i++){var o=r[i].split("=");n[decodeURIComponent(o[0])]=decodeURIComponent(o[1]||"")}return n}(r.doc_search)));return Object.keys(i).length&&(s.company=i),s},r.prototype._getIds=function(){if(!i())return{};for(var e=function(e){if(void 0===e&&(e=!1),e&&p)return p;var t=d(document.cookie);return p=t,t}(!1),t={},n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],a=o[0],s=o[1];this._3pCookies[a]&&(t["_"==a.charAt(0)?a.substr(1):a]=s)}return t},r.prototype.pathMatches=function(e,t){return new URL(t).pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))},r.prototype.track=function(e,t){var n=this,r=t||{};c().debug("track event of type",e,r);var o=i()?he():fe(),a=this.getCtx(o);if(this.config&&this.config.exclude&&this.config.exclude.length>1&&(null==a?void 0:a.url)&&this.config.exclude.split(",").some((function(e){return n.pathMatches(e.trim(),null==a?void 0:a.url)})))return void c().debug("Page is excluded from tracking");var s=this.makeEvent(e,this.compatMode?"eventn":"usermaven",t||{});return this.sendJson(s)},r.prototype.init=function(r){var o,l,p,d,h,f,m,v=this;if(i()&&!r.force_use_fetch)r.fetch&&c().warn("Custom fetch implementation is provided to Usermaven. However, it will be ignored since Usermaven runs in browser"),this.transport=this.beaconApi?ae:me;else{if(!r.fetch&&!globalThis.fetch)throw new Error("Usermaven runs in Node environment. However, neither UsermavenOptions.fetch is provided, nor global fetch function is defined. \nPlease, provide custom fetch implementation. You can get it via node-fetch package");this.transport=(h=r.fetch||globalThis.fetch,function(r,i,o,a){return void 0===a&&(a=function(e,t){}),t(void 0,void 0,void 0,(function(){var t,s,u,l,p,d,f,m;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,h(r,{method:"POST",headers:e({Accept:"application/json","Content-Type":"application/json"},o||{}),body:i})];case 1:return t=n.sent(),[3,3];case 2:return s=n.sent(),c().error("Failed to send",i,s),a(-1,{}),[2];case 3:if(200!==t.status)return c().warn("Failed to send data to ".concat(r," (#").concat(t.status," - ").concat(t.statusText,")"),i),a(t.status,{}),[2];u={},l="",p=null!==(m=null===(f=t.headers)||void 0===f?void 0:f.get("Content-Type"))&&void 0!==m?m:"",n.label=4;case 4:return n.trys.push([4,6,,7]),[4,t.text()];case 5:return l=n.sent(),u=JSON.parse(l),[3,7];case 6:return d=n.sent(),c().error("Failed to parse ".concat(r," response. Content-type: ").concat(p," text: ").concat(l),d),[3,7];case 7:try{a(t.status,u)}catch(e){c().error("Failed to handle ".concat(r," response. Content-type: ").concat(p," text: ").concat(l),e)}return[2]}}))}))})}if(r.custom_headers&&"function"==typeof r.custom_headers?this.customHeaders=r.custom_headers:r.custom_headers&&(this.customHeaders=function(){return r.custom_headers}),"echo"===r.tracking_host&&(c().warn('jitsuClient is configured with "echo" transport. Outgoing requests will be written to console'),this.transport=se),r.ip_policy&&(this.ipPolicy=r.ip_policy),r.cookie_policy&&(this.cookiePolicy=r.cookie_policy),"strict"===r.privacy_policy&&(this.ipPolicy="strict",this.cookiePolicy="strict"),r.use_beacon_api&&navigator.sendBeacon&&(this.beaconApi=!0),"comply"===this.cookiePolicy&&this.beaconApi&&(this.cookiePolicy="strict"),r.log_level&&(f=r.log_level,(m=a[f.toLocaleUpperCase()])||(console.warn("Can't find log level with name ".concat(f.toLocaleUpperCase(),", defaulting to INFO")),m=a.INFO),s=u(m)),this.initialOptions=r,c().debug("Initializing Usemaven Tracker tracker",r,ie),r.key){if(this.compatMode=void 0!==r.compat_mode&&!!r.compat_mode,this.cookieDomain=r.cookie_domain||function(){if(i())return".".concat((e=location.hostname,t=function(e){return(e.indexOf("//")>-1?e.split("/")[2]:e.split("/")[0]).split(":")[0].split("?")[0]}(e),n=t.split("."),(r=n.length)>2&&(t=n[r-2]+"."+n[r-1],2==n[r-2].length&&2==n[r-1].length&&(t=n[r-3]+"."+t)),t));var e,t,n,r}(),this.trackingHost=function(e){for(;n="/",-1!==(t=e).indexOf(n,t.length-n.length);)e=e.substr(0,e.length-1);var t,n;return 0===e.indexOf("https://")||0===e.indexOf("http://")?e:"//"+e}(r.tracking_host||"t.usermaven.com"),this.randomizeUrl=r.randomize_url||!1,this.idCookieName=r.cookie_name||"__eventn_id",this.apiKey=r.key,"strict"===this.cookiePolicy?this.propsPersistance=new le:this.propsPersistance=i()?new ue(this.cookieDomain,this.idCookieName+"_props"):new le,"strict"===this.cookiePolicy?this.userIdPersistence=new le:this.userIdPersistence=i()?new ue(this.cookieDomain,this.idCookieName+"_usr"):new le,this.propsPersistance){var g=this.propsPersistance.restore();g&&(this.permanentProperties=g,this.permanentProperties.globalProps=null!==(o=g.globalProps)&&void 0!==o?o:{},this.permanentProperties.propsPerEvent=null!==(l=g.propsPerEvent)&&void 0!==l?l:{}),c().debug("Restored persistent properties",this.permanentProperties)}this.propertyBlacklist=r.property_blacklist&&r.property_blacklist.length>0?r.property_blacklist:[];this.config=$({},{autocapture:!1,properties_string_max_length:null,property_blacklist:[],sanitize_properties:null},r||{},this.config||{},{token:this.apiKey}),c().debug("Default Configuration",this.config),this.manageAutoCapture(this.config),!1===r.capture_3rd_party_cookies?this._3pCookies={}:(r.capture_3rd_party_cookies||["_ga","_fbp","_ym_uid","ajs_user_id","ajs_anonymous_id"]).forEach((function(e){return v._3pCookies[e]=!0})),r.ga_hook&&c().warn("GA event interceptor isn't supported anymore"),r.segment_hook&&function(e){var t=window;t.analytics||(t.analytics=[]);e.interceptAnalytics(t.analytics)}(this),i()&&(r.disable_event_persistence||(this.queue=new P("jitsu-event-queue"),this.scheduleFlush(0)),window.addEventListener("beforeunload",(function(){return v.flush()}))),this.retryTimeout=[null!==(p=r.min_send_timeout)&&void 0!==p?p:this.retryTimeout[0],null!==(d=r.max_send_timeout)&&void 0!==d?d:this.retryTimeout[1]],r.max_send_attempts&&(this.maxSendAttempts=r.max_send_attempts),this.initialized=!0}else c().error("Can't initialize Usemaven, key property is not set")},r.prototype.interceptAnalytics=function(t){var n=this,r=function(t){var r;try{var i=e({},t.payload);c().debug("Intercepted segment payload",i.obj);var o=t.integrations["Segment.io"];if(o&&o.analytics){var a=o.analytics;"function"==typeof a.user&&a.user()&&"function"==typeof a.user().id&&(i.obj.userId=a.user().id())}(null===(r=null==i?void 0:i.obj)||void 0===r?void 0:r.timestamp)&&(i.obj.sentAt=i.obj.timestamp);var s=t.payload.type();"track"===s&&(s=t.payload.event()),n._send3p("ajs",i,s)}catch(e){c().warn("Failed to send an event",e)}t.next(t.payload)};"function"==typeof t.addSourceMiddleware?(c().debug("Analytics.js is initialized, calling addSourceMiddleware"),t.addSourceMiddleware(r)):(c().debug("Analytics.js is not initialized, pushing addSourceMiddleware to callstack"),t.push(["addSourceMiddleware",r])),t.__en_intercepted=!0},r.prototype.restoreId=function(){if(this.userIdPersistence){var t=this.userIdPersistence.restore();t&&(this.userProperties=e(e({},t),this.userProperties))}},r.prototype.set=function(t,n){var r,i=null==n?void 0:n.eventType,o=void 0===(null==n?void 0:n.persist)||(null==n?void 0:n.persist);if(void 0!==i){var a=null!==(r=this.permanentProperties.propsPerEvent[i])&&void 0!==r?r:{};this.permanentProperties.propsPerEvent[i]=e(e({},a),t)}else this.permanentProperties.globalProps=e(e({},this.permanentProperties.globalProps),t);this.propsPersistance&&o&&this.propsPersistance.save(this.permanentProperties)},r.prototype.unset=function(e,t){o();var n=null==t?void 0:t.eventType,r=void 0===(null==t?void 0:t.persist)||(null==t?void 0:t.persist);n?this.permanentProperties.propsPerEvent[n]&&delete this.permanentProperties.propsPerEvent[n][e]:delete this.permanentProperties.globalProps[e],this.propsPersistance&&r&&this.propsPersistance.save(this.permanentProperties)},r.prototype.manageAutoCapture=function(e){if(c().debug("Auto Capture Status: ",this.config.autocapture),this.__autocapture_enabled=this.config.autocapture,this.__autocapture_enabled){te.enabledForProject(this.apiKey,100,100)?te.isBrowserSupported()?(c().debug("Autocapture enabled..."),te.init(this,e)):(this.config.autocapture=!1,this.__autocapture_enabled=!1,c().debug("Disabling Automatic Event Collection because this browser is not supported")):(this.config.autocapture=!1,this.__autocapture_enabled=!1,c().debug("Not in active bucket: disabling Automatic Event Collection."))}},r.prototype.capture=function(e,t){var n,r;if(void 0===t&&(t={}),this.initialized)if(D(e)||"string"!=typeof e)console.error("No event name provided to usermaven.capture");else{var i={event:e+(t.$event_type?"_"+t.$event_type:""),properties:this._calculate_event_properties(e,t)};(null===(r=null===(n=(i=q(i,this.get_config("properties_string_max_length"))).properties)||void 0===n?void 0:n.autocapture_attributes)||void 0===r?void 0:r.tag_name)&&this.track("$autocapture",i.properties)}else console.error("Trying to capture event before initialization")},r.prototype._calculate_event_properties=function(e,t){var n,r,i=t||{};if("$snapshot"===e)return i;O(this.propertyBlacklist)?j(this.propertyBlacklist,(function(e){delete i[e]})):console.error("Invalid value for property_blacklist config: "+this.propertyBlacklist);var o={},a=i.$elements||[];return a.length&&(o=a[0]),i.autocapture_attributes=o,i.autocapture_attributes.el_text=null!==(n=i.autocapture_attributes.$el_text)&&void 0!==n?n:"",i.autocapture_attributes.event_type=null!==(r=i.$event_type)&&void 0!==r?r:"",["$ce_version","$event_type","$initial_referrer","$initial_referring_domain","$referrer","$referring_domain","$elements"].forEach((function(e){delete i[e]})),delete i.autocapture_attributes.$el_text,delete i.autocapture_attributes.nth_child,delete i.autocapture_attributes.nth_of_type,i},r}();var ge=["use_beacon_api","cookie_domain","tracking_host","cookie_name","key","ga_hook","segment_hook","randomize_url","capture_3rd_party_cookies","id_method","log_level","compat_mode","privacy_policy","cookie_policy","ip_policy","custom_headers","force_use_fetch","min_send_timeout","max_send_timeout","max_send_attempts","disable_event_persistence","project_id","autocapture","properties_string_max_length","property_blacklist","exclude"];var ye="data-suppress-interception-warning";function _e(e){return"\n ATTENTION! ".concat(e,"-hook set to true along with defer/async attribute! If ").concat(e," code is inserted right after Usermaven tag,\n first tracking call might not be intercepted! Consider one of the following:\n - Inject usermaven tracking code without defer/async attribute\n - If you're sure that events won't be sent to ").concat(e," before Usermaven is fully initialized, set ").concat(ye,'="true"\n script attribute\n ')}function be(e,t){c().debug("Processing queue",e);for(var n=0;n<e.length;n+=1){var i=r([],e[n],!0)||[],o=i[0],a=i.slice(1),s=t[o];"function"==typeof s&&s.apply(t,a)}e.length=0}if(window){var we=window,ke=function(e){var t=document.currentScript||document.querySelector("script[src*=jsFileName][data-usermaven-api-key]");if(t){var n,r={tracking_host:(n=t.getAttribute("src"),n.replace("/s/lib.js","").replace("/lib.js","")),key:null};ge.forEach((function(e){var n="data-"+e.replace(new RegExp("_","g"),"-");if(void 0!==t.getAttribute(n)&&null!==t.getAttribute(n)){var i=t.getAttribute(n);"true"===i?i=!0:"false"===i&&(i=!1),r[e]=i}})),e.usermavenClient=function(e){var t=new ve;return t.init(e),t}(r),!r.segment_hook||null===t.getAttribute("defer")&&null===t.getAttribute("async")||null!==t.getAttribute(ye)||c().warn(_e("segment")),!r.ga_hook||null===t.getAttribute("defer")&&null===t.getAttribute("async")||null!==t.getAttribute(ye)||c().warn(_e("ga"));var i=function(){var t=e.usermavenQ=e.usermavenQ||[];t.push(arguments),be(t,e.usermavenClient)};return e.usermaven=i,r.project_id&&i("set",{project_id:r.project_id}),"true"!==t.getAttribute("data-init-only")&&"yes"!==t.getAttribute("data-init-only")&&i("track","pageview"),e.usermavenClient}c().warn("Usermaven script is not properly initialized. The definition must contain data-usermaven-api-key as a parameter")}(we);ke?(c().debug("Usermaven in-browser tracker has been initialized"),we.usermaven=function(){var e=we.usermavenQ=we.usermavenQ||[];e.push(arguments),be(e,ke)},we.usermavenQ&&(c().debug("Initial queue size of ".concat(we.usermavenQ.length," will be processed")),be(we.usermavenQ,ke))):c().error("Usermaven tracker has not been initialized (reason unknown)")}else c().warn("Usermaven tracker called outside browser context. It will be ignored")}();
1
+ !function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function r(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}function i(e){let t=!!globalThis.window;return!t&&e&&c().warn(e),t}function o(e){if(!i())throw new Error(e||"window' is not available. Seems like this code runs outside browser environment. It shouldn't happen");return window}var s={DEBUG:{name:"DEBUG",severity:10},INFO:{name:"INFO",severity:100},WARN:{name:"WARN",severity:1e3},ERROR:{name:"ERROR",severity:1e4},NONE:{name:"NONE",severity:1e4}},a=null;function c(){return a||(a=u())}function u(e){var t=i()&&window.__eventNLogLevel,n=s.WARN;if(t){var o=s[t.toUpperCase()];o&&o>0&&(n=o)}else e&&(n=e);var a={minLogLevel:n};return Object.values(s).forEach((function(e){var t=e.name,i=e.severity;a[t.toLowerCase()]=function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];if(i>=n.severity&&e.length>0){var s=e[0],a=e.splice(1),c="[J-".concat(t,"] ").concat(s);"DEBUG"===t||"INFO"===t?console.log.apply(console,r([c],a,!1)):"WARN"===t?console.warn.apply(console,r([c],a,!1)):console.error.apply(console,r([c],a,!1))}}})),function(e,t){if(i()){var n=window;n.__usermavenDebug||(n.__usermavenDebug={}),n.__usermavenDebug[e]=t}}("logger",a),a}function l(e,t,n){var r;void 0===n&&(n={});var i=e+"="+encodeURIComponent(t);if(i+="; Path="+(null!==(r=n.path)&&void 0!==r?r:"/"),n.maxAge&&(i+="; Max-Age="+Math.floor(n.maxAge)),n.domain&&(i+="; Domain="+n.domain),n.expires&&(i+="; Expires="+n.expires.toUTCString()),n.httpOnly&&(i+="; HttpOnly"),n.secure&&(i+="; Secure"),n.sameSite)switch("string"==typeof n.sameSite?n.sameSite.toLowerCase():n.sameSite){case!0:i+="; SameSite=Strict";break;case"lax":i+="; SameSite=Lax";break;case"strict":i+="; SameSite=Strict";break;case"none":i+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return i}var p;function d(e){if(!e)return{};for(var t={},n=e.split(";"),r=0;r<n.length;r++){var i=n[r],o=i.indexOf("=");o>0&&(t[i.substr(r>0?1:0,r>0?o-1:o)]=i.substr(o+1))}return t}function h(e,t){return Array.from(e.attributes).forEach((function(e){t.setAttribute(e.nodeName,e.nodeValue)}))}function f(e,t){e.innerHTML=t;var n,r=e.getElementsByTagName("script");for(n=r.length-1;n>=0;n--){var i=r[n],o=document.createElement("script");h(i,o),i.innerHTML&&(o.innerHTML=i.innerHTML),o.setAttribute("data-usermaven-tag-id",e.id),document.getElementsByTagName("head")[0].appendChild(o),r[n].parentNode.removeChild(r[n])}}var m=function(e){if(!e)return null;try{for(var t=e+"=",n=o().document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "==i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return decodeURIComponent(i.substring(t.length,i.length))}}catch(e){}return null},v=function(e,t,n){void 0===n&&(n={}),o().document.cookie=l(e,t,n)},g=function(e,t){void 0===t&&(t="/"),document.cookie=e+"= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"+(t?"; path = "+t:"")},y=function(){return Math.random().toString(36).substring(2,12)},_=function(){return Math.random().toString(36).substring(2,7)},b={utm_source:"source",utm_medium:"medium",utm_campaign:"campaign",utm_term:"term",utm_content:"content"},w={gclid:!0,fbclid:!0,dclid:!0};var k=function(){function e(){this.queue=[]}return e.prototype.flush=function(){var e=this.queue;return this.queue=[],e},e.prototype.push=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=this.queue).push.apply(e,t)},e}(),P=function(){function e(e){this.key=e}return e.prototype.flush=function(){var e=this.get();return e.length&&this.set([]),e},e.prototype.push=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this.get();n.push.apply(n,e),this.set(n)},e.prototype.set=function(e){localStorage.setItem(this.key,JSON.stringify(e))},e.prototype.get=function(){var e=localStorage.getItem(this.key);return null!==e&&""!==e?JSON.parse(e):[]},e}(),S=Object.prototype,x=S.toString,N=S.hasOwnProperty,A=Array.prototype.forEach,E=Array.isArray,C={},O=E||function(e){return"[object Array]"===x.call(e)};function T(e,t,n){if(Array.isArray(e))if(A&&e.forEach===A)e.forEach(t,n);else if("length"in e&&e.length===+e.length)for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r)===C)return}var I=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function j(e,t,n){if(null!=e)if(A&&Array.isArray(e)&&e.forEach===A)e.forEach(t,n);else if("length"in e&&e.length===+e.length){for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r)===C)return}else for(var o in e)if(N.call(e,o)&&t.call(n,e[o],o)===C)return}var D=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return T(t,(function(t){for(var n in t)void 0!==t[n]&&(e[n]=t[n])})),e};function H(e,t){return-1!==e.indexOf(t)}var $=function(e){try{return/^\s*\bfunction\b/.test(e)}catch(e){return!1}},F=function(e){return void 0===e},M=function(){function e(t){return t&&(t.preventDefault=e.preventDefault,t.stopPropagation=e.stopPropagation),t}return e.preventDefault=function(){this.returnValue=!1},e.stopPropagation=function(){this.cancelBubble=!0},function(t,n,r,i,o){if(t)if(t.addEventListener&&!i)t.addEventListener(n,r,!!o);else{var s="on"+n,a=t[s];t[s]=function(t,n,r){return function(i){if(i=i||e(window.event)){var o,s=!0;$(r)&&(o=r(i));var a=n.call(t,i);return!1!==o&&!1!==a||(s=!1),s}}}(t,r,a)}else c().error("No valid element provided to register_event")}}(),U=function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return e.apply(this,t)}catch(e){c().error("Implementation error. Please turn on debug and contact support@usermaven.com.",e)}}},L="undefined"!=typeof Symbol?Symbol("__deepCircularCopyInProgress__"):"__deepCircularCopyInProgress__";function z(e,t,n){return e!==Object(e)?t?t(e,n):e:e[L]?void 0:(e[L]=!0,O(e)?(r=[],T(e,(function(e){r.push(z(e,t))}))):(r={},j(e,(function(e,n){n!==L&&(r[n]=z(e,t,n))}))),delete e[L],r);var r}var q=["$performance_raw"];function J(e,t){return z(e,(function(e,n){return n&&q.indexOf(n)>-1?e:"string"==typeof e&&null!==t?e.slice(0,t):e}))}function R(e){switch(typeof e.className){case"string":return e.className;case"object":return("baseVal"in e.className?e.className.baseVal:null)||e.getAttribute("class")||"";default:return""}}function B(e){var t="";return Y(e)&&!X(e)&&e.childNodes&&e.childNodes.length&&j(e.childNodes,(function(e){K(e)&&e.textContent&&(t+=I(e.textContent).split(/(\s+)/).filter(Z).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))})),I(t)}function V(e){return!!e&&1===e.nodeType}function W(e,t){return!!e&&!!e.tagName&&e.tagName.toLowerCase()===t.toLowerCase()}function K(e){return!!e&&3===e.nodeType}function Q(e){return!!e&&11===e.nodeType}var G=["a","button","form","input","select","textarea","label"];function Y(e){for(var t=e;t.parentNode&&!W(t,"body");t=t.parentNode){var n=R(t).split(" ");if(H(n,"ph-sensitive")||H(n,"ph-no-capture"))return!1}if(H(R(e).split(" "),"ph-include"))return!0;var r=e.type||"";if("string"==typeof r)switch(r.toLowerCase()){case"hidden":case"password":return!1}var i=e.name||e.id||"";if("string"==typeof i){if(/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(i.replace(/[^a-zA-Z0-9]/g,"")))return!1}return!0}function X(e){return!!(W(e,"input")&&!["button","checkbox","submit","reset"].includes(e.type)||W(e,"select")||W(e,"textarea")||"true"===e.getAttribute("contenteditable"))}function Z(e){if(null===e||F(e))return!1;if("string"==typeof e){e=I(e);if(/^(?:(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}))$/.test((e||"").replace(/[- ]/g,"")))return!1;if(/(^\d{3}-?\d{2}-?\d{4}$)/.test(e))return!1}return!0}var ee=function(){function e(e,t){void 0===t&&(t=!1),this.clicks=[],this.instance=e,this.enabled=t}return e.prototype.click=function(e,t,n){if(this.enabled){var r=this.clicks[this.clicks.length-1];r&&Math.abs(e-r.x)+Math.abs(t-r.y)<30&&n-r.timestamp<1e3?(this.clicks.push({x:e,y:t,timestamp:n}),3===this.clicks.length&&this.instance.capture("$rageclick")):this.clicks=[{x:e,y:t,timestamp:n}]}},e}(),te=function(){function e(e){this.instance=e,this.lastScrollDepth=0,this.canSend=!0,this.documentElement=document.documentElement}return e.prototype.track=function(){var e=this.getScrollDepth();e>this.lastScrollDepth&&(this.lastScrollDepth=e,this.canSend=!0)},e.prototype.send=function(e){if(void 0===e&&(e="$scroll"),this.canSend&&this.lastScrollDepth){var t={percent:this.lastScrollDepth,window_height:this.getWindowHeight(),document_height:this.getDocumentHeight(),scroll_distance:this.getScrollDistance()};this.instance.capture(e,t),this.canSend=!1}},e.prototype.getScrollDepth=function(){try{var e=this.getWindowHeight(),t=this.getDocumentHeight(),n=this.getScrollDistance(),r=t-e;return Math.floor(n/r*100)}catch(e){return 0}},e.prototype.getWindowHeight=function(){try{return window.innerHeight||this.documentElement.clientHeight||document.body.clientHeight||0}catch(e){return 0}},e.prototype.getDocumentHeight=function(){try{return Math.max(document.body.scrollHeight||0,this.documentElement.scrollHeight||0,document.body.offsetHeight||0,this.documentElement.offsetHeight||0,document.body.clientHeight||0,this.documentElement.clientHeight||0)}catch(e){return 0}},e.prototype.getScrollDistance=function(){try{return window.scrollY||window.pageYOffset||document.body.scrollTop||this.documentElement.scrollTop||0}catch(e){return 0}},e}(),ne={_initializedTokens:[],_previousElementSibling:function(e){if(e.previousElementSibling)return e.previousElementSibling;var t=e;do{t=t.previousSibling}while(t&&!V(t));return t},_getPropertiesFromElement:function(e,t,n){var r=e.tagName.toLowerCase(),i={tag_name:r};G.indexOf(r)>-1&&!n&&(i.$el_text=B(e));var o=R(e);o.length>0&&(i.classes=o.split(" ").filter((function(e){return""!==e}))),j(e.attributes,(function(n){var r;X(e)&&-1===["name","id","class"].indexOf(n.name)||!t&&Z(n.value)&&("string"!=typeof(r=n.name)||"_ngcontent"!==r.substring(0,10)&&"_nghost"!==r.substring(0,7))&&(i["attr__"+n.name]=n.value)}));for(var s=1,a=1,c=e;c=this._previousElementSibling(c);)s++,c.tagName===e.tagName&&a++;return i.nth_child=s,i.nth_of_type=a,i},_getDefaultProperties:function(e){return{$event_type:e,$ce_version:1}},_extractCustomPropertyValue:function(e){var t=[];return j(document.querySelectorAll(e.css_selector),(function(e){var n;["input","select"].indexOf(e.tagName.toLowerCase())>-1?n=e.value:e.textContent&&(n=e.textContent),Z(n)&&t.push(n)})),t.join(", ")},_getCustomProperties:function(e){var t=this,n={};return j(this._customProperties,(function(r){j(r.event_selectors,(function(i){j(document.querySelectorAll(i),(function(i){H(e,i)&&Y(i)&&(n[r.name]=t._extractCustomPropertyValue(r))}))}))})),n},_getEventTarget:function(e){var t;return void 0===e.target?e.srcElement||null:(null===(t=e.target)||void 0===t?void 0:t.shadowRoot)?e.composedPath()[0]||null:e.target||null},_captureEvent:function(e,t,n){var r,i=this,o=this._getEventTarget(e);if(K(o)&&(o=o.parentNode||null),"scroll"===e.type)return this.scrollDepth.track(),!0;if("visibilitychange"===e.type&&"hidden"===document.visibilityState||"popstate"===e.type)return this.scrollDepth.send(),!0;if("click"===e.type&&e instanceof MouseEvent&&(null===(r=this.rageclicks)||void 0===r||r.click(e.clientX,e.clientY,(new Date).getTime())),o&&function(e,t){if(!e||W(e,"html")||!V(e))return!1;for(var n=!1,r=[e],i=!0,o=e;o.parentNode&&!W(o,"body");)if(Q(o.parentNode))r.push(o.parentNode.host),o=o.parentNode.host;else{if(!(i=o.parentNode||!1))break;if(G.indexOf(i.tagName.toLowerCase())>-1)n=!0;else{var s=window.getComputedStyle(i);s&&"pointer"===s.getPropertyValue("cursor")&&(n=!0)}r.push(i),o=i}var a=window.getComputedStyle(e);if(a&&"pointer"===a.getPropertyValue("cursor")&&"click"===t.type)return!0;var c=e.tagName.toLowerCase();switch(c){case"html":return!1;case"form":return"submit"===t.type;case"input":case"select":case"textarea":return"change"===t.type||"click"===t.type;default:return n?"click"===t.type:"click"===t.type&&(G.indexOf(c)>-1||"true"===e.getAttribute("contenteditable"))}}(o,e)){for(var s=[o],a=o;a.parentNode&&!W(a,"body");)Q(a.parentNode)?(s.push(a.parentNode.host),a=a.parentNode.host):(s.push(a.parentNode),a=a.parentNode);var c,u=[],l=!1;if(j(s,(function(e){var t=Y(e);"a"===e.tagName.toLowerCase()&&(c=e.getAttribute("href"),c=t&&Z(c)&&c),H(R(e).split(" "),"ph-no-capture")&&(l=!0),u.push(i._getPropertiesFromElement(e,null==n?void 0:n.mask_all_element_attributes,null==n?void 0:n.mask_all_text))})),(null==n?void 0:n.mask_all_text)||(u[0].$el_text=B(o)),c&&(u[0].attr__href=c),l)return!1;var p=D(this._getDefaultProperties(e.type),{$elements:u},this._getCustomProperties(s));return t.capture("$autocapture",p),!0}},_navigate:function(e){window.location.href=e},_addDomEventHandlers:function(e,t){var n=this,r=function(r){r=r||window.event,n._captureEvent(r,e,t)};M(document,"submit",r,!1,!0),M(document,"change",r,!1,!0),M(document,"click",r,!1,!0),M(document,"visibilitychange",r,!1,!0),M(document,"scroll",r,!1,!0),M(window,"popstate",r,!1,!0)},_customProperties:[],rageclicks:null,scrollDepth:null,opts:{},init:function(e,t){var n=this;if(this.rageclicks=new ee(e),this.scrollDepth=new te(e),this.opts=t,!document||!document.body)return console.debug("document not ready yet, trying again in 500 milliseconds..."),void setTimeout((function(){n.readyAutocapture(e,t)}),500);this.readyAutocapture(e,t)},readyAutocapture:function(e,t){this._addDomEventHandlers(e,t)},enabledForProject:function(e,t,n){if(!e)return!0;t=F(t)?10:t,n=F(n)?10:n;for(var r=0,i=0;i<e.length;i++)r+=e.charCodeAt(i);return r%t<n},isBrowserSupported:function(){return $(document.querySelectorAll)}};!function(e){for(var t in e)"function"==typeof e[t]&&(e[t]=e[t].bind(e))}(ne),function(e){for(var t in e)"function"==typeof e[t]&&(e[t]=U(e[t]))}(ne);var re="__buildEnv__",ie="__buildDate__",oe="".concat("__buildVersion__","/").concat(re,"@").concat(ie),se=316224e3,ae=function(e,t){c().debug("Sending beacon",t);var n=new Blob([t],{type:"text/plain"});return navigator.sendBeacon(e,n),Promise.resolve()};var ce=function(e,t){return console.debug("Jitsu client tried to send payload to ".concat(e),function(e){if("string"==typeof e)try{return JSON.stringify(JSON.parse(e),null,2)}catch(t){return e}}(t)),Promise.resolve()};function ue(e,t){void 0===t&&(t=void 0),""!=(t=null!=t?t:window.location.pathname)&&"/"!=t&&(g(e,t),ue(e,t.slice(0,t.lastIndexOf("/"))))}var le=function(){function e(e,t){this.cookieDomain=e,this.cookieName=t}return e.prototype.save=function(e){v(this.cookieName,JSON.stringify(e),{domain:this.cookieDomain,secure:"http:"!==document.location.protocol,maxAge:se})},e.prototype.restore=function(){ue(this.cookieName);var e=m(this.cookieName);if(e)try{var t=JSON.parse(decodeURIComponent(e));return"object"!=typeof t?void c().warn("Can't restore value of ".concat(this.cookieName,"@").concat(this.cookieDomain,", expected to be object, but found ").concat("object"!=typeof t,": ").concat(t,". Ignoring")):t}catch(t){return void c().error("Failed to decode JSON from "+e,t)}},e.prototype.delete=function(){g(this.cookieName)},e}(),pe=function(){function e(){}return e.prototype.save=function(e){},e.prototype.restore=function(){},e.prototype.delete=function(){},e}();var de={getSourceIp:function(){},describeClient:function(){return{referer:document.referrer,url:window.location.href,page_title:document.title,doc_path:document.location.pathname,doc_host:document.location.hostname,doc_search:window.location.search,screen_resolution:screen.width+"x"+screen.height,vp_size:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)+"x"+Math.max(document.documentElement.clientHeight||0,window.innerHeight||0),user_agent:navigator.userAgent,user_language:navigator.language,doc_encoding:document.characterSet}},getAnonymousId:function(e){var t=e.name,n=e.domain;ue(t);var r=m(t);if(r)return c().debug("Existing user id",r),r;var i=y();return c().debug("New user id",i),v(t,i,{domain:n,secure:"http:"!==document.location.protocol,maxAge:se}),i}};var he={getSourceIp:function(){},describeClient:function(){return{}},getAnonymousId:function(){return""}},fe=function(){return de},me=function(){return he},ve=function(e,t,n,r){void 0===r&&(r=function(e,t){});var i=new window.XMLHttpRequest;return new Promise((function(o,s){i.onerror=function(e){c().error("Failed to send",t,e),r(-1,{}),s(new Error("Failed to send JSON. See console logs"))},i.onload=function(){200!==i.status?(r(i.status,{}),c().warn("Failed to send data to ".concat(e," (#").concat(i.status," - ").concat(i.statusText,")"),t),s(new Error("Failed to send JSON. Error code: ".concat(i.status,". See logs for details")))):r(i.status,i.responseText),o()},i.open("POST",e),i.setRequestHeader("Content-Type","application/json"),Object.entries(n||{}).forEach((function(e){var t=e[0],n=e[1];return i.setRequestHeader(t,n)})),i.send(t),c().debug("sending json",t)}))},ge=function(){function r(){this.userProperties={},this.permanentProperties={globalProps:{},propsPerEvent:{}},this.cookieDomain="",this.trackingHost="",this.idCookieName="",this.randomizeUrl=!1,this.apiKey="",this.initialized=!1,this._3pCookies={},this.cookiePolicy="keep",this.ipPolicy="keep",this.beaconApi=!1,this.transport=ve,this.customHeaders=function(){return{}},this.queue=new k,this.maxSendAttempts=4,this.retryTimeout=[500,1e12],this.flushing=!1,this.attempt=1,this.propertyBlacklist=[],this.__autocapture_enabled=!1}return r.prototype.get_config=function(e){return this.config?this.config[e]:null},r.prototype.id=function(t,n){return this.userProperties=e(e({},this.userProperties),t),c().debug("Usermaven user identified",t),this.userIdPersistence?this.userIdPersistence.save(t):c().warn("Id() is called before initialization"),n?Promise.resolve():this.track("user_identify",{})},r.prototype.rawTrack=function(e){return this.sendJson(e)},r.prototype.makeEvent=function(t,n,r){var o,s=r.env,a=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(r,["env"]);s||(s=i()?fe():me()),this.restoreId();var c=this.getCtx(s),u=e(e({},this.permanentProperties.globalProps),null!==(o=this.permanentProperties.propsPerEvent[t])&&void 0!==o?o:{}),l=e({api_key:this.apiKey,src:n,event_type:t},a),p=s.getSourceIp();return p&&(l.source_ip=p),this.compatMode?e(e(e({},u),{eventn_ctx:c}),l):e(e(e({},u),c),l)},r.prototype._send3p=function(e,t,n){var r="3rdparty";n&&""!==n&&(r=n);var i=this.makeEvent(r,e,{src_payload:t});return this.sendJson(i)},r.prototype.sendJson=function(e){return t(this,void 0,Promise,(function(){return n(this,(function(t){switch(t.label){case 0:return this.maxSendAttempts>1?(this.queue.push([e,0]),this.scheduleFlush(0),[3,3]):[3,1];case 1:return[4,this.doSendJson(e)];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))},r.prototype.doSendJson=function(e){var t=this,n="keep"!==this.cookiePolicy?"&cookie_policy=".concat(this.cookiePolicy):"",r="keep"!==this.ipPolicy?"&ip_policy=".concat(this.ipPolicy):"",o=i()?"/api/v1/event":"/api/v1/s2s/event",s="".concat(this.trackingHost).concat(o,"?token=").concat(this.apiKey).concat(n).concat(r);this.randomizeUrl&&(s="".concat(this.trackingHost,"/api.").concat(_(),"?p_").concat(_(),"=").concat(this.apiKey).concat(n).concat(r));var a=JSON.stringify(e);return c().debug("Sending payload to ".concat(s),a),this.transport(s,a,this.customHeaders(),(function(e,n){return t.postHandle(e,n)}))},r.prototype.scheduleFlush=function(e){var t=this;if(!this.flushing){if(this.flushing=!0,void 0===e){var n=Math.random()+1,r=Math.pow(2,this.attempt++);e=Math.min(this.retryTimeout[0]*n*r,this.retryTimeout[1])}c().debug("Scheduling event queue flush in ".concat(e," ms.")),setTimeout((function(){return t.flush()}),e)}},r.prototype.flush=function(){return t(this,void 0,Promise,(function(){var e,t,r=this;return n(this,(function(n){switch(n.label){case 0:if(i()&&!window.navigator.onLine&&(this.flushing=!1,this.scheduleFlush()),e=this.queue.flush(),this.flushing=!1,0===e.length)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.doSendJson(e.map((function(e){return e[0]})))];case 2:return n.sent(),this.attempt=1,c().debug("Successfully flushed ".concat(e.length," events from queue")),[3,4];case 3:return n.sent(),(e=e.map((function(e){return[e[0],e[1]+1]})).filter((function(e){return!(e[1]>=r.maxSendAttempts)||(c().error("Dropping queued event after ".concat(e[1]," attempts since max send attempts ").concat(r.maxSendAttempts," reached. See logs for details")),!1)}))).length>0?((t=this.queue).push.apply(t,e),this.scheduleFlush()):this.attempt=1,[3,4];case 4:return[2]}}))}))},r.prototype.postHandle=function(e,t){if("strict"===this.cookiePolicy||"comply"===this.cookiePolicy){if(200===e){var n=t;if("string"==typeof t&&(n=JSON.parse(t)),!n.delete_cookie)return}this.userIdPersistence.delete(),this.propsPersistance.delete(),g(this.idCookieName)}if(200===e){n=t;if("string"==typeof t&&t.length>0){var r=(n=JSON.parse(t)).jitsu_sdk_extras;if(r&&r.length>0)if(i())for(var o=0,s=r;o<s.length;o++){var a=s[o],u=a.type,l=a.id,p=a.value;if("tag"===u){var d=document.createElement("div");d.id=l,f(d,p),d.childElementCount>0&&document.body.appendChild(d)}}else c().error("Tags destination supported only in browser environment")}}},r.prototype.getCtx=function(t){var n=new Date,r=t.describeClient()||{},i=this.userProperties.company||{};delete this.userProperties.company;var o,s,a=e(e({event_id:"",user:e({anonymous_id:"strict"!==this.cookiePolicy?t.getAnonymousId({name:this.idCookieName,domain:this.cookieDomain}):""},this.userProperties),ids:this._getIds(),utc_time:(o=n.toISOString(),s=o.split(".")[1],s?s.length>=7?o:o.slice(0,-1)+"0".repeat(7-s.length)+"Z":o),local_tz_offset:n.getTimezoneOffset()},r),function(e){var t={utm:{},click_id:{}};for(var n in e)if(e.hasOwnProperty(n)){var r=e[n],i=b[n];i?t.utm[i]=r:w[n]&&(t.click_id[n]=r)}return t}(function(e){if(!e)return{};for(var t=e.length>0&&"?"===e.charAt(0)?e.substring(1):e,n={},r=("?"===t[0]?t.substr(1):t).split("&"),i=0;i<r.length;i++){var o=r[i].split("=");n[decodeURIComponent(o[0])]=decodeURIComponent(o[1]||"")}return n}(r.doc_search)));return Object.keys(i).length&&(a.company=i),a},r.prototype._getIds=function(){if(!i())return{};for(var e=function(e){if(void 0===e&&(e=!1),e&&p)return p;var t=d(document.cookie);return p=t,t}(!1),t={},n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],s=o[0],a=o[1];this._3pCookies[s]&&(t["_"==s.charAt(0)?s.substr(1):s]=a)}return t},r.prototype.pathMatches=function(e,t){return new URL(t).pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))},r.prototype.track=function(e,t){var n=this,r=t||{};c().debug("track event of type",e,r);var o=i()?fe():me(),s=this.getCtx(o);if(this.config&&this.config.exclude&&this.config.exclude.length>1&&(null==s?void 0:s.url)&&this.config.exclude.split(",").some((function(e){return n.pathMatches(e.trim(),null==s?void 0:s.url)})))return void c().debug("Page is excluded from tracking");var a=t||{};"$autocapture"!==e&&"user_identify"!==e&&"pageview"!==e&&(a={event_attributes:t});var u=this.makeEvent(e,this.compatMode?"eventn":"usermaven",a);return this.sendJson(u)},r.prototype.init=function(r){var o,l,p,d,h,f,m,v=this;if(i()&&!r.force_use_fetch)r.fetch&&c().warn("Custom fetch implementation is provided to Usermaven. However, it will be ignored since Usermaven runs in browser"),this.transport=this.beaconApi?ae:ve;else{if(!r.fetch&&!globalThis.fetch)throw new Error("Usermaven runs in Node environment. However, neither UsermavenOptions.fetch is provided, nor global fetch function is defined. \nPlease, provide custom fetch implementation. You can get it via node-fetch package");this.transport=(h=r.fetch||globalThis.fetch,function(r,i,o,s){return void 0===s&&(s=function(e,t){}),t(void 0,void 0,void 0,(function(){var t,a,u,l,p,d,f,m;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,h(r,{method:"POST",headers:e({Accept:"application/json","Content-Type":"application/json"},o||{}),body:i})];case 1:return t=n.sent(),[3,3];case 2:return a=n.sent(),c().error("Failed to send",i,a),s(-1,{}),[2];case 3:if(200!==t.status)return c().warn("Failed to send data to ".concat(r," (#").concat(t.status," - ").concat(t.statusText,")"),i),s(t.status,{}),[2];u={},l="",p=null!==(m=null===(f=t.headers)||void 0===f?void 0:f.get("Content-Type"))&&void 0!==m?m:"",n.label=4;case 4:return n.trys.push([4,6,,7]),[4,t.text()];case 5:return l=n.sent(),u=JSON.parse(l),[3,7];case 6:return d=n.sent(),c().error("Failed to parse ".concat(r," response. Content-type: ").concat(p," text: ").concat(l),d),[3,7];case 7:try{s(t.status,u)}catch(e){c().error("Failed to handle ".concat(r," response. Content-type: ").concat(p," text: ").concat(l),e)}return[2]}}))}))})}if(r.custom_headers&&"function"==typeof r.custom_headers?this.customHeaders=r.custom_headers:r.custom_headers&&(this.customHeaders=function(){return r.custom_headers}),"echo"===r.tracking_host&&(c().warn('jitsuClient is configured with "echo" transport. Outgoing requests will be written to console'),this.transport=ce),r.ip_policy&&(this.ipPolicy=r.ip_policy),r.cookie_policy&&(this.cookiePolicy=r.cookie_policy),"strict"===r.privacy_policy&&(this.ipPolicy="strict",this.cookiePolicy="strict"),r.use_beacon_api&&navigator.sendBeacon&&(this.beaconApi=!0),"comply"===this.cookiePolicy&&this.beaconApi&&(this.cookiePolicy="strict"),r.log_level&&(f=r.log_level,(m=s[f.toLocaleUpperCase()])||(console.warn("Can't find log level with name ".concat(f.toLocaleUpperCase(),", defaulting to INFO")),m=s.INFO),a=u(m)),this.initialOptions=r,c().debug("Initializing Usemaven Tracker tracker",r,oe),r.key){if(this.compatMode=void 0!==r.compat_mode&&!!r.compat_mode,this.cookieDomain=r.cookie_domain||function(){if(i())return".".concat((e=location.hostname,t=function(e){return(e.indexOf("//")>-1?e.split("/")[2]:e.split("/")[0]).split(":")[0].split("?")[0]}(e),n=t.split("."),(r=n.length)>2&&(t=n[r-2]+"."+n[r-1],2==n[r-2].length&&2==n[r-1].length&&(t=n[r-3]+"."+t)),t));var e,t,n,r}(),this.trackingHost=function(e){for(;n="/",-1!==(t=e).indexOf(n,t.length-n.length);)e=e.substr(0,e.length-1);var t,n;return 0===e.indexOf("https://")||0===e.indexOf("http://")?e:"//"+e}(r.tracking_host||"t.usermaven.com"),this.randomizeUrl=r.randomize_url||!1,this.idCookieName=r.cookie_name||"__eventn_id",this.apiKey=r.key,"strict"===this.cookiePolicy?this.propsPersistance=new pe:this.propsPersistance=i()?new le(this.cookieDomain,this.idCookieName+"_props"):new pe,"strict"===this.cookiePolicy?this.userIdPersistence=new pe:this.userIdPersistence=i()?new le(this.cookieDomain,this.idCookieName+"_usr"):new pe,this.propsPersistance){var g=this.propsPersistance.restore();g&&(this.permanentProperties=g,this.permanentProperties.globalProps=null!==(o=g.globalProps)&&void 0!==o?o:{},this.permanentProperties.propsPerEvent=null!==(l=g.propsPerEvent)&&void 0!==l?l:{}),c().debug("Restored persistent properties",this.permanentProperties)}this.propertyBlacklist=r.property_blacklist&&r.property_blacklist.length>0?r.property_blacklist:[];this.config=D({},{autocapture:!1,properties_string_max_length:null,property_blacklist:[],sanitize_properties:null},r||{},this.config||{},{token:this.apiKey}),c().debug("Default Configuration",this.config),this.manageAutoCapture(this.config),!1===r.capture_3rd_party_cookies?this._3pCookies={}:(r.capture_3rd_party_cookies||["_ga","_fbp","_ym_uid","ajs_user_id","ajs_anonymous_id"]).forEach((function(e){return v._3pCookies[e]=!0})),r.ga_hook&&c().warn("GA event interceptor isn't supported anymore"),r.segment_hook&&function(e){var t=window;t.analytics||(t.analytics=[]);e.interceptAnalytics(t.analytics)}(this),i()&&(r.disable_event_persistence||(this.queue=new P("jitsu-event-queue"),this.scheduleFlush(0)),window.addEventListener("beforeunload",(function(){return v.flush()}))),this.retryTimeout=[null!==(p=r.min_send_timeout)&&void 0!==p?p:this.retryTimeout[0],null!==(d=r.max_send_timeout)&&void 0!==d?d:this.retryTimeout[1]],r.max_send_attempts&&(this.maxSendAttempts=r.max_send_attempts),this.initialized=!0}else c().error("Can't initialize Usemaven, key property is not set")},r.prototype.interceptAnalytics=function(t){var n=this,r=function(t){var r;try{var i=e({},t.payload);c().debug("Intercepted segment payload",i.obj);var o=t.integrations["Segment.io"];if(o&&o.analytics){var s=o.analytics;"function"==typeof s.user&&s.user()&&"function"==typeof s.user().id&&(i.obj.userId=s.user().id())}(null===(r=null==i?void 0:i.obj)||void 0===r?void 0:r.timestamp)&&(i.obj.sentAt=i.obj.timestamp);var a=t.payload.type();"track"===a&&(a=t.payload.event()),n._send3p("ajs",i,a)}catch(e){c().warn("Failed to send an event",e)}t.next(t.payload)};"function"==typeof t.addSourceMiddleware?(c().debug("Analytics.js is initialized, calling addSourceMiddleware"),t.addSourceMiddleware(r)):(c().debug("Analytics.js is not initialized, pushing addSourceMiddleware to callstack"),t.push(["addSourceMiddleware",r])),t.__en_intercepted=!0},r.prototype.restoreId=function(){if(this.userIdPersistence){var t=this.userIdPersistence.restore();t&&(this.userProperties=e(e({},t),this.userProperties))}},r.prototype.set=function(t,n){var r,i=null==n?void 0:n.eventType,o=void 0===(null==n?void 0:n.persist)||(null==n?void 0:n.persist);if(void 0!==i){var s=null!==(r=this.permanentProperties.propsPerEvent[i])&&void 0!==r?r:{};this.permanentProperties.propsPerEvent[i]=e(e({},s),t)}else this.permanentProperties.globalProps=e(e({},this.permanentProperties.globalProps),t);this.propsPersistance&&o&&this.propsPersistance.save(this.permanentProperties)},r.prototype.unset=function(e,t){o();var n=null==t?void 0:t.eventType,r=void 0===(null==t?void 0:t.persist)||(null==t?void 0:t.persist);n?this.permanentProperties.propsPerEvent[n]&&delete this.permanentProperties.propsPerEvent[n][e]:delete this.permanentProperties.globalProps[e],this.propsPersistance&&r&&this.propsPersistance.save(this.permanentProperties)},r.prototype.manageAutoCapture=function(e){if(c().debug("Auto Capture Status: ",this.config.autocapture),this.__autocapture_enabled=this.config.autocapture,this.__autocapture_enabled){ne.enabledForProject(this.apiKey,100,100)?ne.isBrowserSupported()?(c().debug("Autocapture enabled..."),ne.init(this,e)):(this.config.autocapture=!1,this.__autocapture_enabled=!1,c().debug("Disabling Automatic Event Collection because this browser is not supported")):(this.config.autocapture=!1,this.__autocapture_enabled=!1,c().debug("Not in active bucket: disabling Automatic Event Collection."))}},r.prototype.capture=function(e,t){var n,r;if(void 0===t&&(t={}),this.initialized)if(F(e)||"string"!=typeof e)console.error("No event name provided to usermaven.capture");else{var i={event:e+(t.$event_type?"_"+t.$event_type:""),properties:this._calculate_event_properties(e,t)};(null===(r=null===(n=(i=J(i,this.get_config("properties_string_max_length"))).properties)||void 0===n?void 0:n.autocapture_attributes)||void 0===r?void 0:r.tag_name)&&this.track("$autocapture",i.properties),"$scroll"===e&&this.track(e,i.properties)}else console.error("Trying to capture event before initialization")},r.prototype._calculate_event_properties=function(e,t){var n,r,i=t||{};if("$snapshot"===e||"$scroll"===e)return i;O(this.propertyBlacklist)?j(this.propertyBlacklist,(function(e){delete i[e]})):console.error("Invalid value for property_blacklist config: "+this.propertyBlacklist);var o={},s=i.$elements||[];return s.length&&(o=s[0]),i.autocapture_attributes=o,i.autocapture_attributes.el_text=null!==(n=i.autocapture_attributes.$el_text)&&void 0!==n?n:"",i.autocapture_attributes.event_type=null!==(r=i.$event_type)&&void 0!==r?r:"",["$ce_version","$event_type","$initial_referrer","$initial_referring_domain","$referrer","$referring_domain","$elements"].forEach((function(e){delete i[e]})),delete i.autocapture_attributes.$el_text,delete i.autocapture_attributes.nth_child,delete i.autocapture_attributes.nth_of_type,i},r}();var ye=["use_beacon_api","cookie_domain","tracking_host","cookie_name","key","ga_hook","segment_hook","randomize_url","capture_3rd_party_cookies","id_method","log_level","compat_mode","privacy_policy","cookie_policy","ip_policy","custom_headers","force_use_fetch","min_send_timeout","max_send_timeout","max_send_attempts","disable_event_persistence","project_id","autocapture","properties_string_max_length","property_blacklist","exclude"];var _e="data-suppress-interception-warning";function be(e){return"\n ATTENTION! ".concat(e,"-hook set to true along with defer/async attribute! If ").concat(e," code is inserted right after Usermaven tag,\n first tracking call might not be intercepted! Consider one of the following:\n - Inject usermaven tracking code without defer/async attribute\n - If you're sure that events won't be sent to ").concat(e," before Usermaven is fully initialized, set ").concat(_e,'="true"\n script attribute\n ')}function we(e,t){c().debug("Processing queue",e);for(var n=0;n<e.length;n+=1){var i=r([],e[n],!0)||[],o=i[0],s=i.slice(1),a=t[o];"function"==typeof a&&a.apply(t,s)}e.length=0}if(window){var ke=window,Pe=function(e){var t=document.currentScript||document.querySelector("script[src*=jsFileName][data-usermaven-api-key]");if(t){var n,r={tracking_host:(n=t.getAttribute("src"),n.replace("/s/lib.js","").replace("/lib.js","")),key:null};ye.forEach((function(e){var n="data-"+e.replace(new RegExp("_","g"),"-");if(void 0!==t.getAttribute(n)&&null!==t.getAttribute(n)){var i=t.getAttribute(n);"true"===i?i=!0:"false"===i&&(i=!1),r[e]=i}})),e.usermavenClient=function(e){var t=new ge;return t.init(e),t}(r),!r.segment_hook||null===t.getAttribute("defer")&&null===t.getAttribute("async")||null!==t.getAttribute(_e)||c().warn(be("segment")),!r.ga_hook||null===t.getAttribute("defer")&&null===t.getAttribute("async")||null!==t.getAttribute(_e)||c().warn(be("ga"));var i=function(){var t=e.usermavenQ=e.usermavenQ||[];t.push(arguments),we(t,e.usermavenClient)};return e.usermaven=i,r.project_id&&i("set",{project_id:r.project_id}),"true"!==t.getAttribute("data-init-only")&&"yes"!==t.getAttribute("data-init-only")&&i("track","pageview"),e.usermavenClient}c().warn("Usermaven script is not properly initialized. The definition must contain data-usermaven-api-key as a parameter")}(ke);Pe?(c().debug("Usermaven in-browser tracker has been initialized"),ke.usermaven=function(){var e=ke.usermavenQ=ke.usermavenQ||[];e.push(arguments),we(e,Pe)},ke.usermavenQ&&(c().debug("Initial queue size of ".concat(ke.usermavenQ.length," will be processed")),we(ke.usermavenQ,Pe))):c().error("Usermaven tracker has not been initialized (reason unknown)")}else c().warn("Usermaven tracker called outside browser context. It will be ignored")}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/sdk-js",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Usermaven JavaScript SDK.",
5
5
  "main": "dist/npm/usermaven.cjs.js",
6
6
  "module": "dist/npm/dist/usermaven.es.js",