@usermaven/nextjs 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.es.js +51 -31
- 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 "
|
|
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-"
|
|
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 =
|
|
219
|
+
var new_cookie_val = name + "=" + encodeURIComponent(val);
|
|
220
220
|
if (domain) {
|
|
221
|
-
new_cookie_val += "; domain="
|
|
221
|
+
new_cookie_val += "; domain=" + domain;
|
|
222
222
|
}
|
|
223
223
|
if (path) {
|
|
224
|
-
new_cookie_val += "; 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="
|
|
230
|
+
new_cookie_val += "; expires=" + expires.toUTCString();
|
|
231
231
|
}
|
|
232
232
|
if (maxAge) {
|
|
233
|
-
new_cookie_val += "; max-age="
|
|
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-
|
|
1403
|
-
version: '1.2.
|
|
1402
|
+
date: '2023-12-12T10:57:33.456Z',
|
|
1403
|
+
version: '1.2.6'
|
|
1404
1404
|
};
|
|
1405
|
-
var USERMAVEN_VERSION =
|
|
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 "
|
|
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 "
|
|
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:
|
|
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 "
|
|
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 "
|
|
1643
|
-
reject(new Error("Failed to send JSON. Error code: "
|
|
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 "
|
|
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 "
|
|
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 "
|
|
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 "
|
|
1710
|
+
getLogger().error("Failed to handle " + url + " response. Content-type: " + contentType + " text: " + text, e);
|
|
1711
1711
|
}
|
|
1712
1712
|
return [2 /*return*/];
|
|
1713
1713
|
}
|
|
@@ -1744,6 +1744,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
1744
1744
|
// public persistence?: UserMavenPersistence;
|
|
1745
1745
|
// public sessionManager?: SessionIdManager;
|
|
1746
1746
|
this.__autocapture_enabled = false;
|
|
1747
|
+
this.__auto_pageview_enabled = false;
|
|
1747
1748
|
// private anonymousId: string = '';
|
|
1748
1749
|
// Fallback tracking host
|
|
1749
1750
|
this.trackingHostFallback = "https://events.usermaven.com" ;
|
|
@@ -1857,15 +1858,15 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
1857
1858
|
};
|
|
1858
1859
|
UsermavenClientImpl.prototype.doSendJson = function (json) {
|
|
1859
1860
|
var _this = this;
|
|
1860
|
-
var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy="
|
|
1861
|
-
var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy="
|
|
1861
|
+
var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy=" + this.cookiePolicy : "";
|
|
1862
|
+
var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy=" + this.ipPolicy : "";
|
|
1862
1863
|
var urlPrefix = isWindowAvailable() ? "/api/v1/event" : "/api/v1/s2s/event";
|
|
1863
|
-
var url = ""
|
|
1864
|
+
var url = "" + this.trackingHost + urlPrefix + "?token=" + this.apiKey + cookiePolicy + ipPolicy;
|
|
1864
1865
|
if (this.randomizeUrl) {
|
|
1865
|
-
url =
|
|
1866
|
+
url = this.trackingHost + "/api." + generateRandom() + "?p_" + generateRandom() + "=" + this.apiKey + cookiePolicy + ipPolicy;
|
|
1866
1867
|
}
|
|
1867
1868
|
var jsonString = JSON.stringify(json);
|
|
1868
|
-
getLogger().debug("Sending payload to "
|
|
1869
|
+
getLogger().debug("Sending payload to " + url, jsonString);
|
|
1869
1870
|
return this.transport(url, jsonString, this.customHeaders(), function (code, body) {
|
|
1870
1871
|
return _this.postHandle(code, body);
|
|
1871
1872
|
});
|
|
@@ -1881,7 +1882,7 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
1881
1882
|
var factor = Math.pow(2, this.attempt++);
|
|
1882
1883
|
timeout = Math.min(this.retryTimeout[0] * random * factor, this.retryTimeout[1]);
|
|
1883
1884
|
}
|
|
1884
|
-
getLogger().debug("Scheduling event queue flush in "
|
|
1885
|
+
getLogger().debug("Scheduling event queue flush in " + timeout + " ms.");
|
|
1885
1886
|
setTimeout(function () { return _this.flush(); }, timeout);
|
|
1886
1887
|
};
|
|
1887
1888
|
UsermavenClientImpl.prototype.flush = function () {
|
|
@@ -1908,18 +1909,18 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
1908
1909
|
case 2:
|
|
1909
1910
|
_b.sent();
|
|
1910
1911
|
this.attempt = 1;
|
|
1911
|
-
getLogger().debug("Successfully flushed "
|
|
1912
|
+
getLogger().debug("Successfully flushed " + queue.length + " events from queue");
|
|
1912
1913
|
return [3 /*break*/, 4];
|
|
1913
1914
|
case 3:
|
|
1914
1915
|
_b.sent();
|
|
1915
1916
|
// In case of failing custom domain (trackingHost), we will replace it with default domain (trackingHostFallback)
|
|
1916
1917
|
if (this.trackingHost !== this.trackingHostFallback) {
|
|
1917
|
-
getLogger().debug("Using fallback tracking host "
|
|
1918
|
+
getLogger().debug("Using fallback tracking host " + this.trackingHostFallback + " instead of " + this.trackingHost + " on " + VERSION_INFO.env);
|
|
1918
1919
|
this.trackingHost = this.trackingHostFallback;
|
|
1919
1920
|
}
|
|
1920
1921
|
queue = queue.map(function (el) { return [el[0], el[1] + 1]; }).filter(function (el) {
|
|
1921
1922
|
if (el[1] >= _this.maxSendAttempts) {
|
|
1922
|
-
getLogger().error("Dropping queued event after "
|
|
1923
|
+
getLogger().error("Dropping queued event after " + el[1] + " attempts since max send attempts " + _this.maxSendAttempts + " reached. See logs for details");
|
|
1923
1924
|
return false;
|
|
1924
1925
|
}
|
|
1925
1926
|
return true;
|
|
@@ -2103,7 +2104,8 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2103
2104
|
this.trackingHost = getHostWithProtocol(options["tracking_host"] || "t.usermaven.com");
|
|
2104
2105
|
this.randomizeUrl = options.randomize_url || false;
|
|
2105
2106
|
this.apiKey = options.key;
|
|
2106
|
-
this.
|
|
2107
|
+
this.__auto_pageview_enabled = options.auto_pageview || false;
|
|
2108
|
+
this.idCookieName = options.cookie_name || "__eventn_id_" + options.key;
|
|
2107
2109
|
if (this.cookiePolicy === "strict") {
|
|
2108
2110
|
this.propsPersistance = new NoPersistence();
|
|
2109
2111
|
}
|
|
@@ -2135,7 +2137,8 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2135
2137
|
autocapture: false,
|
|
2136
2138
|
properties_string_max_length: null,
|
|
2137
2139
|
property_blacklist: [],
|
|
2138
|
-
sanitize_properties: null
|
|
2140
|
+
sanitize_properties: null,
|
|
2141
|
+
auto_pageview: false
|
|
2139
2142
|
};
|
|
2140
2143
|
this.config = _extend({}, defaultConfig, options || {}, this.config || {}, { token: this.apiKey });
|
|
2141
2144
|
getLogger().debug('Default Configuration', this.config);
|
|
@@ -2166,6 +2169,9 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2166
2169
|
}
|
|
2167
2170
|
window.addEventListener("beforeunload", function () { return _this.flush(); });
|
|
2168
2171
|
}
|
|
2172
|
+
if (this.__auto_pageview_enabled) {
|
|
2173
|
+
enableAutoPageviews(this);
|
|
2174
|
+
}
|
|
2169
2175
|
this.retryTimeout = [
|
|
2170
2176
|
(_c = options.min_send_timeout) !== null && _c !== void 0 ? _c : this.retryTimeout[0],
|
|
2171
2177
|
(_d = options.max_send_timeout) !== null && _d !== void 0 ? _d : this.retryTimeout[1],
|
|
@@ -2356,6 +2362,20 @@ var UsermavenClientImpl = /** @class */ (function () {
|
|
|
2356
2362
|
};
|
|
2357
2363
|
return UsermavenClientImpl;
|
|
2358
2364
|
}());
|
|
2365
|
+
function enableAutoPageviews(t) {
|
|
2366
|
+
var page = function () { return t.track("pageview"); };
|
|
2367
|
+
// Attach pushState and popState listeners
|
|
2368
|
+
var originalPushState = history.pushState;
|
|
2369
|
+
if (originalPushState) {
|
|
2370
|
+
// eslint-disable-next-line functional/immutable-data
|
|
2371
|
+
history.pushState = function (data, title, url) {
|
|
2372
|
+
originalPushState.apply(this, [data, title, url]);
|
|
2373
|
+
page();
|
|
2374
|
+
};
|
|
2375
|
+
addEventListener('popstate', page);
|
|
2376
|
+
}
|
|
2377
|
+
addEventListener('hashchange', page);
|
|
2378
|
+
}
|
|
2359
2379
|
function interceptSegmentCalls(t) {
|
|
2360
2380
|
var win = window;
|
|
2361
2381
|
if (!win.analytics) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/nextjs",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
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
|
+
}
|