posthog-node 3.1.1 → 3.1.2

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,7 @@
1
+ # 3.1.2 - 2023-08-17
2
+
3
+ 1. Returns the current flag property with $feature_flag_called events, to make it easier to use in experiments
4
+
1
5
  # 3.1.1 - 2023-04-26
2
6
 
3
7
  1. Replace crypto library with pure-js rusha library which makes posthog-node work with Cloudflare Workers in Next.js edge runtime.
package/lib/index.cjs.js CHANGED
@@ -163,7 +163,7 @@ function __spreadArray(to, from, pack) {
163
163
  return to.concat(ar || Array.prototype.slice.call(from));
164
164
  }
165
165
 
166
- var version = "3.1.1";
166
+ var version = "3.1.2";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -1187,6 +1187,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1187
1187
  var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
1188
1188
  _this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
1189
1189
  _this.flagCallReported = {};
1190
+ _this.sessionProps = {};
1190
1191
  _this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
1191
1192
  _this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
1192
1193
  return _this;
@@ -1228,6 +1229,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1228
1229
  });
1229
1230
  PostHogCore.prototype.clearProps = function () {
1230
1231
  this.props = undefined;
1232
+ this.sessionProps = {};
1231
1233
  };
1232
1234
  PostHogCore.prototype.on = function (event, cb) {
1233
1235
  return this._events.on(event, cb);
@@ -1255,7 +1257,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1255
1257
  return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
1256
1258
  };
1257
1259
  PostHogCore.prototype.enrichProperties = function (properties) {
1258
- return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1260
+ return __assign(__assign(__assign(__assign(__assign({}, this.props), this.sessionProps), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1259
1261
  };
1260
1262
  PostHogCore.prototype.getSessionId = function () {
1261
1263
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
@@ -1281,13 +1283,19 @@ var PostHogCoreStateless = /** @class */ (function () {
1281
1283
  PostHogCore.prototype.getDistinctId = function () {
1282
1284
  return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
1283
1285
  };
1286
+ PostHogCore.prototype.unregister = function (property) {
1287
+ delete this.props[property];
1288
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1289
+ };
1284
1290
  PostHogCore.prototype.register = function (properties) {
1285
1291
  this.props = __assign(__assign({}, this.props), properties);
1286
1292
  this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1287
1293
  };
1288
- PostHogCore.prototype.unregister = function (property) {
1289
- delete this.props[property];
1290
- this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1294
+ PostHogCore.prototype.registerForSession = function (properties) {
1295
+ this.sessionProps = __assign(__assign({}, this.sessionProps), properties);
1296
+ };
1297
+ PostHogCore.prototype.unregisterForSession = function (property) {
1298
+ delete this.sessionProps[property];
1291
1299
  };
1292
1300
  /***
1293
1301
  *** TRACKING
@@ -2655,8 +2663,10 @@ function (_super) {
2655
2663
  return __awaiter(this, void 0, void 0, function () {
2656
2664
  var _b, groups, personProperties, groupProperties, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, response, flagWasLocallyEvaluated, featureFlagReportedKey;
2657
2665
 
2658
- return __generator(this, function (_d) {
2659
- switch (_d.label) {
2666
+ var _d;
2667
+
2668
+ return __generator(this, function (_e) {
2669
+ switch (_e.label) {
2660
2670
  case 0:
2661
2671
  _b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
2662
2672
  _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents; // set defaults
@@ -2674,7 +2684,7 @@ function (_super) {
2674
2684
  , (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getFeatureFlag(key, distinctId, groups, personProperties, groupProperties)];
2675
2685
 
2676
2686
  case 1:
2677
- response = _d.sent();
2687
+ response = _e.sent();
2678
2688
  flagWasLocallyEvaluated = response !== undefined;
2679
2689
  if (!(!flagWasLocallyEvaluated && !onlyEvaluateLocally)) return [3
2680
2690
  /*break*/
@@ -2684,8 +2694,8 @@ function (_super) {
2684
2694
  , _super.prototype.getFeatureFlagStateless.call(this, key, distinctId, groups, personProperties, groupProperties, disableGeoip)];
2685
2695
 
2686
2696
  case 2:
2687
- response = _d.sent();
2688
- _d.label = 3;
2697
+ response = _e.sent();
2698
+ _e.label = 3;
2689
2699
 
2690
2700
  case 3:
2691
2701
  featureFlagReportedKey = "".concat(key, "_").concat(response);
@@ -2704,11 +2714,11 @@ function (_super) {
2704
2714
  this.capture({
2705
2715
  distinctId: distinctId,
2706
2716
  event: '$feature_flag_called',
2707
- properties: {
2717
+ properties: (_d = {
2708
2718
  $feature_flag: key,
2709
2719
  $feature_flag_response: response,
2710
2720
  locally_evaluated: flagWasLocallyEvaluated
2711
- },
2721
+ }, _d["$feature/".concat(key)] = response, _d),
2712
2722
  groups: groups,
2713
2723
  disableGeoip: disableGeoip
2714
2724
  });