posthog-js-lite 2.3.0 → 2.5.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.5.0 - 2023-12-04
2
+
3
+ 1. Renamed `personProperties` to `setPersonPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
4
+ 2. Renamed `groupProperties` to `setGroupPropertiesForFlags` to match `posthog-js` and more clearly indicated what it does
5
+
6
+ # 2.4.0 - 2023-04-20
7
+
8
+ 1. Fixes a race condition that could occur when initialising PostHog
9
+ 2. Fixes an issue where feature flags would not be reloaded after a reset
10
+
1
11
  # 2.3.0 - 2023-04-19
2
12
 
3
13
  1. Some small fixes to incorrect types
package/lib/index.cjs.js CHANGED
@@ -158,6 +158,8 @@ var PostHogPersistedProperty;
158
158
  PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
159
159
  PostHogPersistedProperty["PersonProperties"] = "person_properties";
160
160
  PostHogPersistedProperty["GroupProperties"] = "group_properties";
161
+ PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
162
+ PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
161
163
  })(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
162
164
 
163
165
  function assert(truthyValue, message) {
@@ -716,7 +718,10 @@ var PostHogFetchHttpError = /** @class */ (function (_super) {
716
718
  var PostHogFetchNetworkError = /** @class */ (function (_super) {
717
719
  __extends(PostHogFetchNetworkError, _super);
718
720
  function PostHogFetchNetworkError(error) {
719
- var _this = _super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
721
+ var _this =
722
+ // TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
723
+ // @ts-ignore
724
+ _super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
720
725
  _this.error = error;
721
726
  _this.name = 'PostHogFetchNetworkError';
722
727
  return _this;
@@ -1132,7 +1137,11 @@ var PostHogCoreStateless = /** @class */ (function () {
1132
1137
  return [4 /*yield*/, this.flushAsync()];
1133
1138
  case 2:
1134
1139
  _a.sent();
1135
- return [4 /*yield*/, Promise.allSettled(Object.values(this.pendingPromises))];
1140
+ return [4 /*yield*/, Promise.all(Object.values(this.pendingPromises).map(function (x) {
1141
+ return x.catch(function () {
1142
+ // ignore errors as we are shutting down and can't deal with them anyways.
1143
+ });
1144
+ }))];
1136
1145
  case 3:
1137
1146
  _a.sent();
1138
1147
  return [3 /*break*/, 5];
@@ -1162,14 +1171,9 @@ var PostHogCore = /** @class */ (function (_super) {
1162
1171
  var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
1163
1172
  _this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
1164
1173
  _this.flagCallReported = {};
1174
+ _this.sessionProps = {};
1165
1175
  _this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
1166
1176
  _this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
1167
- // NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
1168
- if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
1169
- safeSetTimeout(function () {
1170
- _this.reloadFeatureFlags();
1171
- }, 1);
1172
- }
1173
1177
  return _this;
1174
1178
  }
1175
1179
  PostHogCore.prototype.setupBootstrap = function (options) {
@@ -1209,6 +1213,7 @@ var PostHogCore = /** @class */ (function (_super) {
1209
1213
  });
1210
1214
  PostHogCore.prototype.clearProps = function () {
1211
1215
  this.props = undefined;
1216
+ this.sessionProps = {};
1212
1217
  };
1213
1218
  PostHogCore.prototype.on = function (event, cb) {
1214
1219
  return this._events.on(event, cb);
@@ -1236,7 +1241,7 @@ var PostHogCore = /** @class */ (function (_super) {
1236
1241
  return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
1237
1242
  };
1238
1243
  PostHogCore.prototype.enrichProperties = function (properties) {
1239
- return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1244
+ return __assign(__assign(__assign(__assign(__assign({}, this.props), this.sessionProps), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1240
1245
  };
1241
1246
  PostHogCore.prototype.getSessionId = function () {
1242
1247
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
@@ -1262,13 +1267,19 @@ var PostHogCore = /** @class */ (function (_super) {
1262
1267
  PostHogCore.prototype.getDistinctId = function () {
1263
1268
  return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
1264
1269
  };
1270
+ PostHogCore.prototype.unregister = function (property) {
1271
+ delete this.props[property];
1272
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1273
+ };
1265
1274
  PostHogCore.prototype.register = function (properties) {
1266
1275
  this.props = __assign(__assign({}, this.props), properties);
1267
1276
  this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1268
1277
  };
1269
- PostHogCore.prototype.unregister = function (property) {
1270
- delete this.props[property];
1271
- this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1278
+ PostHogCore.prototype.registerForSession = function (properties) {
1279
+ this.sessionProps = __assign(__assign({}, this.sessionProps), properties);
1280
+ };
1281
+ PostHogCore.prototype.unregisterForSession = function (property) {
1282
+ delete this.sessionProps[property];
1272
1283
  };
1273
1284
  /***
1274
1285
  *** TRACKING
@@ -1284,9 +1295,7 @@ var PostHogCore = /** @class */ (function (_super) {
1284
1295
  // We keep the AnonymousId to be used by decide calls and identify to link the previousId
1285
1296
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
1286
1297
  this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
1287
- if (this.getFeatureFlags()) {
1288
- this.reloadFeatureFlags();
1289
- }
1298
+ this.reloadFeatureFlags();
1290
1299
  }
1291
1300
  _super.prototype.identifyStateless.call(this, distinctId, allProperties, options);
1292
1301
  return this;
@@ -1326,7 +1335,7 @@ var PostHogCore = /** @class */ (function (_super) {
1326
1335
  this.register({
1327
1336
  $groups: __assign(__assign({}, existingGroups), groups),
1328
1337
  });
1329
- if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; }) && this.getFeatureFlags()) {
1338
+ if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; })) {
1330
1339
  this.reloadFeatureFlags();
1331
1340
  }
1332
1341
  return this;
@@ -1350,13 +1359,20 @@ var PostHogCore = /** @class */ (function (_super) {
1350
1359
  /***
1351
1360
  * PROPERTIES
1352
1361
  ***/
1353
- PostHogCore.prototype.personProperties = function (properties) {
1362
+ PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
1354
1363
  // Get persisted person properties
1355
1364
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
1356
1365
  this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
1357
1366
  return this;
1358
1367
  };
1359
- PostHogCore.prototype.groupProperties = function (properties) {
1368
+ PostHogCore.prototype.resetPersonPropertiesForFlags = function () {
1369
+ this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {});
1370
+ };
1371
+ /** @deprecated - Renamed to setPersonPropertiesForFlags */
1372
+ PostHogCore.prototype.personProperties = function (properties) {
1373
+ return this.setPersonPropertiesForFlags(properties);
1374
+ };
1375
+ PostHogCore.prototype.setGroupPropertiesForFlags = function (properties) {
1360
1376
  // Get persisted group properties
1361
1377
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
1362
1378
  if (Object.keys(existingProperties).length !== 0) {
@@ -1368,6 +1384,13 @@ var PostHogCore = /** @class */ (function (_super) {
1368
1384
  this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
1369
1385
  return this;
1370
1386
  };
1387
+ PostHogCore.prototype.resetGroupPropertiesForFlags = function () {
1388
+ this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {});
1389
+ };
1390
+ /** @deprecated - Renamed to setGroupPropertiesForFlags */
1391
+ PostHogCore.prototype.groupProperties = function (properties) {
1392
+ return this.setGroupPropertiesForFlags(properties);
1393
+ };
1371
1394
  /***
1372
1395
  *** FEATURE FLAGS
1373
1396
  ***/
@@ -1559,7 +1582,7 @@ var PostHogCore = /** @class */ (function (_super) {
1559
1582
  return PostHogCore;
1560
1583
  }(PostHogCoreStateless));
1561
1584
 
1562
- var version = "2.3.0";
1585
+ var version = "2.5.0";
1563
1586
 
1564
1587
  function getContext(window) {
1565
1588
  var context = {};
@@ -1924,6 +1947,10 @@ function (_super) {
1924
1947
 
1925
1948
  _this.setupBootstrap(options);
1926
1949
 
1950
+ if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
1951
+ _this.reloadFeatureFlags();
1952
+ }
1953
+
1927
1954
  return _this;
1928
1955
  }
1929
1956