posthog-js-lite 2.0.1 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.2.0 - 2023-02-02
2
+
3
+ 1. Adds support for overriding timestamp of capture events
4
+
5
+ # 2.1.0 - 2022-1-26
6
+
7
+ 1. uses v3 decide endpoint
8
+ 2. JSON payloads will be returned with feature flags
9
+ 3. Feature flags will gracefully fail and optimistically save evaluated flags if server is down
10
+
1
11
  # 2.0.1 - 2023-01-25
2
12
 
3
13
  - Ensures the distinctId used in `.groupIdentify` is the same as the currently identified user
package/lib/index.cjs.js CHANGED
@@ -857,7 +857,7 @@ var PostHogCore = /** @class */ (function () {
857
857
  /***
858
858
  *** TRACKING
859
859
  ***/
860
- PostHogCore.prototype.identify = function (distinctId, properties) {
860
+ PostHogCore.prototype.identify = function (distinctId, properties, options) {
861
861
  var previousDistinctId = this.getDistinctId();
862
862
  distinctId = distinctId || previousDistinctId;
863
863
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
@@ -876,21 +876,15 @@ var PostHogCore = /** @class */ (function () {
876
876
  void this.reloadFeatureFlagsAsync();
877
877
  }
878
878
  }
879
- this.enqueue('identify', payload);
879
+ this.enqueue('identify', payload, options);
880
880
  return this;
881
881
  };
882
- PostHogCore.prototype.capture = function (event, properties, forceSendFeatureFlags) {
883
- if (forceSendFeatureFlags === void 0) { forceSendFeatureFlags = false; }
882
+ PostHogCore.prototype.capture = function (event, properties, options) {
884
883
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
885
884
  this.groups(properties.$groups);
886
885
  }
887
- if (forceSendFeatureFlags) {
888
- this._sendFeatureFlags(event, properties);
889
- }
890
- else {
891
- var payload = this.buildPayload({ event: event, properties: properties });
892
- this.enqueue('capture', payload);
893
- }
886
+ var payload = this.buildPayload({ event: event, properties: properties });
887
+ this.enqueue('capture', payload, options);
894
888
  return this;
895
889
  };
896
890
  PostHogCore.prototype.alias = function (alias) {
@@ -905,13 +899,13 @@ var PostHogCore = /** @class */ (function () {
905
899
  this.enqueue('alias', payload);
906
900
  return this;
907
901
  };
908
- PostHogCore.prototype.autocapture = function (eventType, elements, properties) {
902
+ PostHogCore.prototype.autocapture = function (eventType, elements, properties, options) {
909
903
  if (properties === void 0) { properties = {}; }
910
904
  var payload = this.buildPayload({
911
905
  event: '$autocapture',
912
906
  properties: __assign(__assign({}, properties), { $event_type: eventType, $elements: elements }),
913
907
  });
914
- this.enqueue('autocapture', payload);
908
+ this.enqueue('autocapture', payload, options);
915
909
  return this;
916
910
  };
917
911
  /***
@@ -928,22 +922,22 @@ var PostHogCore = /** @class */ (function () {
928
922
  }
929
923
  return this;
930
924
  };
931
- PostHogCore.prototype.group = function (groupType, groupKey, groupProperties) {
925
+ PostHogCore.prototype.group = function (groupType, groupKey, groupProperties, options) {
932
926
  var _a;
933
927
  this.groups((_a = {},
934
928
  _a[groupType] = groupKey,
935
929
  _a));
936
930
  if (groupProperties) {
937
- this.groupIdentify(groupType, groupKey, groupProperties);
931
+ this.groupIdentify(groupType, groupKey, groupProperties, options);
938
932
  }
939
933
  return this;
940
934
  };
941
- PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties) {
935
+ PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties, options) {
942
936
  var payload = this.buildPayload({
943
937
  event: '$groupidentify',
944
938
  properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, this.getCommonEventProperties()),
945
939
  });
946
- this.enqueue('capture', payload);
940
+ this.enqueue('capture', payload, options);
947
941
  return this;
948
942
  };
949
943
  /***
@@ -1160,23 +1154,15 @@ var PostHogCore = /** @class */ (function () {
1160
1154
  }
1161
1155
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1162
1156
  };
1163
- PostHogCore.prototype._sendFeatureFlags = function (event, properties) {
1164
- var _this = this;
1165
- this.reloadFeatureFlagsAsync(false).finally(function () {
1166
- // Try to enqueue message irrespective of errors during feature flag fetching
1167
- var payload = _this.buildPayload({ event: event, properties: properties });
1168
- _this.enqueue('capture', payload);
1169
- });
1170
- };
1171
1157
  /***
1172
1158
  *** QUEUEING AND FLUSHING
1173
1159
  ***/
1174
- PostHogCore.prototype.enqueue = function (type, _message) {
1160
+ PostHogCore.prototype.enqueue = function (type, _message, options) {
1175
1161
  var _this = this;
1176
1162
  if (this.optedOut) {
1177
1163
  return;
1178
1164
  }
1179
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: _message.timestamp ? _message.timestamp : currentISOTime() });
1165
+ 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() });
1180
1166
  if (message.distinctId) {
1181
1167
  message.distinct_id = message.distinctId;
1182
1168
  delete message.distinctId;
@@ -1295,7 +1281,7 @@ var PostHogCore = /** @class */ (function () {
1295
1281
  return PostHogCore;
1296
1282
  }());
1297
1283
 
1298
- var version = "2.0.1";
1284
+ var version = "2.2.0";
1299
1285
 
1300
1286
  function getContext(window) {
1301
1287
  var context = {};