posthog-js-lite 2.0.0-alpha4 → 2.0.0-alpha5
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.cjs.js +52 -3
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +5 -3
- package/lib/index.esm.js +52 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-web/src/posthog-web.d.ts +2 -5
- package/lib/posthog-web/src/storage.d.ts +2 -0
- package/lib/posthog-web/src/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/posthog-web.ts +4 -8
- package/src/storage.ts +48 -0
- package/src/types.ts +7 -0
package/lib/index.esm.js
CHANGED
|
@@ -1121,7 +1121,7 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1121
1121
|
return PostHogCore;
|
|
1122
1122
|
}());
|
|
1123
1123
|
|
|
1124
|
-
var version = "2.0.0-
|
|
1124
|
+
var version = "2.0.0-alpha5";
|
|
1125
1125
|
|
|
1126
1126
|
function getContext(window) {
|
|
1127
1127
|
var context = {};
|
|
@@ -1412,17 +1412,66 @@ var checkStoreIsSupported = function (storage, key) {
|
|
|
1412
1412
|
var localStore = checkStoreIsSupported(_localStore) ? _localStore : undefined;
|
|
1413
1413
|
var sessionStorage = checkStoreIsSupported(_sessionStore) ? _sessionStore : undefined;
|
|
1414
1414
|
|
|
1415
|
+
var createMemoryStorage = function () {
|
|
1416
|
+
var _cache = {};
|
|
1417
|
+
var store = {
|
|
1418
|
+
getItem: function (key) {
|
|
1419
|
+
return _cache[key];
|
|
1420
|
+
},
|
|
1421
|
+
setItem: function (key, value) {
|
|
1422
|
+
_cache[key] = value !== null ? value : undefined;
|
|
1423
|
+
},
|
|
1424
|
+
removeItem: function (key) {
|
|
1425
|
+
delete _cache[key];
|
|
1426
|
+
},
|
|
1427
|
+
clear: function () {
|
|
1428
|
+
for (var key in _cache) {
|
|
1429
|
+
delete _cache[key];
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
getAllKeys: function () {
|
|
1433
|
+
var keys = [];
|
|
1434
|
+
|
|
1435
|
+
for (var key in _cache) {
|
|
1436
|
+
keys.push(key);
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
return keys;
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
return store;
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1445
|
+
var getStorage = function (type) {
|
|
1446
|
+
switch (type) {
|
|
1447
|
+
case 'cookie':
|
|
1448
|
+
return cookieStore || localStore || sessionStorage || createMemoryStorage();
|
|
1449
|
+
|
|
1450
|
+
case 'localStorage':
|
|
1451
|
+
return localStore || sessionStorage || createMemoryStorage();
|
|
1452
|
+
|
|
1453
|
+
case 'sessionStorage':
|
|
1454
|
+
return sessionStorage || createMemoryStorage();
|
|
1455
|
+
|
|
1456
|
+
case 'memory':
|
|
1457
|
+
return createMemoryStorage();
|
|
1458
|
+
|
|
1459
|
+
default:
|
|
1460
|
+
return createMemoryStorage();
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1415
1464
|
var PostHog =
|
|
1416
1465
|
/** @class */
|
|
1417
1466
|
function (_super) {
|
|
1418
1467
|
__extends(PostHog, _super);
|
|
1419
1468
|
|
|
1420
1469
|
function PostHog(apiKey, options) {
|
|
1421
|
-
var _this = _super.call(this, apiKey, options) || this;
|
|
1470
|
+
var _this = _super.call(this, apiKey, options) || this; // posthog-js stores options in one object on
|
|
1422
1471
|
|
|
1423
|
-
_this._storage = localStore || sessionStorage || cookieStore; // posthog-js stores options in one object on
|
|
1424
1472
|
|
|
1425
1473
|
_this._storageKey = (options === null || options === void 0 ? void 0 : options.persistence_name) ? "ph_".concat(options.persistence_name) : "ph_".concat(apiKey, "_posthog");
|
|
1474
|
+
_this._storage = getStorage((options === null || options === void 0 ? void 0 : options.persistence) || 'localStorage');
|
|
1426
1475
|
return _this;
|
|
1427
1476
|
}
|
|
1428
1477
|
|