posthog-js-lite 2.4.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,8 @@
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
+
1
6
  # 2.4.0 - 2023-04-20
2
7
 
3
8
  1. Fixes a race condition that could occur when initialising PostHog
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;
@@ -1166,6 +1171,7 @@ var PostHogCore = /** @class */ (function (_super) {
1166
1171
  var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
1167
1172
  _this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
1168
1173
  _this.flagCallReported = {};
1174
+ _this.sessionProps = {};
1169
1175
  _this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
1170
1176
  _this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
1171
1177
  return _this;
@@ -1207,6 +1213,7 @@ var PostHogCore = /** @class */ (function (_super) {
1207
1213
  });
1208
1214
  PostHogCore.prototype.clearProps = function () {
1209
1215
  this.props = undefined;
1216
+ this.sessionProps = {};
1210
1217
  };
1211
1218
  PostHogCore.prototype.on = function (event, cb) {
1212
1219
  return this._events.on(event, cb);
@@ -1234,7 +1241,7 @@ var PostHogCore = /** @class */ (function (_super) {
1234
1241
  return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
1235
1242
  };
1236
1243
  PostHogCore.prototype.enrichProperties = function (properties) {
1237
- 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() });
1238
1245
  };
1239
1246
  PostHogCore.prototype.getSessionId = function () {
1240
1247
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
@@ -1260,13 +1267,19 @@ var PostHogCore = /** @class */ (function (_super) {
1260
1267
  PostHogCore.prototype.getDistinctId = function () {
1261
1268
  return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
1262
1269
  };
1270
+ PostHogCore.prototype.unregister = function (property) {
1271
+ delete this.props[property];
1272
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1273
+ };
1263
1274
  PostHogCore.prototype.register = function (properties) {
1264
1275
  this.props = __assign(__assign({}, this.props), properties);
1265
1276
  this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1266
1277
  };
1267
- PostHogCore.prototype.unregister = function (property) {
1268
- delete this.props[property];
1269
- 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];
1270
1283
  };
1271
1284
  /***
1272
1285
  *** TRACKING
@@ -1346,13 +1359,20 @@ var PostHogCore = /** @class */ (function (_super) {
1346
1359
  /***
1347
1360
  * PROPERTIES
1348
1361
  ***/
1349
- PostHogCore.prototype.personProperties = function (properties) {
1362
+ PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
1350
1363
  // Get persisted person properties
1351
1364
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
1352
1365
  this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
1353
1366
  return this;
1354
1367
  };
1355
- 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) {
1356
1376
  // Get persisted group properties
1357
1377
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
1358
1378
  if (Object.keys(existingProperties).length !== 0) {
@@ -1364,6 +1384,13 @@ var PostHogCore = /** @class */ (function (_super) {
1364
1384
  this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
1365
1385
  return this;
1366
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
+ };
1367
1394
  /***
1368
1395
  *** FEATURE FLAGS
1369
1396
  ***/
@@ -1555,7 +1582,7 @@ var PostHogCore = /** @class */ (function (_super) {
1555
1582
  return PostHogCore;
1556
1583
  }(PostHogCoreStateless));
1557
1584
 
1558
- var version = "2.4.0";
1585
+ var version = "2.5.0";
1559
1586
 
1560
1587
  function getContext(window) {
1561
1588
  var context = {};