posthog-js-lite 2.6.0 → 2.6.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,11 @@
1
+ # 2.6.2 - 2024-02-15
2
+
3
+ 1. fix: using `captureMode=form` won't throw an error and retry unnecessarily
4
+
5
+ # 2.6.1 - 2024-02-06
6
+
7
+ 1. Swapped to `uuidv7` for unique ID generation
8
+
1
9
  # 2.6.0 - 2024-01-18
2
10
 
3
11
  1. Adds support for overriding the event `uuid` via capture options
package/lib/index.cjs.js CHANGED
@@ -211,26 +211,6 @@ function retriable(fn, props) {
211
211
  });
212
212
  });
213
213
  }
214
- // https://stackoverflow.com/a/8809472
215
- function generateUUID(globalThis) {
216
- // Public Domain/MIT
217
- var d = new Date().getTime(); //Timestamp
218
- var d2 = (globalThis && globalThis.performance && globalThis.performance.now && globalThis.performance.now() * 1000) || 0; //Time in microseconds since page-load or 0 if unsupported
219
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
220
- var r = Math.random() * 16; //random number between 0 and 16
221
- if (d > 0) {
222
- //Use timestamp until depleted
223
- r = (d + r) % 16 | 0;
224
- d = Math.floor(d / 16);
225
- }
226
- else {
227
- //Use microseconds since page-load if supported
228
- r = (d2 + r) % 16 | 0;
229
- d2 = Math.floor(d2 / 16);
230
- }
231
- return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
232
- });
233
- }
234
214
  function currentTimestamp() {
235
215
  return new Date().getTime();
236
216
  }
@@ -705,6 +685,413 @@ var SimpleEventEmitter = /** @class */ (function () {
705
685
  return SimpleEventEmitter;
706
686
  }());
707
687
 
688
+ // vendor from: https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
689
+ // https://github.com/LiosK/uuidv7#license
690
+ /**
691
+ * uuidv7: An experimental implementation of the proposed UUID Version 7
692
+ *
693
+ * @license Apache-2.0
694
+ * @copyright 2021-2023 LiosK
695
+ * @packageDocumentation
696
+ */
697
+ var DIGITS = "0123456789abcdef";
698
+ /** Represents a UUID as a 16-byte byte array. */
699
+ var UUID = /** @class */ (function () {
700
+ /** @param bytes - The 16-byte byte array representation. */
701
+ function UUID(bytes) {
702
+ this.bytes = bytes;
703
+ }
704
+ /**
705
+ * Creates an object from the internal representation, a 16-byte byte array
706
+ * containing the binary UUID representation in the big-endian byte order.
707
+ *
708
+ * This method does NOT shallow-copy the argument, and thus the created object
709
+ * holds the reference to the underlying buffer.
710
+ *
711
+ * @throws TypeError if the length of the argument is not 16.
712
+ */
713
+ UUID.ofInner = function (bytes) {
714
+ if (bytes.length !== 16) {
715
+ throw new TypeError("not 128-bit length");
716
+ }
717
+ else {
718
+ return new UUID(bytes);
719
+ }
720
+ };
721
+ /**
722
+ * Builds a byte array from UUIDv7 field values.
723
+ *
724
+ * @param unixTsMs - A 48-bit `unix_ts_ms` field value.
725
+ * @param randA - A 12-bit `rand_a` field value.
726
+ * @param randBHi - The higher 30 bits of 62-bit `rand_b` field value.
727
+ * @param randBLo - The lower 32 bits of 62-bit `rand_b` field value.
728
+ * @throws RangeError if any field value is out of the specified range.
729
+ */
730
+ UUID.fromFieldsV7 = function (unixTsMs, randA, randBHi, randBLo) {
731
+ if (!Number.isInteger(unixTsMs) ||
732
+ !Number.isInteger(randA) ||
733
+ !Number.isInteger(randBHi) ||
734
+ !Number.isInteger(randBLo) ||
735
+ unixTsMs < 0 ||
736
+ randA < 0 ||
737
+ randBHi < 0 ||
738
+ randBLo < 0 ||
739
+ unixTsMs > 281474976710655 ||
740
+ randA > 0xfff ||
741
+ randBHi > 1073741823 ||
742
+ randBLo > 4294967295) {
743
+ throw new RangeError("invalid field value");
744
+ }
745
+ var bytes = new Uint8Array(16);
746
+ bytes[0] = unixTsMs / Math.pow(2, 40);
747
+ bytes[1] = unixTsMs / Math.pow(2, 32);
748
+ bytes[2] = unixTsMs / Math.pow(2, 24);
749
+ bytes[3] = unixTsMs / Math.pow(2, 16);
750
+ bytes[4] = unixTsMs / Math.pow(2, 8);
751
+ bytes[5] = unixTsMs;
752
+ bytes[6] = 0x70 | (randA >>> 8);
753
+ bytes[7] = randA;
754
+ bytes[8] = 0x80 | (randBHi >>> 24);
755
+ bytes[9] = randBHi >>> 16;
756
+ bytes[10] = randBHi >>> 8;
757
+ bytes[11] = randBHi;
758
+ bytes[12] = randBLo >>> 24;
759
+ bytes[13] = randBLo >>> 16;
760
+ bytes[14] = randBLo >>> 8;
761
+ bytes[15] = randBLo;
762
+ return new UUID(bytes);
763
+ };
764
+ /**
765
+ * Builds a byte array from a string representation.
766
+ *
767
+ * This method accepts the following formats:
768
+ *
769
+ * - 32-digit hexadecimal format without hyphens: `0189dcd553117d408db09496a2eef37b`
770
+ * - 8-4-4-4-12 hyphenated format: `0189dcd5-5311-7d40-8db0-9496a2eef37b`
771
+ * - Hyphenated format with surrounding braces: `{0189dcd5-5311-7d40-8db0-9496a2eef37b}`
772
+ * - RFC 4122 URN format: `urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b`
773
+ *
774
+ * Leading and trailing whitespaces represents an error.
775
+ *
776
+ * @throws SyntaxError if the argument could not parse as a valid UUID string.
777
+ */
778
+ UUID.parse = function (uuid) {
779
+ var _a, _b, _c, _d;
780
+ var hex = undefined;
781
+ switch (uuid.length) {
782
+ case 32:
783
+ hex = (_a = /^[0-9a-f]{32}$/i.exec(uuid)) === null || _a === void 0 ? void 0 : _a[0];
784
+ break;
785
+ case 36:
786
+ hex =
787
+ (_b = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
788
+ .exec(uuid)) === null || _b === void 0 ? void 0 : _b.slice(1, 6).join("");
789
+ break;
790
+ case 38:
791
+ hex =
792
+ (_c = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i
793
+ .exec(uuid)) === null || _c === void 0 ? void 0 : _c.slice(1, 6).join("");
794
+ break;
795
+ case 45:
796
+ hex =
797
+ (_d = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
798
+ .exec(uuid)) === null || _d === void 0 ? void 0 : _d.slice(1, 6).join("");
799
+ break;
800
+ }
801
+ if (hex) {
802
+ var inner = new Uint8Array(16);
803
+ for (var i = 0; i < 16; i += 4) {
804
+ var n = parseInt(hex.substring(2 * i, 2 * i + 8), 16);
805
+ inner[i + 0] = n >>> 24;
806
+ inner[i + 1] = n >>> 16;
807
+ inner[i + 2] = n >>> 8;
808
+ inner[i + 3] = n;
809
+ }
810
+ return new UUID(inner);
811
+ }
812
+ else {
813
+ throw new SyntaxError("could not parse UUID string");
814
+ }
815
+ };
816
+ /**
817
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
818
+ * (`0189dcd5-5311-7d40-8db0-9496a2eef37b`).
819
+ */
820
+ UUID.prototype.toString = function () {
821
+ var text = "";
822
+ for (var i = 0; i < this.bytes.length; i++) {
823
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
824
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
825
+ if (i === 3 || i === 5 || i === 7 || i === 9) {
826
+ text += "-";
827
+ }
828
+ }
829
+ return text;
830
+ };
831
+ /**
832
+ * @returns The 32-digit hexadecimal representation without hyphens
833
+ * (`0189dcd553117d408db09496a2eef37b`).
834
+ */
835
+ UUID.prototype.toHex = function () {
836
+ var text = "";
837
+ for (var i = 0; i < this.bytes.length; i++) {
838
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
839
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
840
+ }
841
+ return text;
842
+ };
843
+ /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
844
+ UUID.prototype.toJSON = function () {
845
+ return this.toString();
846
+ };
847
+ /**
848
+ * Reports the variant field value of the UUID or, if appropriate, "NIL" or
849
+ * "MAX".
850
+ *
851
+ * For convenience, this method reports "NIL" or "MAX" if `this` represents
852
+ * the Nil or Max UUID, although the Nil and Max UUIDs are technically
853
+ * subsumed under the variants `0b0` and `0b111`, respectively.
854
+ */
855
+ UUID.prototype.getVariant = function () {
856
+ var n = this.bytes[8] >>> 4;
857
+ if (n < 0) {
858
+ throw new Error("unreachable");
859
+ }
860
+ else if (n <= 7) {
861
+ return this.bytes.every(function (e) { return e === 0; }) ? "NIL" : "VAR_0";
862
+ }
863
+ else if (n <= 11) {
864
+ return "VAR_10";
865
+ }
866
+ else if (n <= 13) {
867
+ return "VAR_110";
868
+ }
869
+ else if (n <= 15) {
870
+ return this.bytes.every(function (e) { return e === 0xff; }) ? "MAX" : "VAR_RESERVED";
871
+ }
872
+ else {
873
+ throw new Error("unreachable");
874
+ }
875
+ };
876
+ /**
877
+ * Returns the version field value of the UUID or `undefined` if the UUID does
878
+ * not have the variant field value of `0b10`.
879
+ */
880
+ UUID.prototype.getVersion = function () {
881
+ return this.getVariant() === "VAR_10" ? this.bytes[6] >>> 4 : undefined;
882
+ };
883
+ /** Creates an object from `this`. */
884
+ UUID.prototype.clone = function () {
885
+ return new UUID(this.bytes.slice(0));
886
+ };
887
+ /** Returns true if `this` is equivalent to `other`. */
888
+ UUID.prototype.equals = function (other) {
889
+ return this.compareTo(other) === 0;
890
+ };
891
+ /**
892
+ * Returns a negative integer, zero, or positive integer if `this` is less
893
+ * than, equal to, or greater than `other`, respectively.
894
+ */
895
+ UUID.prototype.compareTo = function (other) {
896
+ for (var i = 0; i < 16; i++) {
897
+ var diff = this.bytes[i] - other.bytes[i];
898
+ if (diff !== 0) {
899
+ return Math.sign(diff);
900
+ }
901
+ }
902
+ return 0;
903
+ };
904
+ return UUID;
905
+ }());
906
+ /**
907
+ * Encapsulates the monotonic counter state.
908
+ *
909
+ * This class provides APIs to utilize a separate counter state from that of the
910
+ * global generator used by {@link uuidv7} and {@link uuidv7obj}. In addition to
911
+ * the default {@link generate} method, this class has {@link generateOrAbort}
912
+ * that is useful to absolutely guarantee the monotonically increasing order of
913
+ * generated UUIDs. See their respective documentation for details.
914
+ */
915
+ var V7Generator = /** @class */ (function () {
916
+ /**
917
+ * Creates a generator object with the default random number generator, or
918
+ * with the specified one if passed as an argument. The specified random
919
+ * number generator should be cryptographically strong and securely seeded.
920
+ */
921
+ function V7Generator(randomNumberGenerator) {
922
+ this.timestamp = 0;
923
+ this.counter = 0;
924
+ this.random = randomNumberGenerator !== null && randomNumberGenerator !== void 0 ? randomNumberGenerator : getDefaultRandom();
925
+ }
926
+ /**
927
+ * Generates a new UUIDv7 object from the current timestamp, or resets the
928
+ * generator upon significant timestamp rollback.
929
+ *
930
+ * This method returns a monotonically increasing UUID by reusing the previous
931
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
932
+ * preceding UUID's. However, when such a clock rollback is considered
933
+ * significant (i.e., by more than ten seconds), this method resets the
934
+ * generator and returns a new UUID based on the given timestamp, breaking the
935
+ * increasing order of UUIDs.
936
+ *
937
+ * See {@link generateOrAbort} for the other mode of generation and
938
+ * {@link generateOrResetCore} for the low-level primitive.
939
+ */
940
+ V7Generator.prototype.generate = function () {
941
+ return this.generateOrResetCore(Date.now(), 10000);
942
+ };
943
+ /**
944
+ * Generates a new UUIDv7 object from the current timestamp, or returns
945
+ * `undefined` upon significant timestamp rollback.
946
+ *
947
+ * This method returns a monotonically increasing UUID by reusing the previous
948
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
949
+ * preceding UUID's. However, when such a clock rollback is considered
950
+ * significant (i.e., by more than ten seconds), this method aborts and
951
+ * returns `undefined` immediately.
952
+ *
953
+ * See {@link generate} for the other mode of generation and
954
+ * {@link generateOrAbortCore} for the low-level primitive.
955
+ */
956
+ V7Generator.prototype.generateOrAbort = function () {
957
+ return this.generateOrAbortCore(Date.now(), 10000);
958
+ };
959
+ /**
960
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or resets the
961
+ * generator upon significant timestamp rollback.
962
+ *
963
+ * This method is equivalent to {@link generate} except that it takes a custom
964
+ * timestamp and clock rollback allowance.
965
+ *
966
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
967
+ * considered significant. A suggested value is `10_000` (milliseconds).
968
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
969
+ */
970
+ V7Generator.prototype.generateOrResetCore = function (unixTsMs, rollbackAllowance) {
971
+ var value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
972
+ if (value === undefined) {
973
+ // reset state and resume
974
+ this.timestamp = 0;
975
+ value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
976
+ }
977
+ return value;
978
+ };
979
+ /**
980
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or returns
981
+ * `undefined` upon significant timestamp rollback.
982
+ *
983
+ * This method is equivalent to {@link generateOrAbort} except that it takes a
984
+ * custom timestamp and clock rollback allowance.
985
+ *
986
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
987
+ * considered significant. A suggested value is `10_000` (milliseconds).
988
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
989
+ */
990
+ V7Generator.prototype.generateOrAbortCore = function (unixTsMs, rollbackAllowance) {
991
+ var MAX_COUNTER = 4398046511103;
992
+ if (!Number.isInteger(unixTsMs) ||
993
+ unixTsMs < 1 ||
994
+ unixTsMs > 281474976710655) {
995
+ throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
996
+ }
997
+ else if (rollbackAllowance < 0 || rollbackAllowance > 281474976710655) {
998
+ throw new RangeError("`rollbackAllowance` out of reasonable range");
999
+ }
1000
+ if (unixTsMs > this.timestamp) {
1001
+ this.timestamp = unixTsMs;
1002
+ this.resetCounter();
1003
+ }
1004
+ else if (unixTsMs + rollbackAllowance >= this.timestamp) {
1005
+ // go on with previous timestamp if new one is not much smaller
1006
+ this.counter++;
1007
+ if (this.counter > MAX_COUNTER) {
1008
+ // increment timestamp at counter overflow
1009
+ this.timestamp++;
1010
+ this.resetCounter();
1011
+ }
1012
+ }
1013
+ else {
1014
+ // abort if clock went backwards to unbearable extent
1015
+ return undefined;
1016
+ }
1017
+ return UUID.fromFieldsV7(this.timestamp, Math.trunc(this.counter / Math.pow(2, 30)), this.counter & (Math.pow(2, 30) - 1), this.random.nextUint32());
1018
+ };
1019
+ /** Initializes the counter at a 42-bit random integer. */
1020
+ V7Generator.prototype.resetCounter = function () {
1021
+ this.counter =
1022
+ this.random.nextUint32() * 0x400 + (this.random.nextUint32() & 0x3ff);
1023
+ };
1024
+ /**
1025
+ * Generates a new UUIDv4 object utilizing the random number generator inside.
1026
+ *
1027
+ * @internal
1028
+ */
1029
+ V7Generator.prototype.generateV4 = function () {
1030
+ var bytes = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
1031
+ bytes[6] = 0x40 | (bytes[6] >>> 4);
1032
+ bytes[8] = 0x80 | (bytes[8] >>> 2);
1033
+ return UUID.ofInner(bytes);
1034
+ };
1035
+ return V7Generator;
1036
+ }());
1037
+ /** A global flag to force use of cryptographically strong RNG. */
1038
+ // declare const UUIDV7_DENY_WEAK_RNG: boolean;
1039
+ /** Returns the default random number generator available in the environment. */
1040
+ var getDefaultRandom = function () {
1041
+ // fix: crypto isn't available in react-native, always use Math.random
1042
+ // // detect Web Crypto API
1043
+ // if (
1044
+ // typeof crypto !== "undefined" &&
1045
+ // typeof crypto.getRandomValues !== "undefined"
1046
+ // ) {
1047
+ // return new BufferedCryptoRandom();
1048
+ // } else {
1049
+ // // fall back on Math.random() unless the flag is set to true
1050
+ // if (typeof UUIDV7_DENY_WEAK_RNG !== "undefined" && UUIDV7_DENY_WEAK_RNG) {
1051
+ // throw new Error("no cryptographically strong RNG available");
1052
+ // }
1053
+ // return {
1054
+ // nextUint32: (): number =>
1055
+ // Math.trunc(Math.random() * 0x1_0000) * 0x1_0000 +
1056
+ // Math.trunc(Math.random() * 0x1_0000),
1057
+ // };
1058
+ // }
1059
+ return {
1060
+ nextUint32: function () {
1061
+ return Math.trunc(Math.random() * 65536) * 65536 +
1062
+ Math.trunc(Math.random() * 65536);
1063
+ },
1064
+ };
1065
+ };
1066
+ // /**
1067
+ // * Wraps `crypto.getRandomValues()` to enable buffering; this uses a small
1068
+ // * buffer by default to avoid both unbearable throughput decline in some
1069
+ // * environments and the waste of time and space for unused values.
1070
+ // */
1071
+ // class BufferedCryptoRandom {
1072
+ // private readonly buffer = new Uint32Array(8);
1073
+ // private cursor = 0xffff;
1074
+ // nextUint32(): number {
1075
+ // if (this.cursor >= this.buffer.length) {
1076
+ // crypto.getRandomValues(this.buffer);
1077
+ // this.cursor = 0;
1078
+ // }
1079
+ // return this.buffer[this.cursor++];
1080
+ // }
1081
+ // }
1082
+ var defaultGenerator;
1083
+ /**
1084
+ * Generates a UUIDv7 string.
1085
+ *
1086
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
1087
+ * ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
1088
+ */
1089
+ var uuidv7 = function () { return uuidv7obj().toString(); };
1090
+ /** Generates a UUIDv7 object. */
1091
+ var uuidv7obj = function () {
1092
+ return (defaultGenerator || (defaultGenerator = new V7Generator())).generate();
1093
+ };
1094
+
708
1095
  var PostHogFetchHttpError = /** @class */ (function (_super) {
709
1096
  __extends(PostHogFetchHttpError, _super);
710
1097
  function PostHogFetchHttpError(response) {
@@ -796,7 +1183,7 @@ var PostHogCoreStateless = /** @class */ (function () {
796
1183
  };
797
1184
  PostHogCoreStateless.prototype.addPendingPromise = function (promise) {
798
1185
  var _this = this;
799
- var promiseUUID = generateUUID();
1186
+ var promiseUUID = uuidv7();
800
1187
  this.pendingPromises[promiseUUID] = promise;
801
1188
  promise.finally(function () {
802
1189
  delete _this.pendingPromises[promiseUUID];
@@ -1000,7 +1387,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1000
1387
  this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1001
1388
  return;
1002
1389
  }
1003
- 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(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : generateUUID(globalThis) });
1390
+ 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(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : uuidv7() });
1004
1391
  var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
1005
1392
  if (addGeoipDisableProperty) {
1006
1393
  if (!message.properties) {
@@ -1100,7 +1487,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1100
1487
  return ctrl.signal;
1101
1488
  });
1102
1489
  return [4 /*yield*/, retriable(function () { return __awaiter(_this, void 0, void 0, function () {
1103
- var res, e_1;
1490
+ var res, e_1, isNoCors;
1104
1491
  return __generator(this, function (_a) {
1105
1492
  switch (_a.label) {
1106
1493
  case 0:
@@ -1117,7 +1504,8 @@ var PostHogCoreStateless = /** @class */ (function () {
1117
1504
  // fetch will only throw on network errors or on timeouts
1118
1505
  throw new PostHogFetchNetworkError(e_1);
1119
1506
  case 4:
1120
- if (res.status < 200 || res.status >= 400) {
1507
+ isNoCors = options.mode === 'no-cors';
1508
+ if (!isNoCors && (res.status < 200 || res.status >= 400)) {
1121
1509
  throw new PostHogFetchHttpError(res);
1122
1510
  }
1123
1511
  return [2 /*return*/, res];
@@ -1265,7 +1653,7 @@ var PostHogCore = /** @class */ (function (_super) {
1265
1653
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
1266
1654
  var sessionTimestamp = this.getPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp) || 0;
1267
1655
  if (!sessionId || Date.now() - sessionTimestamp > this._sessionExpirationTimeSeconds * 1000) {
1268
- sessionId = generateUUID(globalThis);
1656
+ sessionId = uuidv7();
1269
1657
  this.setPersistedProperty(PostHogPersistedProperty.SessionId, sessionId);
1270
1658
  }
1271
1659
  this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
@@ -1277,7 +1665,7 @@ var PostHogCore = /** @class */ (function (_super) {
1277
1665
  PostHogCore.prototype.getAnonymousId = function () {
1278
1666
  var anonId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
1279
1667
  if (!anonId) {
1280
- anonId = generateUUID(globalThis);
1668
+ anonId = uuidv7();
1281
1669
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, anonId);
1282
1670
  }
1283
1671
  return anonId;
@@ -1600,7 +1988,7 @@ var PostHogCore = /** @class */ (function (_super) {
1600
1988
  return PostHogCore;
1601
1989
  }(PostHogCoreStateless));
1602
1990
 
1603
- var version = "2.6.0";
1991
+ var version = "2.6.2";
1604
1992
 
1605
1993
  function getContext(window) {
1606
1994
  var context = {};