posthog-node 2.3.0 → 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/lib/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  /// <reference types="node" />
2
- import { JsonType as JsonType$1 } from 'posthog-core/src';
3
-
4
2
  declare type PosthogCoreOptions = {
5
3
  host?: string;
6
4
  flushAt?: number;
@@ -70,6 +68,7 @@ interface EventMessageV1 extends IdentifyMessageV1 {
70
68
  event: string;
71
69
  groups?: Record<string, string | number>;
72
70
  sendFeatureFlags?: boolean;
71
+ timestamp?: Date;
73
72
  }
74
73
  interface GroupIdentifyMessage {
75
74
  groupType: string;
@@ -174,7 +173,7 @@ declare type PostHogNodeV1 = {
174
173
  */
175
174
  getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: {
176
175
  onlyEvaluateLocally?: boolean;
177
- }): Promise<JsonType$1 | undefined>;
176
+ }): Promise<JsonType | undefined>;
178
177
  /**
179
178
  * @description Sets a groups properties, which allows asking questions like "Who are the most active companies"
180
179
  * using my product in PostHog.
@@ -213,7 +212,7 @@ declare class PostHog implements PostHogNodeV1 {
213
212
  private reInit;
214
213
  enable(): void;
215
214
  disable(): void;
216
- capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
215
+ capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
217
216
  identify({ distinctId, properties }: IdentifyMessageV1): void;
218
217
  alias(data: {
219
218
  distinctId: string;
package/lib/index.esm.js CHANGED
@@ -155,7 +155,7 @@ function __spreadArray(to, from, pack) {
155
155
  return to.concat(ar || Array.prototype.slice.call(from));
156
156
  }
157
157
 
158
- var version = "2.3.0";
158
+ var version = "2.4.0";
159
159
 
160
160
  var PostHogPersistedProperty;
161
161
  (function (PostHogPersistedProperty) {
@@ -870,7 +870,7 @@ var PostHogCore = /** @class */ (function () {
870
870
  /***
871
871
  *** TRACKING
872
872
  ***/
873
- PostHogCore.prototype.identify = function (distinctId, properties) {
873
+ PostHogCore.prototype.identify = function (distinctId, properties, options) {
874
874
  var previousDistinctId = this.getDistinctId();
875
875
  distinctId = distinctId || previousDistinctId;
876
876
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
@@ -889,21 +889,15 @@ var PostHogCore = /** @class */ (function () {
889
889
  void this.reloadFeatureFlagsAsync();
890
890
  }
891
891
  }
892
- this.enqueue('identify', payload);
892
+ this.enqueue('identify', payload, options);
893
893
  return this;
894
894
  };
895
- PostHogCore.prototype.capture = function (event, properties, forceSendFeatureFlags) {
896
- if (forceSendFeatureFlags === void 0) { forceSendFeatureFlags = false; }
895
+ PostHogCore.prototype.capture = function (event, properties, options) {
897
896
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
898
897
  this.groups(properties.$groups);
899
898
  }
900
- if (forceSendFeatureFlags) {
901
- this._sendFeatureFlags(event, properties);
902
- }
903
- else {
904
- var payload = this.buildPayload({ event: event, properties: properties });
905
- this.enqueue('capture', payload);
906
- }
899
+ var payload = this.buildPayload({ event: event, properties: properties });
900
+ this.enqueue('capture', payload, options);
907
901
  return this;
908
902
  };
909
903
  PostHogCore.prototype.alias = function (alias) {
@@ -918,13 +912,13 @@ var PostHogCore = /** @class */ (function () {
918
912
  this.enqueue('alias', payload);
919
913
  return this;
920
914
  };
921
- PostHogCore.prototype.autocapture = function (eventType, elements, properties) {
915
+ PostHogCore.prototype.autocapture = function (eventType, elements, properties, options) {
922
916
  if (properties === void 0) { properties = {}; }
923
917
  var payload = this.buildPayload({
924
918
  event: '$autocapture',
925
919
  properties: __assign(__assign({}, properties), { $event_type: eventType, $elements: elements }),
926
920
  });
927
- this.enqueue('autocapture', payload);
921
+ this.enqueue('autocapture', payload, options);
928
922
  return this;
929
923
  };
930
924
  /***
@@ -941,22 +935,22 @@ var PostHogCore = /** @class */ (function () {
941
935
  }
942
936
  return this;
943
937
  };
944
- PostHogCore.prototype.group = function (groupType, groupKey, groupProperties) {
938
+ PostHogCore.prototype.group = function (groupType, groupKey, groupProperties, options) {
945
939
  var _a;
946
940
  this.groups((_a = {},
947
941
  _a[groupType] = groupKey,
948
942
  _a));
949
943
  if (groupProperties) {
950
- this.groupIdentify(groupType, groupKey, groupProperties);
944
+ this.groupIdentify(groupType, groupKey, groupProperties, options);
951
945
  }
952
946
  return this;
953
947
  };
954
- PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties) {
948
+ PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties, options) {
955
949
  var payload = this.buildPayload({
956
950
  event: '$groupidentify',
957
951
  properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, this.getCommonEventProperties()),
958
952
  });
959
- this.enqueue('capture', payload);
953
+ this.enqueue('capture', payload, options);
960
954
  return this;
961
955
  };
962
956
  /***
@@ -1173,23 +1167,15 @@ var PostHogCore = /** @class */ (function () {
1173
1167
  }
1174
1168
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1175
1169
  };
1176
- PostHogCore.prototype._sendFeatureFlags = function (event, properties) {
1177
- var _this = this;
1178
- this.reloadFeatureFlagsAsync(false).finally(function () {
1179
- // Try to enqueue message irrespective of errors during feature flag fetching
1180
- var payload = _this.buildPayload({ event: event, properties: properties });
1181
- _this.enqueue('capture', payload);
1182
- });
1183
- };
1184
1170
  /***
1185
1171
  *** QUEUEING AND FLUSHING
1186
1172
  ***/
1187
- PostHogCore.prototype.enqueue = function (type, _message) {
1173
+ PostHogCore.prototype.enqueue = function (type, _message, options) {
1188
1174
  var _this = this;
1189
1175
  if (this.optedOut) {
1190
1176
  return;
1191
1177
  }
1192
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: _message.timestamp ? _message.timestamp : currentISOTime() });
1178
+ 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() });
1193
1179
  if (message.distinctId) {
1194
1180
  message.distinct_id = message.distinctId;
1195
1181
  delete message.distinctId;
@@ -2172,18 +2158,33 @@ function () {
2172
2158
  };
2173
2159
 
2174
2160
  PostHog.prototype.capture = function (_a) {
2161
+ var _this = this;
2162
+
2175
2163
  var distinctId = _a.distinctId,
2176
2164
  event = _a.event,
2177
2165
  properties = _a.properties,
2178
2166
  groups = _a.groups,
2179
- sendFeatureFlags = _a.sendFeatureFlags;
2167
+ sendFeatureFlags = _a.sendFeatureFlags,
2168
+ timestamp = _a.timestamp;
2180
2169
  this.reInit(distinctId);
2181
2170
 
2182
2171
  if (groups) {
2183
2172
  this._sharedClient.groups(groups);
2184
2173
  }
2185
2174
 
2186
- this._sharedClient.capture(event, properties, sendFeatureFlags || false);
2175
+ var _capture = function () {
2176
+ _this._sharedClient.capture(event, properties, {
2177
+ timestamp: timestamp
2178
+ });
2179
+ };
2180
+
2181
+ if (sendFeatureFlags) {
2182
+ this._sharedClient.reloadFeatureFlagsAsync(false).finally(function () {
2183
+ _capture();
2184
+ });
2185
+ } else {
2186
+ _capture();
2187
+ }
2187
2188
  };
2188
2189
 
2189
2190
  PostHog.prototype.identify = function (_a) {