posthog-js 1.45.0 → 1.45.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.45.0";
920
+ var version = "1.45.1";
921
921
 
922
922
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
923
923
 
@@ -3581,7 +3581,7 @@ var PostHogPersistence = /*#__PURE__*/function () {
3581
3581
  this.storage = cookieStore;
3582
3582
  }
3583
3583
 
3584
- this.user_state = undefined;
3584
+ this.user_state = 'anonymous';
3585
3585
  this.load();
3586
3586
  this.update_config(config);
3587
3587
  this.save();
@@ -3830,7 +3830,7 @@ var PostHogPersistence = /*#__PURE__*/function () {
3830
3830
  }, {
3831
3831
  key: "get_user_state",
3832
3832
  value: function get_user_state() {
3833
- return this.props[USER_STATE];
3833
+ return this.props[USER_STATE] || 'anonymous';
3834
3834
  }
3835
3835
  }, {
3836
3836
  key: "set_user_state",
@@ -7386,7 +7386,7 @@ var PostHog = /*#__PURE__*/function () {
7386
7386
  /**
7387
7387
  * Identify a user with a unique ID instead of a PostHog
7388
7388
  * randomly generated distinct_id. If the method is never called,
7389
- * then unique visitors will be identified by a UUID generated
7389
+ * then unique visitors will be identified by a UUID that is generated
7390
7390
  * the first time they visit the site.
7391
7391
  *
7392
7392
  * If user properties are passed, they are also sent to posthog.
@@ -7400,21 +7400,30 @@ var PostHog = /*#__PURE__*/function () {
7400
7400
  * ### Notes:
7401
7401
  *
7402
7402
  * You can call this function to overwrite a previously set
7403
- * unique ID for the current user. PostHog cannot translate
7404
- * between IDs at this time, so when you change a user's ID
7405
- * they will appear to be a new user.
7406
- *
7407
- * When used alone, posthog.identify will change the user's
7408
- * distinct_id to the unique ID provided. When used in tandem
7409
- * with posthog.alias, it will allow you to identify based on
7410
- * unique ID and map that back to the original, anonymous
7411
- * distinct_id given to the user upon her first arrival to your
7412
- * site (thus connecting anonymous pre-signup activity to
7413
- * post-signup activity). Though the two work together, do not
7414
- * call identify() at the same time as alias(). Calling the two
7415
- * at the same time can cause a race condition, so it is best
7416
- * practice to call identify on the original, anonymous ID
7417
- * right after you've aliased it.
7403
+ * unique ID for the current user.
7404
+ *
7405
+ * If the user has been identified ($user_state in persistence is set to 'identified'),
7406
+ * then capture of $identify is skipped to avoid merging users. For example,
7407
+ * if your system allows an admin user to impersonate another user.
7408
+ *
7409
+ * Then a single browser instance can have:
7410
+ *
7411
+ * `identify('a') -> capture(1) -> identify('b') -> capture(2)`
7412
+ *
7413
+ * and capture 1 and capture 2 will have the correct distinct_id.
7414
+ * but users a and b will NOT be merged in posthog.
7415
+ *
7416
+ * However, if reset is called then:
7417
+ *
7418
+ * `identify('a') -> capture(1) -> reset() -> capture(2) -> identify('b') -> capture(3)`
7419
+ *
7420
+ * users a and b are not merged.
7421
+ * Capture 1 is associated with user a.
7422
+ * A new distinct id is generated for capture 2.
7423
+ * which is merged with user b.
7424
+ * So, capture 2 and 3 are associated with user b.
7425
+ *
7426
+ * If you want to merge two identified users, you can call posthog.alias
7418
7427
  *
7419
7428
  * @param {String} [new_distinct_id] A string that uniquely identifies a user. If not provided, the distinct_id currently in the persistent store (cookie or localStorage) will be used.
7420
7429
  * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
@@ -7445,8 +7454,7 @@ var PostHog = /*#__PURE__*/function () {
7445
7454
  $had_persisted_distinct_id: true,
7446
7455
  $device_id: device_id
7447
7456
  }, '');
7448
- } // identify only changes the distinct id if it doesn't match either the existing or the alias;
7449
- // if it's new, blow away the alias as well.
7457
+ } // if the previous distinct id had an alias stored, then we clear it
7450
7458
 
7451
7459
 
7452
7460
  if (new_distinct_id !== previous_distinct_id && new_distinct_id !== this.get_property(ALIAS_ID_KEY)) {
@@ -7456,11 +7464,10 @@ var PostHog = /*#__PURE__*/function () {
7456
7464
  });
7457
7465
  }
7458
7466
 
7459
- var deviceIdMarksForIdentify = !this.get_property('$device_id');
7460
7467
  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
7461
7468
  // - logic on the server will determine whether or not to do anything with it.
7462
7469
 
7463
- if (new_distinct_id !== previous_distinct_id && (isKnownAnonymous || deviceIdMarksForIdentify)) {
7470
+ if (new_distinct_id !== previous_distinct_id && isKnownAnonymous) {
7464
7471
  this.persistence.set_user_state('identified');
7465
7472
  this.capture('$identify', {
7466
7473
  distinct_id: new_distinct_id,