@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/jitsu.es.js
CHANGED
|
@@ -1049,6 +1049,37 @@ const defaultConfig = {
|
|
|
1049
1049
|
fetchTimeoutMs: undefined,
|
|
1050
1050
|
s2s: undefined,
|
|
1051
1051
|
idEndpoint: undefined,
|
|
1052
|
+
privacy: {
|
|
1053
|
+
dontSend: false,
|
|
1054
|
+
disableUserIds: false,
|
|
1055
|
+
ipPolicy: "keep",
|
|
1056
|
+
consentCategories: undefined,
|
|
1057
|
+
},
|
|
1058
|
+
};
|
|
1059
|
+
// mergeConfig merges newConfig into currentConfig also making sure that all undefined values are replaced with defaultConfig values
|
|
1060
|
+
const mergeConfig = (current, newConfig) => {
|
|
1061
|
+
for (const key of Object.keys(defaultConfig)) {
|
|
1062
|
+
const value = newConfig[key];
|
|
1063
|
+
if (key === "privacy") {
|
|
1064
|
+
if (typeof value === "object") {
|
|
1065
|
+
current.privacy = Object.assign(Object.assign(Object.assign({}, defaultConfig.privacy), current.privacy), value);
|
|
1066
|
+
}
|
|
1067
|
+
else if (newConfig.hasOwnProperty("privacy") && typeof value === "undefined") {
|
|
1068
|
+
// explicitly set to undefined - reset to default
|
|
1069
|
+
current.privacy = Object.assign({}, defaultConfig.privacy);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
else if (typeof value === "undefined") {
|
|
1073
|
+
if (newConfig.hasOwnProperty(key) || !current.hasOwnProperty(key)) {
|
|
1074
|
+
// explicitly set to undefined - reset to default
|
|
1075
|
+
// or was not set at all - set to default
|
|
1076
|
+
current[key] = defaultConfig[key];
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
current[key] = value;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1052
1083
|
};
|
|
1053
1084
|
const parseQuery = (qs) => {
|
|
1054
1085
|
if (!qs) {
|
|
@@ -1156,10 +1187,19 @@ const defaultCookie2Key = {
|
|
|
1156
1187
|
__anon_id: "__eventn_id",
|
|
1157
1188
|
__user_traits: "__eventn_id_usr",
|
|
1158
1189
|
__user_id: "__eventn_uid",
|
|
1190
|
+
__group_id: "__group_id",
|
|
1191
|
+
__group_traits: "__group_traits",
|
|
1159
1192
|
};
|
|
1160
1193
|
const cookieStorage = (cookieDomain, key2cookie) => {
|
|
1161
1194
|
return {
|
|
1162
1195
|
setItem(key, val) {
|
|
1196
|
+
if (typeof val === "undefined") {
|
|
1197
|
+
removeCookie(key2cookie[key] || key, {
|
|
1198
|
+
domain: cookieDomain,
|
|
1199
|
+
secure: window.location.protocol === "https:",
|
|
1200
|
+
});
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1163
1203
|
const strVal = typeof val === "object" && val !== null ? encodeURIComponent(JSON.stringify(val)) : val;
|
|
1164
1204
|
const cookieName = key2cookie[key] || key;
|
|
1165
1205
|
setCookie(cookieName, strVal, {
|
|
@@ -1267,7 +1307,12 @@ const emptyRuntime = (config) => ({
|
|
|
1267
1307
|
if (config.debug) {
|
|
1268
1308
|
console.log(`[JITSU EMPTY RUNTIME] Set storage item ${key}=${JSON.stringify(val)}`);
|
|
1269
1309
|
}
|
|
1270
|
-
|
|
1310
|
+
if (typeof val === "undefined") {
|
|
1311
|
+
delete storage[key];
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
storage[key] = val;
|
|
1315
|
+
}
|
|
1271
1316
|
},
|
|
1272
1317
|
getItem(key) {
|
|
1273
1318
|
const val = storage[key];
|
|
@@ -1340,7 +1385,7 @@ function urlPath(url) {
|
|
|
1340
1385
|
return "/" + pathMatch;
|
|
1341
1386
|
}
|
|
1342
1387
|
function adjustPayload(payload, config, storage, s2s) {
|
|
1343
|
-
var _a, _b;
|
|
1388
|
+
var _a, _b, _c, _d, _e;
|
|
1344
1389
|
const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
|
|
1345
1390
|
const url = runtime.pageUrl();
|
|
1346
1391
|
const parsedUrl = safeCall(() => new URL(url), undefined);
|
|
@@ -1357,8 +1402,13 @@ function adjustPayload(payload, config, storage, s2s) {
|
|
|
1357
1402
|
library: {
|
|
1358
1403
|
name: jitsuLibraryName,
|
|
1359
1404
|
version: jitsuVersion,
|
|
1360
|
-
env:
|
|
1405
|
+
env: isInBrowser() ? "browser" : "node",
|
|
1361
1406
|
},
|
|
1407
|
+
consent: ((_c = config.privacy) === null || _c === void 0 ? void 0 : _c.consentCategories)
|
|
1408
|
+
? {
|
|
1409
|
+
categoryPreferences: config.privacy.consentCategories,
|
|
1410
|
+
}
|
|
1411
|
+
: undefined,
|
|
1362
1412
|
userAgent: runtime.userAgent(),
|
|
1363
1413
|
locale: runtime.language(),
|
|
1364
1414
|
screen: runtime.screen(),
|
|
@@ -1373,12 +1423,19 @@ function adjustPayload(payload, config, storage, s2s) {
|
|
|
1373
1423
|
url: properties.url || url,
|
|
1374
1424
|
encoding: properties.encoding || runtime.documentEncoding(),
|
|
1375
1425
|
},
|
|
1376
|
-
clientIds:
|
|
1426
|
+
clientIds: !((_d = config.privacy) === null || _d === void 0 ? void 0 : _d.disableUserIds)
|
|
1427
|
+
? Object.assign({ fbc: runtime.getCookie("_fbc"), fbp: runtime.getCookie("_fbp") }, getGa4Ids(runtime)) : undefined,
|
|
1377
1428
|
campaign: parseUtms(query),
|
|
1378
1429
|
};
|
|
1379
1430
|
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) });
|
|
1380
1431
|
delete withContext.meta;
|
|
1381
1432
|
delete withContext.options;
|
|
1433
|
+
if ((_e = config.privacy) === null || _e === void 0 ? void 0 : _e.disableUserIds) {
|
|
1434
|
+
delete withContext.userId;
|
|
1435
|
+
delete withContext.anonymousId;
|
|
1436
|
+
delete withContext.context.traits;
|
|
1437
|
+
delete withContext.groupId;
|
|
1438
|
+
}
|
|
1382
1439
|
return withContext;
|
|
1383
1440
|
}
|
|
1384
1441
|
function isDiff(obj) {
|
|
@@ -1484,11 +1541,12 @@ function maskWriteKey(writeKey) {
|
|
|
1484
1541
|
}
|
|
1485
1542
|
function send(method, payload, jitsuConfig, instance, store) {
|
|
1486
1543
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1544
|
+
var _a, _b;
|
|
1487
1545
|
if (jitsuConfig.echoEvents) {
|
|
1488
1546
|
console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
|
|
1489
1547
|
return;
|
|
1490
1548
|
}
|
|
1491
|
-
const s2s = jitsuConfig.s2s
|
|
1549
|
+
const s2s = !!jitsuConfig.s2s;
|
|
1492
1550
|
const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
|
|
1493
1551
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
1494
1552
|
if (!fetch) {
|
|
@@ -1498,7 +1556,7 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
1498
1556
|
// if (jitsuConfig.debug) {
|
|
1499
1557
|
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
1500
1558
|
// }
|
|
1501
|
-
const adjustedPayload = adjustPayload(payload, jitsuConfig, store
|
|
1559
|
+
const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
|
|
1502
1560
|
const abortController = jitsuConfig.fetchTimeoutMs ? new AbortController() : undefined;
|
|
1503
1561
|
const abortTimeout = jitsuConfig.fetchTimeoutMs
|
|
1504
1562
|
? setTimeout(() => {
|
|
@@ -1506,11 +1564,14 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
1506
1564
|
}, jitsuConfig.fetchTimeoutMs)
|
|
1507
1565
|
: undefined;
|
|
1508
1566
|
const authHeader = jitsuConfig.writeKey ? { "X-Write-Key": jitsuConfig.writeKey } : {};
|
|
1567
|
+
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"
|
|
1568
|
+
? {}
|
|
1569
|
+
: { "X-IP-Policy": jitsuConfig.privacy.ipPolicy };
|
|
1509
1570
|
let fetchResult;
|
|
1510
1571
|
try {
|
|
1511
1572
|
fetchResult = yield fetch(url, {
|
|
1512
1573
|
method: "POST",
|
|
1513
|
-
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|
|
1574
|
+
headers: Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader), ipHeader),
|
|
1514
1575
|
body: JSON.stringify(adjustedPayload),
|
|
1515
1576
|
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
1516
1577
|
});
|
|
@@ -1558,11 +1619,12 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
1558
1619
|
return adjustedPayload;
|
|
1559
1620
|
});
|
|
1560
1621
|
}
|
|
1561
|
-
const jitsuAnalyticsPlugin = (
|
|
1562
|
-
|
|
1622
|
+
const jitsuAnalyticsPlugin = (jitsuOptions = {}, storage) => {
|
|
1623
|
+
// just to make sure that all undefined values are replaced with defaultConfig values
|
|
1624
|
+
mergeConfig(jitsuOptions, jitsuOptions);
|
|
1563
1625
|
return {
|
|
1564
1626
|
name: "jitsu",
|
|
1565
|
-
config:
|
|
1627
|
+
config: jitsuOptions,
|
|
1566
1628
|
initialize: (args) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
1567
1629
|
const { config } = args;
|
|
1568
1630
|
if (config.debug) {
|
|
@@ -1599,17 +1661,28 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
1599
1661
|
}
|
|
1600
1662
|
}),
|
|
1601
1663
|
page: args => {
|
|
1664
|
+
var _a;
|
|
1602
1665
|
const { payload, config, instance } = args;
|
|
1603
|
-
|
|
1666
|
+
if ((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) {
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
return send("page", payload, config, instance, storage);
|
|
1604
1670
|
},
|
|
1605
1671
|
track: args => {
|
|
1672
|
+
var _a;
|
|
1606
1673
|
const { payload, config, instance } = args;
|
|
1607
|
-
|
|
1674
|
+
if ((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) {
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
return send("track", payload, config, instance, storage);
|
|
1608
1678
|
},
|
|
1609
1679
|
identify: args => {
|
|
1680
|
+
var _a, _b;
|
|
1610
1681
|
const { payload, config, instance } = args;
|
|
1682
|
+
if (((_a = config.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = config.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1611
1685
|
// Store traits in cache to be able to use them in page and track events that run asynchronously with current identify.
|
|
1612
|
-
const storage = pluginConfig.storageWrapper ? pluginConfig.storageWrapper(instance.storage) : instance.storage;
|
|
1613
1686
|
storage.setItem("__user_id", payload.userId);
|
|
1614
1687
|
if (payload.traits && typeof payload.traits === "object") {
|
|
1615
1688
|
storage.setItem("__user_traits", payload.traits);
|
|
@@ -1618,31 +1691,50 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
1618
1691
|
},
|
|
1619
1692
|
reset: args => {
|
|
1620
1693
|
const { config, instance } = args;
|
|
1621
|
-
|
|
1622
|
-
storage === null || storage === void 0 ? void 0 : storage.reset();
|
|
1694
|
+
storage.reset();
|
|
1623
1695
|
if (config.debug) {
|
|
1624
1696
|
console.log("[JITSU DEBUG] Resetting Jitsu plugin storage");
|
|
1625
1697
|
}
|
|
1626
1698
|
},
|
|
1627
1699
|
methods: {
|
|
1628
1700
|
//analytics doesn't support group as a base method, so we need to add it manually
|
|
1701
|
+
configure(newOptions) {
|
|
1702
|
+
var _a, _b, _c, _d;
|
|
1703
|
+
const idsWasDisabled = ((_a = jitsuOptions.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = jitsuOptions.privacy) === null || _b === void 0 ? void 0 : _b.dontSend);
|
|
1704
|
+
mergeConfig(jitsuOptions, newOptions);
|
|
1705
|
+
const idsDisabledNow = ((_c = jitsuOptions.privacy) === null || _c === void 0 ? void 0 : _c.disableUserIds) || ((_d = jitsuOptions.privacy) === null || _d === void 0 ? void 0 : _d.dontSend);
|
|
1706
|
+
if (!idsDisabledNow && idsWasDisabled) {
|
|
1707
|
+
if (jitsuOptions.debug) {
|
|
1708
|
+
console.log("[JITSU] Enabling Anonymous ID. Generating new Id.");
|
|
1709
|
+
}
|
|
1710
|
+
const instance = this.instance;
|
|
1711
|
+
const newAnonymousId = uuid();
|
|
1712
|
+
const userState = instance.user();
|
|
1713
|
+
if (userState) {
|
|
1714
|
+
userState.anonymousId = newAnonymousId;
|
|
1715
|
+
}
|
|
1716
|
+
storage.setItem("__anon_id", newAnonymousId);
|
|
1717
|
+
instance.setAnonymousId(newAnonymousId);
|
|
1718
|
+
}
|
|
1719
|
+
},
|
|
1629
1720
|
group(groupId, traits, options, callback) {
|
|
1721
|
+
var _a, _b;
|
|
1722
|
+
if (((_a = jitsuOptions.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = jitsuOptions.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1630
1725
|
if (typeof groupId === "number") {
|
|
1631
1726
|
//fix potential issues with group id being used incorrectly
|
|
1632
1727
|
groupId = groupId + "";
|
|
1633
1728
|
}
|
|
1634
|
-
const
|
|
1635
|
-
const
|
|
1636
|
-
? pluginConfig.storageWrapper(analyticsInstance.storage)
|
|
1637
|
-
: analyticsInstance.storage;
|
|
1638
|
-
const user = analyticsInstance.user();
|
|
1729
|
+
const instance = this.instance;
|
|
1730
|
+
const user = instance.user();
|
|
1639
1731
|
const userId = (options === null || options === void 0 ? void 0 : options.userId) || (user === null || user === void 0 ? void 0 : user.userId);
|
|
1640
|
-
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId) ||
|
|
1641
|
-
|
|
1732
|
+
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId) || storage.getItem("__anon_id");
|
|
1733
|
+
storage.setItem("__group_id", groupId);
|
|
1642
1734
|
if (traits && typeof traits === "object") {
|
|
1643
|
-
|
|
1735
|
+
storage.setItem("__group_traits", traits);
|
|
1644
1736
|
}
|
|
1645
|
-
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})),
|
|
1737
|
+
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})), jitsuOptions, instance, storage);
|
|
1646
1738
|
},
|
|
1647
1739
|
},
|
|
1648
1740
|
};
|
|
@@ -1657,6 +1749,15 @@ function randomId(hashString = "") {
|
|
|
1657
1749
|
return (((Math.random() * d * hash(hashString !== null && hashString !== void 0 ? hashString : "", getSeed())) % Number.MAX_SAFE_INTEGER).toString(36) +
|
|
1658
1750
|
((Math.random() * d * hash(hashString !== null && hashString !== void 0 ? hashString : "", getSeed())) % Number.MAX_SAFE_INTEGER).toString(36));
|
|
1659
1751
|
}
|
|
1752
|
+
function uuid() {
|
|
1753
|
+
var u = "", m = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", i = 0, rb = (Math.random() * 0xffffffff) | 0;
|
|
1754
|
+
while (i++ < 36) {
|
|
1755
|
+
var c = m[i - 1], r = rb & 0xf, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
1756
|
+
u += c == "-" || c == "4" ? c : v.toString(16);
|
|
1757
|
+
rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;
|
|
1758
|
+
}
|
|
1759
|
+
return u;
|
|
1760
|
+
}
|
|
1660
1761
|
function hash(str, seed = 0) {
|
|
1661
1762
|
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
1662
1763
|
for (let i = 0, ch; i < str.length; i++) {
|
|
@@ -1709,15 +1810,20 @@ const emptyAnalytics = {
|
|
|
1709
1810
|
identify: () => Promise.resolve({}),
|
|
1710
1811
|
group: () => Promise.resolve({}),
|
|
1711
1812
|
reset: () => Promise.resolve({}),
|
|
1813
|
+
configure: () => { },
|
|
1712
1814
|
};
|
|
1713
1815
|
function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
1714
|
-
|
|
1816
|
+
var _a, _b;
|
|
1715
1817
|
const storageCache = {};
|
|
1716
1818
|
// AnalyticsInstance's storage is async somewhere inside. So if we make 'page' call right after 'identify' call
|
|
1717
1819
|
// 'page' call will load traits from storage before 'identify' call had a change to save them.
|
|
1718
1820
|
// to avoid that we use in-memory cache for storage
|
|
1719
1821
|
const cachingStorageWrapper = (persistentStorage) => ({
|
|
1720
1822
|
setItem(key, val) {
|
|
1823
|
+
var _a, _b;
|
|
1824
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1721
1827
|
if (opts.debug) {
|
|
1722
1828
|
console.log(`[JITSU DEBUG] Caching storage setItem: ${key}=${val}`);
|
|
1723
1829
|
}
|
|
@@ -1725,6 +1831,10 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1725
1831
|
persistentStorage.setItem(key, val);
|
|
1726
1832
|
},
|
|
1727
1833
|
getItem(key) {
|
|
1834
|
+
var _a, _b;
|
|
1835
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.dontSend) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.disableUserIds)) {
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1728
1838
|
const value = storageCache[key] || persistentStorage.getItem(key);
|
|
1729
1839
|
if (opts.debug) {
|
|
1730
1840
|
console.log(`[JITSU DEBUG] Caching storage getItem: ${key}=${value}. Evicted from cache: ${!storageCache[key]}`);
|
|
@@ -1735,7 +1845,7 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1735
1845
|
for (const key of [...Object.keys(storageCache)]) {
|
|
1736
1846
|
delete storageCache[key];
|
|
1737
1847
|
}
|
|
1738
|
-
|
|
1848
|
+
persistentStorage.reset();
|
|
1739
1849
|
},
|
|
1740
1850
|
removeItem(key) {
|
|
1741
1851
|
if (opts.debug) {
|
|
@@ -1745,12 +1855,13 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1745
1855
|
persistentStorage.removeItem(key);
|
|
1746
1856
|
},
|
|
1747
1857
|
});
|
|
1858
|
+
const storage = cachingStorageWrapper(rt.store());
|
|
1748
1859
|
const analytics = analyticsLib({
|
|
1749
1860
|
debug: !!opts.debug,
|
|
1750
1861
|
storage,
|
|
1751
|
-
plugins: [jitsuAnalyticsPlugin(
|
|
1862
|
+
plugins: [jitsuAnalyticsPlugin(opts, storage), ...plugins],
|
|
1752
1863
|
});
|
|
1753
|
-
|
|
1864
|
+
const a = Object.assign(Object.assign({}, analytics), { page: (...args) => {
|
|
1754
1865
|
if (args.length === 2 && typeof args[0] === "string" && typeof args[1] === "object") {
|
|
1755
1866
|
return analytics.page(Object.assign({ name: args[0] }, args[1]));
|
|
1756
1867
|
}
|
|
@@ -1784,7 +1895,7 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1784
1895
|
if (opts.debug) {
|
|
1785
1896
|
console.log("[JITSU DEBUG] Setting anonymous id to " + id);
|
|
1786
1897
|
}
|
|
1787
|
-
//Workaround for analytics.js bug. Underlying setAnonymousId doesn't
|
|
1898
|
+
//Workaround for analytics.js bug. Underlying setAnonymousId doesn't set the id immediately,
|
|
1788
1899
|
//so we got to it manually here. See https://github.com/jitsucom/jitsu/issues/1060
|
|
1789
1900
|
storage.setItem("__anon_id", id);
|
|
1790
1901
|
const userState = analytics.user();
|
|
@@ -1805,6 +1916,22 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1805
1916
|
}
|
|
1806
1917
|
});
|
|
1807
1918
|
},
|
|
1919
|
+
configure(options) {
|
|
1920
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1921
|
+
var _a, _b;
|
|
1922
|
+
if (opts.debug) {
|
|
1923
|
+
console.log("[JITSU DEBUG] Update Jitsu config with", JSON.stringify(options));
|
|
1924
|
+
}
|
|
1925
|
+
if (((_a = options.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = options.privacy) === null || _b === void 0 ? void 0 : _b.dontSend)) {
|
|
1926
|
+
storage.reset();
|
|
1927
|
+
}
|
|
1928
|
+
for (const plugin of Object.values(analytics.plugins)) {
|
|
1929
|
+
if (typeof plugin["configure"] === "function") {
|
|
1930
|
+
plugin["configure"](options);
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
},
|
|
1808
1935
|
group(groupId, traits, options, callback) {
|
|
1809
1936
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1810
1937
|
const results = [];
|
|
@@ -1818,13 +1945,20 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
1818
1945
|
return results[0];
|
|
1819
1946
|
});
|
|
1820
1947
|
} });
|
|
1948
|
+
if (((_a = opts.privacy) === null || _a === void 0 ? void 0 : _a.disableUserIds) || ((_b = opts.privacy) === null || _b === void 0 ? void 0 : _b.dontSend)) {
|
|
1949
|
+
storage.reset();
|
|
1950
|
+
}
|
|
1951
|
+
return a;
|
|
1821
1952
|
}
|
|
1822
1953
|
/**
|
|
1823
1954
|
* Fix common mistakes in jitsu configuration
|
|
1824
1955
|
* @param opts
|
|
1825
1956
|
*/
|
|
1826
1957
|
function fixOptions(opts) {
|
|
1827
|
-
|
|
1958
|
+
var _a, _b;
|
|
1959
|
+
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
|
|
1960
|
+
? `https://${opts.host}`
|
|
1961
|
+
: opts.host });
|
|
1828
1962
|
}
|
|
1829
1963
|
function jitsuAnalytics(_opts) {
|
|
1830
1964
|
const opts = fixOptions(_opts);
|
|
@@ -1854,14 +1988,5 @@ function jitsuAnalytics(_opts) {
|
|
|
1854
1988
|
// result.loaded(createUnderlyingAnalyticsInstance(opts, rt));
|
|
1855
1989
|
// }
|
|
1856
1990
|
}
|
|
1857
|
-
function uuid() {
|
|
1858
|
-
var u = "", m = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", i = 0, rb = (Math.random() * 0xffffffff) | 0;
|
|
1859
|
-
while (i++ < 36) {
|
|
1860
|
-
var c = m[i - 1], r = rb & 0xf, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
1861
|
-
u += c == "-" || c == "4" ? c : v.toString(16);
|
|
1862
|
-
rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;
|
|
1863
|
-
}
|
|
1864
|
-
return u;
|
|
1865
|
-
}
|
|
1866
1991
|
|
|
1867
|
-
export { emptyAnalytics, emptyRuntime, isInBrowser, jitsuAnalytics, jitsuAnalyticsPlugin, parseQuery, randomId, windowRuntime };
|
|
1992
|
+
export { emptyAnalytics, emptyRuntime, isInBrowser, jitsuAnalytics, jitsuAnalyticsPlugin, parseQuery, randomId, uuid, windowRuntime };
|