@jitsu/js 1.9.7-canary.903.20240731114701 → 1.9.8
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/.turbo/turbo-build.log +5 -5
- package/.turbo/turbo-clean.log +1 -1
- package/.turbo/turbo-test.log +2129 -436
- package/__tests__/node/nodejs.test.ts +213 -78
- package/__tests__/playwright/cases/disable-user-ids.html +23 -0
- package/__tests__/playwright/cases/dont-send.html +22 -0
- package/__tests__/playwright/cases/ip-policy.html +22 -0
- package/__tests__/playwright/integration.test.ts +170 -2
- package/dist/analytics-plugin.d.ts +3 -5
- package/dist/browser.d.ts +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/jitsu.cjs.js +165 -39
- package/dist/jitsu.d.ts +6 -1
- package/dist/jitsu.es.js +165 -40
- package/dist/web/p.js.txt +195 -44
- package/package.json +4 -3
- package/src/analytics-plugin.ts +146 -49
- package/src/browser.ts +45 -16
- package/src/destination-plugins/index.ts +0 -1
- package/src/index.ts +57 -28
- package/src/jitsu.ts +0 -93
package/dist/web/p.js.txt
CHANGED
|
@@ -1052,6 +1052,37 @@
|
|
|
1052
1052
|
fetchTimeoutMs: undefined,
|
|
1053
1053
|
s2s: undefined,
|
|
1054
1054
|
idEndpoint: undefined,
|
|
1055
|
+
privacy: {
|
|
1056
|
+
dontSend: false,
|
|
1057
|
+
disableUserIds: false,
|
|
1058
|
+
ipPolicy: "keep",
|
|
1059
|
+
consentCategories: undefined,
|
|
1060
|
+
},
|
|
1061
|
+
};
|
|
1062
|
+
// mergeConfig merges newConfig into currentConfig also making sure that all undefined values are replaced with defaultConfig values
|
|
1063
|
+
const mergeConfig = (current, newConfig) => {
|
|
1064
|
+
for (const key of Object.keys(defaultConfig)) {
|
|
1065
|
+
const value = newConfig[key];
|
|
1066
|
+
if (key === "privacy") {
|
|
1067
|
+
if (typeof value === "object") {
|
|
1068
|
+
current.privacy = Object.assign(Object.assign(Object.assign({}, defaultConfig.privacy), current.privacy), value);
|
|
1069
|
+
}
|
|
1070
|
+
else if (newConfig.hasOwnProperty("privacy") && typeof value === "undefined") {
|
|
1071
|
+
// explicitly set to undefined - reset to default
|
|
1072
|
+
current.privacy = Object.assign({}, defaultConfig.privacy);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
else if (typeof value === "undefined") {
|
|
1076
|
+
if (newConfig.hasOwnProperty(key) || !current.hasOwnProperty(key)) {
|
|
1077
|
+
// explicitly set to undefined - reset to default
|
|
1078
|
+
// or was not set at all - set to default
|
|
1079
|
+
current[key] = defaultConfig[key];
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
else {
|
|
1083
|
+
current[key] = value;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1055
1086
|
};
|
|
1056
1087
|
const parseQuery = (qs) => {
|
|
1057
1088
|
if (!qs) {
|
|
@@ -1159,10 +1190,19 @@
|
|
|
1159
1190
|
__anon_id: "__eventn_id",
|
|
1160
1191
|
__user_traits: "__eventn_id_usr",
|
|
1161
1192
|
__user_id: "__eventn_uid",
|
|
1193
|
+
__group_id: "__group_id",
|
|
1194
|
+
__group_traits: "__group_traits",
|
|
1162
1195
|
};
|
|
1163
1196
|
const cookieStorage = (cookieDomain, key2cookie) => {
|
|
1164
1197
|
return {
|
|
1165
1198
|
setItem(key, val) {
|
|
1199
|
+
if (typeof val === "undefined") {
|
|
1200
|
+
removeCookie(key2cookie[key] || key, {
|
|
1201
|
+
domain: cookieDomain,
|
|
1202
|
+
secure: window.location.protocol === "https:",
|
|
1203
|
+
});
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1166
1206
|
const strVal = typeof val === "object" && val !== null ? encodeURIComponent(JSON.stringify(val)) : val;
|
|
1167
1207
|
const cookieName = key2cookie[key] || key;
|
|
1168
1208
|
setCookie(cookieName, strVal, {
|
|
@@ -1270,7 +1310,12 @@
|
|
|
1270
1310
|
if (config.debug) {
|
|
1271
1311
|
console.log(`[JITSU EMPTY RUNTIME] Set storage item ${key}=${JSON.stringify(val)}`);
|
|
1272
1312
|
}
|
|
1273
|
-
|
|
1313
|
+
if (typeof val === "undefined") {
|
|
1314
|
+
delete storage[key];
|
|
1315
|
+
}
|
|
1316
|
+
else {
|
|
1317
|
+
storage[key] = val;
|
|
1318
|
+
}
|
|
1274
1319
|
},
|
|
1275
1320
|
getItem(key) {
|
|
1276
1321
|
const val = storage[key];
|
|
@@ -1343,7 +1388,7 @@
|
|
|
1343
1388
|
return "/" + pathMatch;
|
|
1344
1389
|
}
|
|
1345
1390
|
function adjustPayload(payload, config, storage, s2s) {
|
|
1346
|
-
var _a, _b;
|
|
1391
|
+
var _a, _b, _c, _d, _e;
|
|
1347
1392
|
const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
|
|
1348
1393
|
const url = runtime.pageUrl();
|
|
1349
1394
|
const parsedUrl = safeCall(() => new URL(url), undefined);
|
|
@@ -1360,8 +1405,13 @@
|
|
|
1360
1405
|
library: {
|
|
1361
1406
|
name: jitsuLibraryName,
|
|
1362
1407
|
version: jitsuVersion,
|
|
1363
|
-
env:
|
|
1408
|
+
env: isInBrowser() ? "browser" : "node",
|
|
1364
1409
|
},
|
|
1410
|
+
consent: ((_c = config.privacy) === null || _c === void 0 ? void 0 : _c.consentCategories)
|
|
1411
|
+
? {
|
|
1412
|
+
categoryPreferences: config.privacy.consentCategories,
|
|
1413
|
+
}
|
|
1414
|
+
: undefined,
|
|
1365
1415
|
userAgent: runtime.userAgent(),
|
|
1366
1416
|
locale: runtime.language(),
|
|
1367
1417
|
screen: runtime.screen(),
|
|
@@ -1376,12 +1426,19 @@
|
|
|
1376
1426
|
url: properties.url || url,
|
|
1377
1427
|
encoding: properties.encoding || runtime.documentEncoding(),
|
|
1378
1428
|
},
|
|
1379
|
-
clientIds:
|
|
1429
|
+
clientIds: !((_d = config.privacy) === null || _d === void 0 ? void 0 : _d.disableUserIds)
|
|
1430
|
+
? Object.assign({ fbc: runtime.getCookie("_fbc"), fbp: runtime.getCookie("_fbp") }, getGa4Ids(runtime)) : undefined,
|
|
1380
1431
|
campaign: parseUtms(query),
|
|
1381
1432
|
};
|
|
1382
1433
|
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: maskWriteKey(config.writeKey), groupId: storage.getItem("__group_id"), context: deepMerge(context, customContext) });
|
|
1383
1434
|
delete withContext.meta;
|
|
1384
1435
|
delete withContext.options;
|
|
1436
|
+
if ((_e = config.privacy) === null || _e === void 0 ? void 0 : _e.disableUserIds) {
|
|
1437
|
+
delete withContext.userId;
|
|
1438
|
+
delete withContext.anonymousId;
|
|
1439
|
+
delete withContext.context.traits;
|
|
1440
|
+
delete withContext.groupId;
|
|
1441
|
+
}
|
|
1385
1442
|
return withContext;
|
|
1386
1443
|
}
|
|
1387
1444
|
function isDiff(obj) {
|
|
@@ -1487,11 +1544,12 @@
|
|
|
1487
1544
|
}
|
|
1488
1545
|
function send(method, payload, jitsuConfig, instance, store) {
|
|
1489
1546
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1547
|
+
var _a, _b;
|
|
1490
1548
|
if (jitsuConfig.echoEvents) {
|
|
1491
1549
|
console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
|
|
1492
1550
|
return;
|
|
1493
1551
|
}
|
|
1494
|
-
const s2s = jitsuConfig.s2s
|
|
1552
|
+
const s2s = !!jitsuConfig.s2s;
|
|
1495
1553
|
const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
|
|
1496
1554
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
1497
1555
|
if (!fetch) {
|
|
@@ -1501,7 +1559,7 @@
|
|
|
1501
1559
|
// if (jitsuConfig.debug) {
|
|
1502
1560
|
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
1503
1561
|
// }
|
|
1504
|
-
const adjustedPayload = adjustPayload(payload, jitsuConfig, store
|
|
1562
|
+
const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
|
|
1505
1563
|
const abortController = jitsuConfig.fetchTimeoutMs ? new AbortController() : undefined;
|
|
1506
1564
|
const abortTimeout = jitsuConfig.fetchTimeoutMs
|
|
1507
1565
|
? setTimeout(() => {
|
|
@@ -1509,11 +1567,14 @@
|
|
|
1509
1567
|
}, jitsuConfig.fetchTimeoutMs)
|
|
1510
1568
|
: undefined;
|
|
1511
1569
|
const authHeader = jitsuConfig.writeKey ? { "X-Write-Key": jitsuConfig.writeKey } : {};
|
|
1570
|
+
const ipHeader = typeof ((_a = jitsuConfig.privacy) === null || _a === void 0 ? void 0 : _a.ipPolicy) === "undefined" || ((_b = jitsuConfig.privacy) === null || _b === void 0 ? void 0 : _b.ipPolicy) === "keep"
|
|
1571
|
+
? {}
|
|
1572
|
+
: { "X-IP-Policy": jitsuConfig.privacy.ipPolicy };
|
|
1512
1573
|
let fetchResult;
|
|
1513
1574
|
try {
|
|
1514
1575
|
fetchResult = yield fetch(url, {
|
|
1515
1576
|
method: "POST",
|
|
1516
|
-
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|
|
1577
|
+
headers: Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader), ipHeader),
|
|
1517
1578
|
body: JSON.stringify(adjustedPayload),
|
|
1518
1579
|
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
1519
1580
|
});
|
|
@@ -1561,11 +1622,12 @@
|
|
|
1561
1622
|
return adjustedPayload;
|
|
1562
1623
|
});
|
|
1563
1624
|
}
|
|
1564
|
-
const jitsuAnalyticsPlugin = (
|
|
1565
|
-
|
|
1625
|
+
const jitsuAnalyticsPlugin = (jitsuOptions = {}, storage) => {
|
|
1626
|
+
// just to make sure that all undefined values are replaced with defaultConfig values
|
|
1627
|
+
mergeConfig(jitsuOptions, jitsuOptions);
|
|
1566
1628
|
return {
|
|
1567
1629
|
name: "jitsu",
|
|
1568
|
-
config:
|
|
1630
|
+
config: jitsuOptions,
|
|
1569
1631
|
initialize: (args) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
1570
1632
|
const { config } = args;
|
|
1571
1633
|
if (config.debug) {
|
|
@@ -1602,17 +1664,28 @@
|
|
|
1602
1664
|
}
|
|
1603
1665
|
}),
|
|
1604
1666
|
page: args => {
|
|
1667
|
+
var _a;
|
|
1605
1668
|
const { payload, config, instance } = args;
|
|
1606
|
-
|
|
1669
|
+
if ((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) {
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
return send("page", payload, config, instance, storage);
|
|
1607
1673
|
},
|
|
1608
1674
|
track: args => {
|
|
1675
|
+
var _a;
|
|
1609
1676
|
const { payload, config, instance } = args;
|
|
1610
|
-
|
|
1677
|
+
if ((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
return send("track", payload, config, instance, storage);
|
|
1611
1681
|
},
|
|
1612
1682
|
identify: args => {
|
|
1683
|
+
var _a, _b;
|
|
1613
1684
|
const { payload, config, instance } = args;
|
|
1685
|
+
if (((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = config.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1614
1688
|
// Store traits in cache to be able to use them in page and track events that run asynchronously with current identify.
|
|
1615
|
-
const storage = pluginConfig.storageWrapper ? pluginConfig.storageWrapper(instance.storage) : instance.storage;
|
|
1616
1689
|
storage.setItem("__user_id", payload.userId);
|
|
1617
1690
|
if (payload.traits && typeof payload.traits === "object") {
|
|
1618
1691
|
storage.setItem("__user_traits", payload.traits);
|
|
@@ -1621,31 +1694,50 @@
|
|
|
1621
1694
|
},
|
|
1622
1695
|
reset: args => {
|
|
1623
1696
|
const { config, instance } = args;
|
|
1624
|
-
|
|
1625
|
-
storage === null || storage === void 0 ? void 0 : storage.reset();
|
|
1697
|
+
storage.reset();
|
|
1626
1698
|
if (config.debug) {
|
|
1627
1699
|
console.log("[JITSU DEBUG] Resetting Jitsu plugin storage");
|
|
1628
1700
|
}
|
|
1629
1701
|
},
|
|
1630
1702
|
methods: {
|
|
1631
1703
|
//analytics doesn't support group as a base method, so we need to add it manually
|
|
1704
|
+
configure(newOptions) {
|
|
1705
|
+
var _a, _b, _c, _d;
|
|
1706
|
+
const idsWasDisabled = ((_a = jitsuOptions.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = jitsuOptions.privacy) === null || _b === void 0 ? void 0 : _b.dontSend);
|
|
1707
|
+
mergeConfig(jitsuOptions, newOptions);
|
|
1708
|
+
const idsDisabledNow = ((_c = jitsuOptions.privacy) === null || _c === void 0 ? void 0 : _c.disableUserIds) || ((_d = jitsuOptions.privacy) === null || _d === void 0 ? void 0 : _d.dontSend);
|
|
1709
|
+
if (!idsDisabledNow && idsWasDisabled) {
|
|
1710
|
+
if (jitsuOptions.debug) {
|
|
1711
|
+
console.log("[JITSU] Enabling Anonymous ID. Generating new Id.");
|
|
1712
|
+
}
|
|
1713
|
+
const instance = this.instance;
|
|
1714
|
+
const newAnonymousId = uuid();
|
|
1715
|
+
const userState = instance.user();
|
|
1716
|
+
if (userState) {
|
|
1717
|
+
userState.anonymousId = newAnonymousId;
|
|
1718
|
+
}
|
|
1719
|
+
storage.setItem("__anon_id", newAnonymousId);
|
|
1720
|
+
instance.setAnonymousId(newAnonymousId);
|
|
1721
|
+
}
|
|
1722
|
+
},
|
|
1632
1723
|
group(groupId, traits, options, callback) {
|
|
1724
|
+
var _a, _b;
|
|
1725
|
+
if (((_a = jitsuOptions.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = jitsuOptions.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1633
1728
|
if (typeof groupId === "number") {
|
|
1634
1729
|
//fix potential issues with group id being used incorrectly
|
|
1635
1730
|
groupId = groupId + "";
|
|
1636
1731
|
}
|
|
1637
|
-
const
|
|
1638
|
-
const
|
|
1639
|
-
? pluginConfig.storageWrapper(analyticsInstance.storage)
|
|
1640
|
-
: analyticsInstance.storage;
|
|
1641
|
-
const user = analyticsInstance.user();
|
|
1732
|
+
const instance = this.instance;
|
|
1733
|
+
const user = instance.user();
|
|
1642
1734
|
const userId = (options === null || options === void 0 ? void 0 : options.userId) || (user === null || user === void 0 ? void 0 : user.userId);
|
|
1643
|
-
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId) ||
|
|
1644
|
-
|
|
1735
|
+
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId) || storage.getItem("__anon_id");
|
|
1736
|
+
storage.setItem("__group_id", groupId);
|
|
1645
1737
|
if (traits && typeof traits === "object") {
|
|
1646
|
-
|
|
1738
|
+
storage.setItem("__group_traits", traits);
|
|
1647
1739
|
}
|
|
1648
|
-
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})),
|
|
1740
|
+
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})), jitsuOptions, instance, storage);
|
|
1649
1741
|
},
|
|
1650
1742
|
},
|
|
1651
1743
|
};
|
|
@@ -1660,6 +1752,15 @@
|
|
|
1660
1752
|
return (((Math.random() * d * hash(hashString !== null && hashString !== void 0 ? hashString : "", getSeed())) % Number.MAX_SAFE_INTEGER).toString(36) +
|
|
1661
1753
|
((Math.random() * d * hash(hashString !== null && hashString !== void 0 ? hashString : "", getSeed())) % Number.MAX_SAFE_INTEGER).toString(36));
|
|
1662
1754
|
}
|
|
1755
|
+
function uuid() {
|
|
1756
|
+
var u = "", m = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", i = 0, rb = (Math.random() * 0xffffffff) | 0;
|
|
1757
|
+
while (i++ < 36) {
|
|
1758
|
+
var c = m[i - 1], r = rb & 0xf, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
1759
|
+
u += c == "-" || c == "4" ? c : v.toString(16);
|
|
1760
|
+
rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;
|
|
1761
|
+
}
|
|
1762
|
+
return u;
|
|
1763
|
+
}
|
|
1663
1764
|
function hash(str, seed = 0) {
|
|
1664
1765
|
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
1665
1766
|
for (let i = 0, ch; i < str.length; i++) {
|
|
@@ -1705,13 +1806,17 @@
|
|
|
1705
1806
|
return value;
|
|
1706
1807
|
}
|
|
1707
1808
|
function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
1708
|
-
|
|
1809
|
+
var _a, _b;
|
|
1709
1810
|
const storageCache = {};
|
|
1710
1811
|
// AnalyticsInstance's storage is async somewhere inside. So if we make 'page' call right after 'identify' call
|
|
1711
1812
|
// 'page' call will load traits from storage before 'identify' call had a change to save them.
|
|
1712
1813
|
// to avoid that we use in-memory cache for storage
|
|
1713
1814
|
const cachingStorageWrapper = (persistentStorage) => ({
|
|
1714
1815
|
setItem(key, val) {
|
|
1816
|
+
var _a, _b;
|
|
1817
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1715
1820
|
if (opts.debug) {
|
|
1716
1821
|
console.log(`[JITSU DEBUG] Caching storage setItem: ${key}=${val}`);
|
|
1717
1822
|
}
|
|
@@ -1719,6 +1824,10 @@
|
|
|
1719
1824
|
persistentStorage.setItem(key, val);
|
|
1720
1825
|
},
|
|
1721
1826
|
getItem(key) {
|
|
1827
|
+
var _a, _b;
|
|
1828
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1722
1831
|
const value = storageCache[key] || persistentStorage.getItem(key);
|
|
1723
1832
|
if (opts.debug) {
|
|
1724
1833
|
console.log(`[JITSU DEBUG] Caching storage getItem: ${key}=${value}. Evicted from cache: ${!storageCache[key]}`);
|
|
@@ -1729,7 +1838,7 @@
|
|
|
1729
1838
|
for (const key of [...Object.keys(storageCache)]) {
|
|
1730
1839
|
delete storageCache[key];
|
|
1731
1840
|
}
|
|
1732
|
-
|
|
1841
|
+
persistentStorage.reset();
|
|
1733
1842
|
},
|
|
1734
1843
|
removeItem(key) {
|
|
1735
1844
|
if (opts.debug) {
|
|
@@ -1739,12 +1848,13 @@
|
|
|
1739
1848
|
persistentStorage.removeItem(key);
|
|
1740
1849
|
},
|
|
1741
1850
|
});
|
|
1851
|
+
const storage = cachingStorageWrapper(rt.store());
|
|
1742
1852
|
const analytics = analyticsLib({
|
|
1743
1853
|
debug: !!opts.debug,
|
|
1744
1854
|
storage,
|
|
1745
|
-
plugins: [jitsuAnalyticsPlugin(
|
|
1855
|
+
plugins: [jitsuAnalyticsPlugin(opts, storage), ...plugins],
|
|
1746
1856
|
});
|
|
1747
|
-
|
|
1857
|
+
const a = Object.assign(Object.assign({}, analytics), { page: (...args) => {
|
|
1748
1858
|
if (args.length === 2 && typeof args[0] === "string" && typeof args[1] === "object") {
|
|
1749
1859
|
return analytics.page(Object.assign({ name: args[0] }, args[1]));
|
|
1750
1860
|
}
|
|
@@ -1778,7 +1888,7 @@
|
|
|
1778
1888
|
if (opts.debug) {
|
|
1779
1889
|
console.log("[JITSU DEBUG] Setting anonymous id to " + id);
|
|
1780
1890
|
}
|
|
1781
|
-
//Workaround for analytics.js bug. Underlying setAnonymousId doesn't
|
|
1891
|
+
//Workaround for analytics.js bug. Underlying setAnonymousId doesn't set the id immediately,
|
|
1782
1892
|
//so we got to it manually here. See https://github.com/jitsucom/jitsu/issues/1060
|
|
1783
1893
|
storage.setItem("__anon_id", id);
|
|
1784
1894
|
const userState = analytics.user();
|
|
@@ -1799,6 +1909,22 @@
|
|
|
1799
1909
|
}
|
|
1800
1910
|
});
|
|
1801
1911
|
},
|
|
1912
|
+
configure(options) {
|
|
1913
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1914
|
+
var _a, _b;
|
|
1915
|
+
if (opts.debug) {
|
|
1916
|
+
console.log("[JITSU DEBUG] Update Jitsu config with", JSON.stringify(options));
|
|
1917
|
+
}
|
|
1918
|
+
if (((_a = options.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = options.privacy) === null || _b === void 0 ? void 0 : _b.dontSend)) {
|
|
1919
|
+
storage.reset();
|
|
1920
|
+
}
|
|
1921
|
+
for (const plugin of Object.values(analytics.plugins)) {
|
|
1922
|
+
if (typeof plugin["configure"] === "function") {
|
|
1923
|
+
plugin["configure"](options);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
},
|
|
1802
1928
|
group(groupId, traits, options, callback) {
|
|
1803
1929
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1804
1930
|
const results = [];
|
|
@@ -1812,13 +1938,20 @@
|
|
|
1812
1938
|
return results[0];
|
|
1813
1939
|
});
|
|
1814
1940
|
} });
|
|
1941
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.dontSend)) {
|
|
1942
|
+
storage.reset();
|
|
1943
|
+
}
|
|
1944
|
+
return a;
|
|
1815
1945
|
}
|
|
1816
1946
|
/**
|
|
1817
1947
|
* Fix common mistakes in jitsu configuration
|
|
1818
1948
|
* @param opts
|
|
1819
1949
|
*/
|
|
1820
1950
|
function fixOptions(opts) {
|
|
1821
|
-
|
|
1951
|
+
var _a, _b;
|
|
1952
|
+
return Object.assign(Object.assign({}, opts), { host: ((_a = opts.host) !== null && _a !== void 0 ? _a : "").indexOf("https://") !== 0 && ((_b = opts.host) !== null && _b !== void 0 ? _b : "").indexOf("http://") !== 0
|
|
1953
|
+
? `https://${opts.host}`
|
|
1954
|
+
: opts.host });
|
|
1822
1955
|
}
|
|
1823
1956
|
function jitsuAnalytics(_opts) {
|
|
1824
1957
|
const opts = fixOptions(_opts);
|
|
@@ -1848,35 +1981,53 @@
|
|
|
1848
1981
|
// result.loaded(createUnderlyingAnalyticsInstance(opts, rt));
|
|
1849
1982
|
// }
|
|
1850
1983
|
}
|
|
1851
|
-
function uuid() {
|
|
1852
|
-
var u = "", m = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", i = 0, rb = (Math.random() * 0xffffffff) | 0;
|
|
1853
|
-
while (i++ < 36) {
|
|
1854
|
-
var c = m[i - 1], r = rb & 0xf, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
1855
|
-
u += c == "-" || c == "4" ? c : v.toString(16);
|
|
1856
|
-
rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;
|
|
1857
|
-
}
|
|
1858
|
-
return u;
|
|
1859
|
-
}
|
|
1860
1984
|
|
|
1861
1985
|
function snakeToCamel(s) {
|
|
1862
1986
|
return s.replace(/([-_][a-z])/gi, $1 => {
|
|
1863
1987
|
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
1864
1988
|
});
|
|
1865
1989
|
}
|
|
1866
|
-
const
|
|
1990
|
+
const trimPrefix = (s, prefix) => s.replace(new RegExp(`^${prefix}`), "");
|
|
1991
|
+
const defaultParser = (nestedPath = []) => ({
|
|
1992
|
+
path: (name) => [
|
|
1993
|
+
...nestedPath,
|
|
1994
|
+
snakeToCamel(nestedPath.length > 0 ? trimPrefix(name, nestedPath.join("-") + "-") : name),
|
|
1995
|
+
],
|
|
1996
|
+
parse: (arg) => arg,
|
|
1997
|
+
});
|
|
1998
|
+
const booleanParser = (nestedPath = []) => (Object.assign(Object.assign({}, defaultParser(nestedPath)), { parse: (arg) => arg === "true" || arg === "1" || arg === "yes" }));
|
|
1867
1999
|
const parsers = {
|
|
1868
|
-
debug: booleanParser,
|
|
1869
|
-
|
|
2000
|
+
debug: booleanParser(),
|
|
2001
|
+
"privacy-disable-user-ids": booleanParser(["privacy"]),
|
|
2002
|
+
"privacy-dont-send": booleanParser(["privacy"]),
|
|
2003
|
+
"privacy-ip-policy": defaultParser(["privacy"]),
|
|
2004
|
+
"echo-events": booleanParser(),
|
|
2005
|
+
"init-only": booleanParser(),
|
|
1870
2006
|
};
|
|
1871
2007
|
function getParser(name) {
|
|
1872
|
-
return parsers[name] || (
|
|
2008
|
+
return parsers[name] || defaultParser();
|
|
2009
|
+
}
|
|
2010
|
+
function setPath(obj, path, value) {
|
|
2011
|
+
let current = obj;
|
|
2012
|
+
let i = 0;
|
|
2013
|
+
for (; i < path.length - 1; i++) {
|
|
2014
|
+
const key = path[i];
|
|
2015
|
+
current[key] = current[key] || {};
|
|
2016
|
+
current = current[key];
|
|
2017
|
+
}
|
|
2018
|
+
current[path[i]] = value;
|
|
1873
2019
|
}
|
|
1874
2020
|
function getScriptAttributes(scriptElement) {
|
|
1875
2021
|
return scriptElement
|
|
1876
2022
|
.getAttributeNames()
|
|
1877
2023
|
.filter(name => name.indexOf("data-") === 0)
|
|
1878
2024
|
.map(name => name.substring("data-".length))
|
|
1879
|
-
.reduce((res, name) =>
|
|
2025
|
+
.reduce((res, name) => {
|
|
2026
|
+
const parser = getParser(name);
|
|
2027
|
+
const path = parser.path(name);
|
|
2028
|
+
setPath(res, path, parser.parse(scriptElement.getAttribute(`data-${name}`)));
|
|
2029
|
+
return res;
|
|
2030
|
+
}, {});
|
|
1880
2031
|
}
|
|
1881
2032
|
function runCallback(callback, jitsu) {
|
|
1882
2033
|
if (typeof callback === "function") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/js",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
6
|
"main": "dist/jitsu.cjs.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"private": false,
|
|
14
14
|
"devDependencies": {
|
|
15
|
+
"tslib": "^2.6.3",
|
|
15
16
|
"@playwright/test": "1.39.0",
|
|
16
17
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
17
18
|
"@rollup/plugin-json": "^5.0.1",
|
|
@@ -34,8 +35,8 @@
|
|
|
34
35
|
"rollup": "^3.2.5",
|
|
35
36
|
"ts-jest": "29.0.5",
|
|
36
37
|
"typescript": "^5.5.4",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
38
|
+
"@jitsu/protocols": "1.9.8",
|
|
39
|
+
"jsondiffpatch": "1.9.8"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"analytics": "0.8.9"
|