@usermaven/nextjs 1.2.5 → 1.2.7

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.
Files changed (2) hide show
  1. package/lib/index.es.js +54 -32
  2. package/package.json +2 -2
package/lib/index.es.js CHANGED
@@ -122,7 +122,7 @@ function getLogger() {
122
122
  function setRootLogLevel(logLevelName) {
123
123
  var logLevel = LogLevels[logLevelName.toLocaleUpperCase()];
124
124
  if (!logLevel) {
125
- console.warn("Can't find log level with name ".concat(logLevelName.toLocaleUpperCase(), ", defaulting to INFO"));
125
+ console.warn("Can't find log level with name " + logLevelName.toLocaleUpperCase() + ", defaulting to INFO");
126
126
  logLevel = LogLevels.INFO;
127
127
  }
128
128
  rootLogger = createLogger(logLevel);
@@ -165,7 +165,7 @@ function createLogger(logLevel) {
165
165
  if (severity >= minLogLevel.severity && args.length > 0) {
166
166
  var message = args[0];
167
167
  var msgArgs = args.splice(1);
168
- var msgFormatted = "[J-".concat(name, "] ").concat(message);
168
+ var msgFormatted = "[J-" + name + "] " + message;
169
169
  if (name === 'DEBUG' || name === 'INFO') {
170
170
  console.log.apply(console, __spreadArray([msgFormatted], msgArgs, false));
171
171
  }
@@ -216,21 +216,21 @@ function serializeCookie(name, val, opt) {
216
216
  if (opt === void 0) { opt = {}; }
217
217
  try {
218
218
  var maxAge = opt.maxAge, domain = opt.domain, path = opt.path, expires = opt.expires, httpOnly = opt.httpOnly, secure = opt.secure, sameSite = opt.sameSite;
219
- var new_cookie_val = "".concat(name, "=").concat(encodeURIComponent(val));
219
+ var new_cookie_val = name + "=" + encodeURIComponent(val);
220
220
  if (domain) {
221
- new_cookie_val += "; domain=".concat(domain);
221
+ new_cookie_val += "; domain=" + domain;
222
222
  }
223
223
  if (path) {
224
- new_cookie_val += "; path=".concat(path);
224
+ new_cookie_val += "; path=" + path;
225
225
  }
226
226
  else {
227
227
  new_cookie_val += "; path=/";
228
228
  }
229
229
  if (expires) {
230
- new_cookie_val += "; expires=".concat(expires.toUTCString());
230
+ new_cookie_val += "; expires=" + expires.toUTCString();
231
231
  }
232
232
  if (maxAge) {
233
- new_cookie_val += "; max-age=".concat(maxAge);
233
+ new_cookie_val += "; max-age=" + maxAge;
234
234
  }
235
235
  if (httpOnly) {
236
236
  new_cookie_val += "; httponly";
@@ -1399,10 +1399,10 @@ _safewrap_instance_methods(autocapture);
1399
1399
 
1400
1400
  var VERSION_INFO = {
1401
1401
  env: 'production',
1402
- date: '2023-11-01T06:34:21.101Z',
1403
- version: '1.2.5'
1402
+ date: '2023-12-21T09:27:52.618Z',
1403
+ version: '1.2.7'
1404
1404
  };
1405
- var USERMAVEN_VERSION = "".concat(VERSION_INFO.version, "/").concat(VERSION_INFO.env, "@").concat(VERSION_INFO.date);
1405
+ var USERMAVEN_VERSION = VERSION_INFO.version + "/" + VERSION_INFO.env + "@" + VERSION_INFO.date;
1406
1406
  var MAX_AGE_TEN_YEARS = 31622400 * 10;
1407
1407
  var beaconTransport = function (url, json) {
1408
1408
  getLogger().debug("Sending beacon", json);
@@ -1421,7 +1421,7 @@ function tryFormat(string) {
1421
1421
  }
1422
1422
  }
1423
1423
  var echoTransport = function (url, json) {
1424
- console.debug("Jitsu client tried to send payload to ".concat(url), tryFormat(json));
1424
+ console.debug("Jitsu client tried to send payload to " + url, tryFormat(json));
1425
1425
  return Promise.resolve();
1426
1426
  };
1427
1427
  // This is a hack to expire all cookies with non-root path left behind by invalid tracking.
@@ -1454,7 +1454,7 @@ var CookiePersistence = /** @class */ (function () {
1454
1454
  try {
1455
1455
  var parsed = JSON.parse(decodeURIComponent(str));
1456
1456
  if (typeof parsed !== "object") {
1457
- getLogger().warn("Can't restore value of ".concat(this.cookieName, "@").concat(this.cookieDomain, ", expected to be object, but found ").concat(typeof parsed !== "object", ": ").concat(parsed, ". Ignoring"));
1457
+ getLogger().warn("Can't restore value of " + this.cookieName + "@" + this.cookieDomain + ", expected to be object, but found " + (typeof parsed !== "object") + ": " + parsed + ". Ignoring");
1458
1458
  return undefined;
1459
1459
  }
1460
1460
  return parsed;
@@ -1600,7 +1600,7 @@ function httpApi(req, res, opts) {
1600
1600
  page_title: "",
1601
1601
  referer: header(req, "referrer"),
1602
1602
  screen_resolution: "",
1603
- url: "".concat(proto, "://").concat(requestHost).concat(path || "").concat(query || ""),
1603
+ url: proto + "://" + requestHost + (path || "") + (query || ""),
1604
1604
  user_agent: req.headers["user-agent"],
1605
1605
  user_language: req.headers["accept-language"] &&
1606
1606
  req.headers["accept-language"].split(",")[0],
@@ -1632,15 +1632,15 @@ var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1632
1632
  var req = new window.XMLHttpRequest();
1633
1633
  return new Promise(function (resolve, reject) {
1634
1634
  req.onerror = function (e) {
1635
- getLogger().error("Failed to send payload to ".concat(url, ": ").concat((e === null || e === void 0 ? void 0 : e.message) || "unknown error"), jsonPayload, e);
1635
+ getLogger().error("Failed to send payload to " + url + ": " + ((e === null || e === void 0 ? void 0 : e.message) || "unknown error"), jsonPayload, e);
1636
1636
  handler(-1, {});
1637
1637
  reject(new Error("Failed to send JSON. See console logs"));
1638
1638
  };
1639
1639
  req.onload = function () {
1640
1640
  if (req.status !== 200) {
1641
1641
  handler(req.status, {});
1642
- getLogger().warn("Failed to send data to ".concat(url, " (#").concat(req.status, " - ").concat(req.statusText, ")"), jsonPayload);
1643
- reject(new Error("Failed to send JSON. Error code: ".concat(req.status, ". See logs for details")));
1642
+ getLogger().warn("Failed to send data to " + url + " (#" + req.status + " - " + req.statusText + ")", jsonPayload);
1643
+ reject(new Error("Failed to send JSON. Error code: " + req.status + ". See logs for details"));
1644
1644
  }
1645
1645
  else {
1646
1646
  handler(req.status, req.responseText);
@@ -1678,12 +1678,12 @@ var fetchTransport = function (fetch) {
1678
1678
  return [3 /*break*/, 3];
1679
1679
  case 2:
1680
1680
  e_1 = _c.sent();
1681
- getLogger().error("Failed to send data to ".concat(url, ": ").concat((e_1 === null || e_1 === void 0 ? void 0 : e_1.message) || "unknown error"), jsonPayload, e_1);
1681
+ getLogger().error("Failed to send data to " + url + ": " + ((e_1 === null || e_1 === void 0 ? void 0 : e_1.message) || "unknown error"), jsonPayload, e_1);
1682
1682
  handler(-1, {});
1683
1683
  return [2 /*return*/];
1684
1684
  case 3:
1685
1685
  if (res.status !== 200) {
1686
- getLogger().warn("Failed to send data to ".concat(url, " (#").concat(res.status, " - ").concat(res.statusText, ")"), jsonPayload);
1686
+ getLogger().warn("Failed to send data to " + url + " (#" + res.status + " - " + res.statusText + ")", jsonPayload);
1687
1687
  handler(res.status, {});
1688
1688
  return [2 /*return*/];
1689
1689
  }
@@ -1700,14 +1700,14 @@ var fetchTransport = function (fetch) {
1700
1700
  return [3 /*break*/, 7];
1701
1701
  case 6:
1702
1702
  e_2 = _c.sent();
1703
- getLogger().error("Failed to parse ".concat(url, " response. Content-type: ").concat(contentType, " text: ").concat(text), e_2);
1703
+ getLogger().error("Failed to parse " + url + " response. Content-type: " + contentType + " text: " + text, e_2);
1704
1704
  return [3 /*break*/, 7];
1705
1705
  case 7:
1706
1706
  try {
1707
1707
  handler(res.status, resJson);
1708
1708
  }
1709
1709
  catch (e) {
1710
- getLogger().error("Failed to handle ".concat(url, " response. Content-type: ").concat(contentType, " text: ").concat(text), e);
1710
+ getLogger().error("Failed to handle " + url + " response. Content-type: " + contentType + " text: " + text, e);
1711
1711
  }
1712
1712
  return [2 /*return*/];
1713
1713
  }
@@ -1727,6 +1727,7 @@ var UsermavenClientImpl = /** @class */ (function () {
1727
1727
  this.trackingHost = "";
1728
1728
  this.idCookieName = "";
1729
1729
  this.randomizeUrl = false;
1730
+ this.namespace = "usermaven";
1730
1731
  this.apiKey = "";
1731
1732
  this.initialized = false;
1732
1733
  this._3pCookies = {};
@@ -1744,6 +1745,7 @@ var UsermavenClientImpl = /** @class */ (function () {
1744
1745
  // public persistence?: UserMavenPersistence;
1745
1746
  // public sessionManager?: SessionIdManager;
1746
1747
  this.__autocapture_enabled = false;
1748
+ this.__auto_pageview_enabled = false;
1747
1749
  // private anonymousId: string = '';
1748
1750
  // Fallback tracking host
1749
1751
  this.trackingHostFallback = "https://events.usermaven.com" ;
@@ -1857,15 +1859,15 @@ var UsermavenClientImpl = /** @class */ (function () {
1857
1859
  };
1858
1860
  UsermavenClientImpl.prototype.doSendJson = function (json) {
1859
1861
  var _this = this;
1860
- var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy=".concat(this.cookiePolicy) : "";
1861
- var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy=".concat(this.ipPolicy) : "";
1862
+ var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy=" + this.cookiePolicy : "";
1863
+ var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy=" + this.ipPolicy : "";
1862
1864
  var urlPrefix = isWindowAvailable() ? "/api/v1/event" : "/api/v1/s2s/event";
1863
- var url = "".concat(this.trackingHost).concat(urlPrefix, "?token=").concat(this.apiKey).concat(cookiePolicy).concat(ipPolicy);
1865
+ var url = "" + this.trackingHost + urlPrefix + "?token=" + this.apiKey + cookiePolicy + ipPolicy;
1864
1866
  if (this.randomizeUrl) {
1865
- url = "".concat(this.trackingHost, "/api.").concat(generateRandom(), "?p_").concat(generateRandom(), "=").concat(this.apiKey).concat(cookiePolicy).concat(ipPolicy);
1867
+ url = this.trackingHost + "/api." + generateRandom() + "?p_" + generateRandom() + "=" + this.apiKey + cookiePolicy + ipPolicy;
1866
1868
  }
1867
1869
  var jsonString = JSON.stringify(json);
1868
- getLogger().debug("Sending payload to ".concat(url), jsonString);
1870
+ getLogger().debug("Sending payload to " + url, json.length);
1869
1871
  return this.transport(url, jsonString, this.customHeaders(), function (code, body) {
1870
1872
  return _this.postHandle(code, body);
1871
1873
  });
@@ -1881,7 +1883,7 @@ var UsermavenClientImpl = /** @class */ (function () {
1881
1883
  var factor = Math.pow(2, this.attempt++);
1882
1884
  timeout = Math.min(this.retryTimeout[0] * random * factor, this.retryTimeout[1]);
1883
1885
  }
1884
- getLogger().debug("Scheduling event queue flush in ".concat(timeout, " ms."));
1886
+ getLogger().debug("Scheduling event queue flush in " + timeout + " ms.");
1885
1887
  setTimeout(function () { return _this.flush(); }, timeout);
1886
1888
  };
1887
1889
  UsermavenClientImpl.prototype.flush = function () {
@@ -1908,18 +1910,18 @@ var UsermavenClientImpl = /** @class */ (function () {
1908
1910
  case 2:
1909
1911
  _b.sent();
1910
1912
  this.attempt = 1;
1911
- getLogger().debug("Successfully flushed ".concat(queue.length, " events from queue"));
1913
+ getLogger().debug("Successfully flushed " + queue.length + " events from queue");
1912
1914
  return [3 /*break*/, 4];
1913
1915
  case 3:
1914
1916
  _b.sent();
1915
1917
  // In case of failing custom domain (trackingHost), we will replace it with default domain (trackingHostFallback)
1916
1918
  if (this.trackingHost !== this.trackingHostFallback) {
1917
- getLogger().debug("Using fallback tracking host ".concat(this.trackingHostFallback, " instead of ").concat(this.trackingHost, " on ").concat(VERSION_INFO.env));
1919
+ getLogger().debug("Using fallback tracking host " + this.trackingHostFallback + " instead of " + this.trackingHost + " on " + VERSION_INFO.env);
1918
1920
  this.trackingHost = this.trackingHostFallback;
1919
1921
  }
1920
1922
  queue = queue.map(function (el) { return [el[0], el[1] + 1]; }).filter(function (el) {
1921
1923
  if (el[1] >= _this.maxSendAttempts) {
1922
- getLogger().error("Dropping queued event after ".concat(el[1], " attempts since max send attempts ").concat(_this.maxSendAttempts, " reached. See logs for details"));
1924
+ getLogger().error("Dropping queued event after " + el[1] + " attempts since max send attempts " + _this.maxSendAttempts + " reached. See logs for details");
1923
1925
  return false;
1924
1926
  }
1925
1927
  return true;
@@ -2100,10 +2102,12 @@ var UsermavenClientImpl = /** @class */ (function () {
2100
2102
  ? defaultCompatMode
2101
2103
  : !!options.compat_mode;
2102
2104
  this.cookieDomain = options.cookie_domain || getCookieDomain();
2105
+ this.namespace = options.namespace || "usermaven";
2103
2106
  this.trackingHost = getHostWithProtocol(options["tracking_host"] || "t.usermaven.com");
2104
2107
  this.randomizeUrl = options.randomize_url || false;
2105
2108
  this.apiKey = options.key;
2106
- this.idCookieName = options.cookie_name || "__eventn_id_".concat(options.key);
2109
+ this.__auto_pageview_enabled = options.auto_pageview || false;
2110
+ this.idCookieName = options.cookie_name || "__eventn_id_" + options.key;
2107
2111
  if (this.cookiePolicy === "strict") {
2108
2112
  this.propsPersistance = new NoPersistence();
2109
2113
  }
@@ -2135,7 +2139,8 @@ var UsermavenClientImpl = /** @class */ (function () {
2135
2139
  autocapture: false,
2136
2140
  properties_string_max_length: null,
2137
2141
  property_blacklist: [],
2138
- sanitize_properties: null
2142
+ sanitize_properties: null,
2143
+ auto_pageview: false
2139
2144
  };
2140
2145
  this.config = _extend({}, defaultConfig, options || {}, this.config || {}, { token: this.apiKey });
2141
2146
  getLogger().debug('Default Configuration', this.config);
@@ -2161,11 +2166,14 @@ var UsermavenClientImpl = /** @class */ (function () {
2161
2166
  }
2162
2167
  if (isWindowAvailable()) {
2163
2168
  if (!options.disable_event_persistence) {
2164
- this.queue = new LocalStorageQueue("jitsu-event-queue");
2169
+ this.queue = new LocalStorageQueue(this.namespace + "-event-queue");
2165
2170
  this.scheduleFlush(0);
2166
2171
  }
2167
2172
  window.addEventListener("beforeunload", function () { return _this.flush(); });
2168
2173
  }
2174
+ if (this.__auto_pageview_enabled) {
2175
+ enableAutoPageviews(this);
2176
+ }
2169
2177
  this.retryTimeout = [
2170
2178
  (_c = options.min_send_timeout) !== null && _c !== void 0 ? _c : this.retryTimeout[0],
2171
2179
  (_d = options.max_send_timeout) !== null && _d !== void 0 ? _d : this.retryTimeout[1],
@@ -2356,6 +2364,20 @@ var UsermavenClientImpl = /** @class */ (function () {
2356
2364
  };
2357
2365
  return UsermavenClientImpl;
2358
2366
  }());
2367
+ function enableAutoPageviews(t) {
2368
+ var page = function () { return t.track("pageview"); };
2369
+ // Attach pushState and popState listeners
2370
+ var originalPushState = history.pushState;
2371
+ if (originalPushState) {
2372
+ // eslint-disable-next-line functional/immutable-data
2373
+ history.pushState = function (data, title, url) {
2374
+ originalPushState.apply(this, [data, title, url]);
2375
+ page();
2376
+ };
2377
+ addEventListener('popstate', page);
2378
+ }
2379
+ addEventListener('hashchange', page);
2380
+ }
2359
2381
  function interceptSegmentCalls(t) {
2360
2382
  var win = window;
2361
2383
  if (!win.analytics) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/nextjs",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Usermaven JavaScript SDK for NextJS",
5
5
  "author": "Usermaven <hello@usermaven.com>",
6
6
  "license": "MIT",
@@ -44,4 +44,4 @@
44
44
  "url": "https://github.com/usermaven/usermaven-js",
45
45
  "directory": "packages/nextjs"
46
46
  }
47
- }
47
+ }