posthog-js-lite 2.1.0 → 2.2.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
@@ -41,6 +41,9 @@ declare type PostHogFetchOptions = {
41
41
  body?: string;
42
42
  signal?: AbortSignal;
43
43
  };
44
+ declare type PosthogCaptureOptions = {
45
+ timestamp?: Date;
46
+ };
44
47
  declare type PostHogFetchResponse = {
45
48
  status: number;
46
49
  text: () => Promise<string>;
@@ -144,20 +147,20 @@ declare abstract class PostHogCore {
144
147
  /***
145
148
  *** TRACKING
146
149
  ***/
147
- identify(distinctId?: string, properties?: PostHogEventProperties): this;
150
+ identify(distinctId?: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
148
151
  capture(event: string, properties?: {
149
152
  [key: string]: any;
150
- }, forceSendFeatureFlags?: boolean): this;
153
+ }, options?: PosthogCaptureOptions): this;
151
154
  alias(alias: string): this;
152
- autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties): this;
155
+ autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
153
156
  /***
154
157
  *** GROUPS
155
158
  ***/
156
159
  groups(groups: {
157
160
  [type: string]: string | number;
158
161
  }): this;
159
- group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
160
- groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
162
+ group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
163
+ groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
161
164
  /***
162
165
  * PROPERTIES
163
166
  ***/
@@ -188,9 +191,6 @@ declare abstract class PostHogCore {
188
191
  onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
189
192
  onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
190
193
  overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
191
- _sendFeatureFlags(event: string, properties?: {
192
- [key: string]: any;
193
- }): void;
194
194
  /***
195
195
  *** QUEUEING AND FLUSHING
196
196
  ***/
package/lib/index.esm.js CHANGED
@@ -853,7 +853,7 @@ var PostHogCore = /** @class */ (function () {
853
853
  /***
854
854
  *** TRACKING
855
855
  ***/
856
- PostHogCore.prototype.identify = function (distinctId, properties) {
856
+ PostHogCore.prototype.identify = function (distinctId, properties, options) {
857
857
  var previousDistinctId = this.getDistinctId();
858
858
  distinctId = distinctId || previousDistinctId;
859
859
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
@@ -872,21 +872,15 @@ var PostHogCore = /** @class */ (function () {
872
872
  void this.reloadFeatureFlagsAsync();
873
873
  }
874
874
  }
875
- this.enqueue('identify', payload);
875
+ this.enqueue('identify', payload, options);
876
876
  return this;
877
877
  };
878
- PostHogCore.prototype.capture = function (event, properties, forceSendFeatureFlags) {
879
- if (forceSendFeatureFlags === void 0) { forceSendFeatureFlags = false; }
878
+ PostHogCore.prototype.capture = function (event, properties, options) {
880
879
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
881
880
  this.groups(properties.$groups);
882
881
  }
883
- if (forceSendFeatureFlags) {
884
- this._sendFeatureFlags(event, properties);
885
- }
886
- else {
887
- var payload = this.buildPayload({ event: event, properties: properties });
888
- this.enqueue('capture', payload);
889
- }
882
+ var payload = this.buildPayload({ event: event, properties: properties });
883
+ this.enqueue('capture', payload, options);
890
884
  return this;
891
885
  };
892
886
  PostHogCore.prototype.alias = function (alias) {
@@ -901,13 +895,13 @@ var PostHogCore = /** @class */ (function () {
901
895
  this.enqueue('alias', payload);
902
896
  return this;
903
897
  };
904
- PostHogCore.prototype.autocapture = function (eventType, elements, properties) {
898
+ PostHogCore.prototype.autocapture = function (eventType, elements, properties, options) {
905
899
  if (properties === void 0) { properties = {}; }
906
900
  var payload = this.buildPayload({
907
901
  event: '$autocapture',
908
902
  properties: __assign(__assign({}, properties), { $event_type: eventType, $elements: elements }),
909
903
  });
910
- this.enqueue('autocapture', payload);
904
+ this.enqueue('autocapture', payload, options);
911
905
  return this;
912
906
  };
913
907
  /***
@@ -924,22 +918,22 @@ var PostHogCore = /** @class */ (function () {
924
918
  }
925
919
  return this;
926
920
  };
927
- PostHogCore.prototype.group = function (groupType, groupKey, groupProperties) {
921
+ PostHogCore.prototype.group = function (groupType, groupKey, groupProperties, options) {
928
922
  var _a;
929
923
  this.groups((_a = {},
930
924
  _a[groupType] = groupKey,
931
925
  _a));
932
926
  if (groupProperties) {
933
- this.groupIdentify(groupType, groupKey, groupProperties);
927
+ this.groupIdentify(groupType, groupKey, groupProperties, options);
934
928
  }
935
929
  return this;
936
930
  };
937
- PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties) {
931
+ PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties, options) {
938
932
  var payload = this.buildPayload({
939
933
  event: '$groupidentify',
940
934
  properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, this.getCommonEventProperties()),
941
935
  });
942
- this.enqueue('capture', payload);
936
+ this.enqueue('capture', payload, options);
943
937
  return this;
944
938
  };
945
939
  /***
@@ -1156,23 +1150,15 @@ var PostHogCore = /** @class */ (function () {
1156
1150
  }
1157
1151
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1158
1152
  };
1159
- PostHogCore.prototype._sendFeatureFlags = function (event, properties) {
1160
- var _this = this;
1161
- this.reloadFeatureFlagsAsync(false).finally(function () {
1162
- // Try to enqueue message irrespective of errors during feature flag fetching
1163
- var payload = _this.buildPayload({ event: event, properties: properties });
1164
- _this.enqueue('capture', payload);
1165
- });
1166
- };
1167
1153
  /***
1168
1154
  *** QUEUEING AND FLUSHING
1169
1155
  ***/
1170
- PostHogCore.prototype.enqueue = function (type, _message) {
1156
+ PostHogCore.prototype.enqueue = function (type, _message, options) {
1171
1157
  var _this = this;
1172
1158
  if (this.optedOut) {
1173
1159
  return;
1174
1160
  }
1175
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: _message.timestamp ? _message.timestamp : currentISOTime() });
1161
+ 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() });
1176
1162
  if (message.distinctId) {
1177
1163
  message.distinct_id = message.distinctId;
1178
1164
  delete message.distinctId;
@@ -1291,7 +1277,7 @@ var PostHogCore = /** @class */ (function () {
1291
1277
  return PostHogCore;
1292
1278
  }());
1293
1279
 
1294
- var version = "2.1.0";
1280
+ var version = "2.2.0";
1295
1281
 
1296
1282
  function getContext(window) {
1297
1283
  var context = {};