posthog-node 2.3.1 → 2.4.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,15 +1,23 @@
1
+ # 2.4.0 - 2023-02-02
2
+
3
+ 1. Adds support for overriding timestamp of capture events
4
+
1
5
  # 2.3.0 - 2022-1-26
2
6
 
3
- 1. uses v3 decide endpoint
7
+ 1. uses v3 decide endpoint
4
8
  2. JSON payloads will be returned with feature flags
5
9
  3. Feature flags will gracefully fail and optimistically save evaluated flags if server is down
6
10
 
7
11
  # 2.2.3 - 2022-12-01
12
+
8
13
  1. Fix issues with timeouts for local evaluation requests
14
+
9
15
  # 2.2.2 - 2022-11-28
16
+
10
17
  1. Fix issues with timeout
11
18
 
12
19
  # 2.2.1 - 2022-11-24
20
+
13
21
  1. Add standard 10 second timeout
14
22
 
15
23
  # 2.2.0 - 2022-11-18
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 = "2.3.1";
166
+ var version = "2.4.0";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -878,7 +878,7 @@ var PostHogCore = /** @class */ (function () {
878
878
  /***
879
879
  *** TRACKING
880
880
  ***/
881
- PostHogCore.prototype.identify = function (distinctId, properties) {
881
+ PostHogCore.prototype.identify = function (distinctId, properties, options) {
882
882
  var previousDistinctId = this.getDistinctId();
883
883
  distinctId = distinctId || previousDistinctId;
884
884
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
@@ -897,21 +897,15 @@ var PostHogCore = /** @class */ (function () {
897
897
  void this.reloadFeatureFlagsAsync();
898
898
  }
899
899
  }
900
- this.enqueue('identify', payload);
900
+ this.enqueue('identify', payload, options);
901
901
  return this;
902
902
  };
903
- PostHogCore.prototype.capture = function (event, properties, forceSendFeatureFlags) {
904
- if (forceSendFeatureFlags === void 0) { forceSendFeatureFlags = false; }
903
+ PostHogCore.prototype.capture = function (event, properties, options) {
905
904
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
906
905
  this.groups(properties.$groups);
907
906
  }
908
- if (forceSendFeatureFlags) {
909
- this._sendFeatureFlags(event, properties);
910
- }
911
- else {
912
- var payload = this.buildPayload({ event: event, properties: properties });
913
- this.enqueue('capture', payload);
914
- }
907
+ var payload = this.buildPayload({ event: event, properties: properties });
908
+ this.enqueue('capture', payload, options);
915
909
  return this;
916
910
  };
917
911
  PostHogCore.prototype.alias = function (alias) {
@@ -926,13 +920,13 @@ var PostHogCore = /** @class */ (function () {
926
920
  this.enqueue('alias', payload);
927
921
  return this;
928
922
  };
929
- PostHogCore.prototype.autocapture = function (eventType, elements, properties) {
923
+ PostHogCore.prototype.autocapture = function (eventType, elements, properties, options) {
930
924
  if (properties === void 0) { properties = {}; }
931
925
  var payload = this.buildPayload({
932
926
  event: '$autocapture',
933
927
  properties: __assign(__assign({}, properties), { $event_type: eventType, $elements: elements }),
934
928
  });
935
- this.enqueue('autocapture', payload);
929
+ this.enqueue('autocapture', payload, options);
936
930
  return this;
937
931
  };
938
932
  /***
@@ -949,22 +943,22 @@ var PostHogCore = /** @class */ (function () {
949
943
  }
950
944
  return this;
951
945
  };
952
- PostHogCore.prototype.group = function (groupType, groupKey, groupProperties) {
946
+ PostHogCore.prototype.group = function (groupType, groupKey, groupProperties, options) {
953
947
  var _a;
954
948
  this.groups((_a = {},
955
949
  _a[groupType] = groupKey,
956
950
  _a));
957
951
  if (groupProperties) {
958
- this.groupIdentify(groupType, groupKey, groupProperties);
952
+ this.groupIdentify(groupType, groupKey, groupProperties, options);
959
953
  }
960
954
  return this;
961
955
  };
962
- PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties) {
956
+ PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties, options) {
963
957
  var payload = this.buildPayload({
964
958
  event: '$groupidentify',
965
959
  properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, this.getCommonEventProperties()),
966
960
  });
967
- this.enqueue('capture', payload);
961
+ this.enqueue('capture', payload, options);
968
962
  return this;
969
963
  };
970
964
  /***
@@ -1181,23 +1175,15 @@ var PostHogCore = /** @class */ (function () {
1181
1175
  }
1182
1176
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1183
1177
  };
1184
- PostHogCore.prototype._sendFeatureFlags = function (event, properties) {
1185
- var _this = this;
1186
- this.reloadFeatureFlagsAsync(false).finally(function () {
1187
- // Try to enqueue message irrespective of errors during feature flag fetching
1188
- var payload = _this.buildPayload({ event: event, properties: properties });
1189
- _this.enqueue('capture', payload);
1190
- });
1191
- };
1192
1178
  /***
1193
1179
  *** QUEUEING AND FLUSHING
1194
1180
  ***/
1195
- PostHogCore.prototype.enqueue = function (type, _message) {
1181
+ PostHogCore.prototype.enqueue = function (type, _message, options) {
1196
1182
  var _this = this;
1197
1183
  if (this.optedOut) {
1198
1184
  return;
1199
1185
  }
1200
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: _message.timestamp ? _message.timestamp : currentISOTime() });
1186
+ var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime() });
1201
1187
  if (message.distinctId) {
1202
1188
  message.distinct_id = message.distinctId;
1203
1189
  delete message.distinctId;
@@ -2180,18 +2166,33 @@ function () {
2180
2166
  };
2181
2167
 
2182
2168
  PostHog.prototype.capture = function (_a) {
2169
+ var _this = this;
2170
+
2183
2171
  var distinctId = _a.distinctId,
2184
2172
  event = _a.event,
2185
2173
  properties = _a.properties,
2186
2174
  groups = _a.groups,
2187
- sendFeatureFlags = _a.sendFeatureFlags;
2175
+ sendFeatureFlags = _a.sendFeatureFlags,
2176
+ timestamp = _a.timestamp;
2188
2177
  this.reInit(distinctId);
2189
2178
 
2190
2179
  if (groups) {
2191
2180
  this._sharedClient.groups(groups);
2192
2181
  }
2193
2182
 
2194
- this._sharedClient.capture(event, properties, sendFeatureFlags || false);
2183
+ var _capture = function () {
2184
+ _this._sharedClient.capture(event, properties, {
2185
+ timestamp: timestamp
2186
+ });
2187
+ };
2188
+
2189
+ if (sendFeatureFlags) {
2190
+ this._sharedClient.reloadFeatureFlagsAsync(false).finally(function () {
2191
+ _capture();
2192
+ });
2193
+ } else {
2194
+ _capture();
2195
+ }
2195
2196
  };
2196
2197
 
2197
2198
  PostHog.prototype.identify = function (_a) {