posthog-js 1.42.3 → 1.43.1

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/dist/es.js CHANGED
@@ -917,7 +917,7 @@ var LZString = {
917
917
  }
918
918
  };
919
919
 
920
- var version = "1.42.3";
920
+ var version = "1.43.1";
921
921
 
922
922
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
923
923
 
@@ -3536,7 +3536,8 @@ var SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_s
3536
3536
  var CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side';
3537
3537
  var SESSION_ID = '$sesid';
3538
3538
  var ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
3539
- var RESERVED_PROPERTIES = [SET_QUEUE_KEY, SET_ONCE_QUEUE_KEY, UNSET_QUEUE_KEY, ADD_QUEUE_KEY, APPEND_QUEUE_KEY, REMOVE_QUEUE_KEY, UNION_QUEUE_KEY, PEOPLE_DISTINCT_ID_KEY, ALIAS_ID_KEY, CAMPAIGN_IDS_KEY, EVENT_TIMERS_KEY, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_ID, ENABLED_FEATURE_FLAGS];
3539
+ var USER_STATE = '$user_state';
3540
+ var RESERVED_PROPERTIES = [SET_QUEUE_KEY, SET_ONCE_QUEUE_KEY, UNSET_QUEUE_KEY, ADD_QUEUE_KEY, APPEND_QUEUE_KEY, REMOVE_QUEUE_KEY, UNION_QUEUE_KEY, PEOPLE_DISTINCT_ID_KEY, ALIAS_ID_KEY, CAMPAIGN_IDS_KEY, EVENT_TIMERS_KEY, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_ID, ENABLED_FEATURE_FLAGS, USER_STATE];
3540
3541
  /**
3541
3542
  * PostHog Persistence Object
3542
3543
  * @constructor
@@ -3580,6 +3581,7 @@ var PostHogPersistence = /*#__PURE__*/function () {
3580
3581
  this.storage = cookieStore;
3581
3582
  }
3582
3583
 
3584
+ this.user_state = undefined;
3583
3585
  this.load();
3584
3586
  this.update_config(config);
3585
3587
  this.save();
@@ -3825,6 +3827,17 @@ var PostHogPersistence = /*#__PURE__*/function () {
3825
3827
 
3826
3828
  return timestamp;
3827
3829
  }
3830
+ }, {
3831
+ key: "get_user_state",
3832
+ value: function get_user_state() {
3833
+ return this.props[USER_STATE];
3834
+ }
3835
+ }, {
3836
+ key: "set_user_state",
3837
+ value: function set_user_state(state) {
3838
+ this.props[USER_STATE] = state;
3839
+ this.save();
3840
+ }
3828
3841
  }]);
3829
3842
 
3830
3843
  return PostHogPersistence;
@@ -6657,16 +6670,18 @@ var PostHog = /*#__PURE__*/function () {
6657
6670
  this.register({
6658
6671
  distinct_id: config.segment.user().id()
6659
6672
  });
6673
+ this.persistence.set_user_state('identified');
6660
6674
  }
6661
6675
 
6662
6676
  config.segment.register(this.segmentIntegration());
6663
6677
  }
6664
6678
 
6665
6679
  if (((_config$bootstrap = config.bootstrap) === null || _config$bootstrap === void 0 ? void 0 : _config$bootstrap.distinctID) !== undefined) {
6666
- var _config$bootstrap2;
6680
+ var _config$bootstrap2, _config$bootstrap3;
6667
6681
 
6668
6682
  var uuid = this.get_config('get_device_id')(_UUID());
6669
6683
  var deviceID = (_config$bootstrap2 = config.bootstrap) !== null && _config$bootstrap2 !== void 0 && _config$bootstrap2.isIdentifiedID ? uuid : config.bootstrap.distinctID;
6684
+ this.persistence.set_user_state((_config$bootstrap3 = config.bootstrap) !== null && _config$bootstrap3 !== void 0 && _config$bootstrap3.isIdentifiedID ? 'identified' : 'anonymous');
6670
6685
  this.register({
6671
6686
  distinct_id: config.bootstrap.distinctID,
6672
6687
  $device_id: deviceID
@@ -6674,26 +6689,26 @@ var PostHog = /*#__PURE__*/function () {
6674
6689
  }
6675
6690
 
6676
6691
  if (this._hasBootstrappedFeatureFlags()) {
6677
- var _config$bootstrap3, _config$bootstrap6;
6692
+ var _config$bootstrap4, _config$bootstrap7;
6678
6693
 
6679
- var activeFlags = Object.keys(((_config$bootstrap3 = config.bootstrap) === null || _config$bootstrap3 === void 0 ? void 0 : _config$bootstrap3.featureFlags) || {}).filter(function (flag) {
6680
- var _config$bootstrap4, _config$bootstrap4$fe;
6694
+ var activeFlags = Object.keys(((_config$bootstrap4 = config.bootstrap) === null || _config$bootstrap4 === void 0 ? void 0 : _config$bootstrap4.featureFlags) || {}).filter(function (flag) {
6695
+ var _config$bootstrap5, _config$bootstrap5$fe;
6681
6696
 
6682
- return !!((_config$bootstrap4 = config.bootstrap) !== null && _config$bootstrap4 !== void 0 && (_config$bootstrap4$fe = _config$bootstrap4.featureFlags) !== null && _config$bootstrap4$fe !== void 0 && _config$bootstrap4$fe[flag]);
6697
+ return !!((_config$bootstrap5 = config.bootstrap) !== null && _config$bootstrap5 !== void 0 && (_config$bootstrap5$fe = _config$bootstrap5.featureFlags) !== null && _config$bootstrap5$fe !== void 0 && _config$bootstrap5$fe[flag]);
6683
6698
  }).reduce(function (res, key) {
6684
- var _config$bootstrap5, _config$bootstrap5$fe;
6699
+ var _config$bootstrap6, _config$bootstrap6$fe;
6685
6700
 
6686
- return res[key] = ((_config$bootstrap5 = config.bootstrap) === null || _config$bootstrap5 === void 0 ? void 0 : (_config$bootstrap5$fe = _config$bootstrap5.featureFlags) === null || _config$bootstrap5$fe === void 0 ? void 0 : _config$bootstrap5$fe[key]) || false, res;
6701
+ return res[key] = ((_config$bootstrap6 = config.bootstrap) === null || _config$bootstrap6 === void 0 ? void 0 : (_config$bootstrap6$fe = _config$bootstrap6.featureFlags) === null || _config$bootstrap6$fe === void 0 ? void 0 : _config$bootstrap6$fe[key]) || false, res;
6687
6702
  }, {});
6688
- var featureFlagPayloads = Object.keys(((_config$bootstrap6 = config.bootstrap) === null || _config$bootstrap6 === void 0 ? void 0 : _config$bootstrap6.featureFlagPayloads) || {}).filter(function (key) {
6703
+ var featureFlagPayloads = Object.keys(((_config$bootstrap7 = config.bootstrap) === null || _config$bootstrap7 === void 0 ? void 0 : _config$bootstrap7.featureFlagPayloads) || {}).filter(function (key) {
6689
6704
  return activeFlags[key];
6690
6705
  }).reduce(function (res, key) {
6691
- var _config$bootstrap7, _config$bootstrap7$fe;
6706
+ var _config$bootstrap8, _config$bootstrap8$fe;
6692
6707
 
6693
- if ((_config$bootstrap7 = config.bootstrap) !== null && _config$bootstrap7 !== void 0 && (_config$bootstrap7$fe = _config$bootstrap7.featureFlagPayloads) !== null && _config$bootstrap7$fe !== void 0 && _config$bootstrap7$fe[key]) {
6694
- var _config$bootstrap8, _config$bootstrap8$fe;
6708
+ if ((_config$bootstrap8 = config.bootstrap) !== null && _config$bootstrap8 !== void 0 && (_config$bootstrap8$fe = _config$bootstrap8.featureFlagPayloads) !== null && _config$bootstrap8$fe !== void 0 && _config$bootstrap8$fe[key]) {
6709
+ var _config$bootstrap9, _config$bootstrap9$fe;
6695
6710
 
6696
- res[key] = (_config$bootstrap8 = config.bootstrap) === null || _config$bootstrap8 === void 0 ? void 0 : (_config$bootstrap8$fe = _config$bootstrap8.featureFlagPayloads) === null || _config$bootstrap8$fe === void 0 ? void 0 : _config$bootstrap8$fe[key];
6711
+ res[key] = (_config$bootstrap9 = config.bootstrap) === null || _config$bootstrap9 === void 0 ? void 0 : (_config$bootstrap9$fe = _config$bootstrap9.featureFlagPayloads) === null || _config$bootstrap9$fe === void 0 ? void 0 : _config$bootstrap9$fe[key];
6697
6712
  }
6698
6713
 
6699
6714
  return res;
@@ -6713,7 +6728,9 @@ var PostHog = /*#__PURE__*/function () {
6713
6728
  this.register_once({
6714
6729
  distinct_id: _uuid,
6715
6730
  $device_id: _uuid
6716
- }, '');
6731
+ }, ''); // distinct id == $device_id is a proxy for anonymous user
6732
+
6733
+ this.persistence.set_user_state('anonymous');
6717
6734
  } // Set up event handler for pageleave
6718
6735
  // Use `onpagehide` if available, see https://calendar.perfplanet.com/2020/beaconing-in-practice/#beaconing-reliability-avoiding-abandons
6719
6736
 
@@ -7422,11 +7439,14 @@ var PostHog = /*#__PURE__*/function () {
7422
7439
  this.register({
7423
7440
  distinct_id: new_distinct_id
7424
7441
  });
7425
- } // send an $identify event any time the distinct_id is changing and the old ID is an anoymous ID
7426
- // - logic on the server will determine whether or not to do anything with it.
7442
+ }
7427
7443
 
7444
+ var deviceIdMarksForIdentify = !this.get_property('$device_id');
7445
+ var isKnownAnonymous = this.persistence.get_user_state() === 'anonymous'; // send an $identify event any time the distinct_id is changing and the old ID is an anoymous ID
7446
+ // - logic on the server will determine whether or not to do anything with it.
7428
7447
 
7429
- if (new_distinct_id !== previous_distinct_id && (!this.get_property('$device_id') || previous_distinct_id === this.get_property('$device_id'))) {
7448
+ if (new_distinct_id !== previous_distinct_id && (isKnownAnonymous || deviceIdMarksForIdentify)) {
7449
+ this.persistence.set_user_state('identified');
7430
7450
  this.capture('$identify', {
7431
7451
  distinct_id: new_distinct_id,
7432
7452
  $anon_distinct_id: previous_distinct_id
@@ -7514,6 +7534,7 @@ var PostHog = /*#__PURE__*/function () {
7514
7534
  value: function reset(reset_device_id) {
7515
7535
  var device_id = this.get_property('$device_id');
7516
7536
  this.persistence.clear();
7537
+ this.persistence.set_user_state('anonymous');
7517
7538
  this.sessionManager.resetSessionId();
7518
7539
  var uuid = this.get_config('get_device_id')(_UUID());
7519
7540
  this.register_once({