posthog-js-lite 2.0.0-alpha1 → 2.0.0-alpha4

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.esm.js CHANGED
@@ -156,7 +156,7 @@ function retriable(fn, props) {
156
156
  return __generator(this, function (_d) {
157
157
  switch (_d.label) {
158
158
  case 0:
159
- _a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ? 1000 : _b, _c = props.retryCheck, retryCheck = _c === void 0 ? function () { return true; } : _c;
159
+ _a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ? 5000 : _b, _c = props.retryCheck, retryCheck = _c === void 0 ? function () { return true; } : _c;
160
160
  lastError = null;
161
161
  i = 0;
162
162
  _d.label = 1;
@@ -670,13 +670,14 @@ var SimpleEventEmitter = /** @class */ (function () {
670
670
  };
671
671
  };
672
672
  SimpleEventEmitter.prototype.emit = function (event, payload) {
673
- if (!this.events[event]) {
674
- return;
675
- }
676
- for (var _i = 0, _a = this.events[event]; _i < _a.length; _i++) {
673
+ for (var _i = 0, _a = this.events[event] || []; _i < _a.length; _i++) {
677
674
  var listener = _a[_i];
678
675
  listener(payload);
679
676
  }
677
+ for (var _b = 0, _c = this.events['*'] || []; _b < _c.length; _b++) {
678
+ var listener = _c[_b];
679
+ listener(event, payload);
680
+ }
680
681
  };
681
682
  return SimpleEventEmitter;
682
683
  }());
@@ -756,6 +757,14 @@ var PostHogCore = /** @class */ (function () {
756
757
  }
757
758
  this.setPersistedProperty(PostHogPersistedProperty.DistinctId, generateUUID(globalThis));
758
759
  };
760
+ PostHogCore.prototype.debug = function (enabled) {
761
+ var _a;
762
+ if (enabled === void 0) { enabled = true; }
763
+ (_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
764
+ if (enabled) {
765
+ this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
766
+ }
767
+ };
759
768
  PostHogCore.prototype.buildPayload = function (payload) {
760
769
  return {
761
770
  distinct_id: payload.distinct_id || this.getDistinctId(),
@@ -773,6 +782,9 @@ var PostHogCore = /** @class */ (function () {
773
782
  this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
774
783
  return sessionId;
775
784
  };
785
+ PostHogCore.prototype.resetSessionId = function () {
786
+ this.setPersistedProperty(PostHogPersistedProperty.SessionId, null);
787
+ };
776
788
  PostHogCore.prototype.getDistinctId = function () {
777
789
  var distinctId = this.getPersistedProperty(PostHogPersistedProperty.DistinctId);
778
790
  if (!distinctId) {
@@ -1109,9 +1121,8 @@ var PostHogCore = /** @class */ (function () {
1109
1121
  return PostHogCore;
1110
1122
  }());
1111
1123
 
1112
- // TODO: Get this from package.json
1124
+ var version = "2.0.0-alpha4";
1113
1125
 
1114
- var version$1 = '2.0.0-alpha';
1115
1126
  function getContext(window) {
1116
1127
  var context = {};
1117
1128
 
@@ -1135,7 +1146,7 @@ function getContext(window) {
1135
1146
 
1136
1147
  context = __assign(__assign({}, context), {
1137
1148
  $lib: 'js',
1138
- $lib_version: version$1,
1149
+ $lib_version: version,
1139
1150
  $insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
1140
1151
  $time: currentTimestamp() / 1000
1141
1152
  });
@@ -1311,7 +1322,7 @@ var cookieStore = {
1311
1322
  var cdomain = '',
1312
1323
  expires = '',
1313
1324
  secure = '';
1314
- var new_cookie_val = key + '=' + encodeURIComponent(JSON.stringify(value)) + expires + '; path=/' + cdomain + secure;
1325
+ var new_cookie_val = key + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1315
1326
  document.cookie = new_cookie_val;
1316
1327
  } catch (err) {
1317
1328
  return;
@@ -1351,7 +1362,7 @@ var createStorageLike = function (store) {
1351
1362
  return store.getItem(key);
1352
1363
  },
1353
1364
  setItem: function (key, value) {
1354
- store.setItem(key, JSON.stringify(value));
1365
+ store.setItem(key, value);
1355
1366
  },
1356
1367
  removeItem: function (key) {
1357
1368
  store.removeItem(key);
@@ -1401,8 +1412,6 @@ var checkStoreIsSupported = function (storage, key) {
1401
1412
  var localStore = checkStoreIsSupported(_localStore) ? _localStore : undefined;
1402
1413
  var sessionStorage = checkStoreIsSupported(_sessionStore) ? _sessionStore : undefined;
1403
1414
 
1404
- var version = "2.0.0-alpha1";
1405
-
1406
1415
  var PostHog =
1407
1416
  /** @class */
1408
1417
  function (_super) {
@@ -1432,13 +1441,11 @@ function (_super) {
1432
1441
 
1433
1442
  if (value === null) {
1434
1443
  delete this._storageCache[key];
1435
-
1436
- this._storage.removeItem(this._storageKey);
1437
1444
  } else {
1438
1445
  this._storageCache[key] = value;
1439
-
1440
- this._storage.setItem(this._storageKey, JSON.stringify(this._storageCache));
1441
1446
  }
1447
+
1448
+ this._storage.setItem(this._storageKey, JSON.stringify(this._storageCache));
1442
1449
  };
1443
1450
 
1444
1451
  PostHog.prototype.fetch = function (url, options) {
@@ -1446,7 +1453,7 @@ function (_super) {
1446
1453
  };
1447
1454
 
1448
1455
  PostHog.prototype.getLibraryId = function () {
1449
- return 'posthog-web';
1456
+ return 'posthog-js-lite';
1450
1457
  };
1451
1458
 
1452
1459
  PostHog.prototype.getLibraryVersion = function () {