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/module.d.ts CHANGED
@@ -417,7 +417,7 @@ declare class PostHogPersistence {
417
417
  expire_days: number | undefined;
418
418
  default_expiry: number | undefined;
419
419
  cross_subdomain: boolean | undefined;
420
- user_state: 'anonymous' | 'identified' | undefined;
420
+ user_state: 'anonymous' | 'identified';
421
421
  constructor(config: PostHogConfig);
422
422
  properties(): Properties;
423
423
  load(): void;
@@ -453,7 +453,7 @@ declare class PostHogPersistence {
453
453
  set_secure(secure: boolean): void;
454
454
  set_event_timer(event_name: string, timestamp: number): void;
455
455
  remove_event_timer(event_name: string): number;
456
- get_user_state(): 'anonymous' | 'identified' | undefined;
456
+ get_user_state(): 'anonymous' | 'identified';
457
457
  set_user_state(state: 'anonymous' | 'identified'): void;
458
458
  }
459
459
 
@@ -1132,7 +1132,7 @@ declare class PostHog {
1132
1132
  /**
1133
1133
  * Identify a user with a unique ID instead of a PostHog
1134
1134
  * randomly generated distinct_id. If the method is never called,
1135
- * then unique visitors will be identified by a UUID generated
1135
+ * then unique visitors will be identified by a UUID that is generated
1136
1136
  * the first time they visit the site.
1137
1137
  *
1138
1138
  * If user properties are passed, they are also sent to posthog.
@@ -1146,21 +1146,30 @@ declare class PostHog {
1146
1146
  * ### Notes:
1147
1147
  *
1148
1148
  * You can call this function to overwrite a previously set
1149
- * unique ID for the current user. PostHog cannot translate
1150
- * between IDs at this time, so when you change a user's ID
1151
- * they will appear to be a new user.
1152
- *
1153
- * When used alone, posthog.identify will change the user's
1154
- * distinct_id to the unique ID provided. When used in tandem
1155
- * with posthog.alias, it will allow you to identify based on
1156
- * unique ID and map that back to the original, anonymous
1157
- * distinct_id given to the user upon her first arrival to your
1158
- * site (thus connecting anonymous pre-signup activity to
1159
- * post-signup activity). Though the two work together, do not
1160
- * call identify() at the same time as alias(). Calling the two
1161
- * at the same time can cause a race condition, so it is best
1162
- * practice to call identify on the original, anonymous ID
1163
- * right after you've aliased it.
1149
+ * unique ID for the current user.
1150
+ *
1151
+ * If the user has been identified ($user_state in persistence is set to 'identified'),
1152
+ * then capture of $identify is skipped to avoid merging users. For example,
1153
+ * if your system allows an admin user to impersonate another user.
1154
+ *
1155
+ * Then a single browser instance can have:
1156
+ *
1157
+ * `identify('a') -> capture(1) -> identify('b') -> capture(2)`
1158
+ *
1159
+ * and capture 1 and capture 2 will have the correct distinct_id.
1160
+ * but users a and b will NOT be merged in posthog.
1161
+ *
1162
+ * However, if reset is called then:
1163
+ *
1164
+ * `identify('a') -> capture(1) -> reset() -> capture(2) -> identify('b') -> capture(3)`
1165
+ *
1166
+ * users a and b are not merged.
1167
+ * Capture 1 is associated with user a.
1168
+ * A new distinct id is generated for capture 2.
1169
+ * which is merged with user b.
1170
+ * So, capture 2 and 3 are associated with user b.
1171
+ *
1172
+ * If you want to merge two identified users, you can call posthog.alias
1164
1173
  *
1165
1174
  * @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.
1166
1175
  * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
package/dist/module.js CHANGED
@@ -921,7 +921,7 @@ var LZString = {
921
921
  }
922
922
  };
923
923
 
924
- var version = "1.45.0";
924
+ var version = "1.45.1";
925
925
 
926
926
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
927
927
 
@@ -3585,7 +3585,7 @@ var PostHogPersistence = /*#__PURE__*/function () {
3585
3585
  this.storage = cookieStore;
3586
3586
  }
3587
3587
 
3588
- this.user_state = undefined;
3588
+ this.user_state = 'anonymous';
3589
3589
  this.load();
3590
3590
  this.update_config(config);
3591
3591
  this.save();
@@ -3834,7 +3834,7 @@ var PostHogPersistence = /*#__PURE__*/function () {
3834
3834
  }, {
3835
3835
  key: "get_user_state",
3836
3836
  value: function get_user_state() {
3837
- return this.props[USER_STATE];
3837
+ return this.props[USER_STATE] || 'anonymous';
3838
3838
  }
3839
3839
  }, {
3840
3840
  key: "set_user_state",
@@ -7390,7 +7390,7 @@ var PostHog = /*#__PURE__*/function () {
7390
7390
  /**
7391
7391
  * Identify a user with a unique ID instead of a PostHog
7392
7392
  * randomly generated distinct_id. If the method is never called,
7393
- * then unique visitors will be identified by a UUID generated
7393
+ * then unique visitors will be identified by a UUID that is generated
7394
7394
  * the first time they visit the site.
7395
7395
  *
7396
7396
  * If user properties are passed, they are also sent to posthog.
@@ -7404,21 +7404,30 @@ var PostHog = /*#__PURE__*/function () {
7404
7404
  * ### Notes:
7405
7405
  *
7406
7406
  * You can call this function to overwrite a previously set
7407
- * unique ID for the current user. PostHog cannot translate
7408
- * between IDs at this time, so when you change a user's ID
7409
- * they will appear to be a new user.
7410
- *
7411
- * When used alone, posthog.identify will change the user's
7412
- * distinct_id to the unique ID provided. When used in tandem
7413
- * with posthog.alias, it will allow you to identify based on
7414
- * unique ID and map that back to the original, anonymous
7415
- * distinct_id given to the user upon her first arrival to your
7416
- * site (thus connecting anonymous pre-signup activity to
7417
- * post-signup activity). Though the two work together, do not
7418
- * call identify() at the same time as alias(). Calling the two
7419
- * at the same time can cause a race condition, so it is best
7420
- * practice to call identify on the original, anonymous ID
7421
- * right after you've aliased it.
7407
+ * unique ID for the current user.
7408
+ *
7409
+ * If the user has been identified ($user_state in persistence is set to 'identified'),
7410
+ * then capture of $identify is skipped to avoid merging users. For example,
7411
+ * if your system allows an admin user to impersonate another user.
7412
+ *
7413
+ * Then a single browser instance can have:
7414
+ *
7415
+ * `identify('a') -> capture(1) -> identify('b') -> capture(2)`
7416
+ *
7417
+ * and capture 1 and capture 2 will have the correct distinct_id.
7418
+ * but users a and b will NOT be merged in posthog.
7419
+ *
7420
+ * However, if reset is called then:
7421
+ *
7422
+ * `identify('a') -> capture(1) -> reset() -> capture(2) -> identify('b') -> capture(3)`
7423
+ *
7424
+ * users a and b are not merged.
7425
+ * Capture 1 is associated with user a.
7426
+ * A new distinct id is generated for capture 2.
7427
+ * which is merged with user b.
7428
+ * So, capture 2 and 3 are associated with user b.
7429
+ *
7430
+ * If you want to merge two identified users, you can call posthog.alias
7422
7431
  *
7423
7432
  * @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.
7424
7433
  * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
@@ -7449,8 +7458,7 @@ var PostHog = /*#__PURE__*/function () {
7449
7458
  $had_persisted_distinct_id: true,
7450
7459
  $device_id: device_id
7451
7460
  }, '');
7452
- } // identify only changes the distinct id if it doesn't match either the existing or the alias;
7453
- // if it's new, blow away the alias as well.
7461
+ } // if the previous distinct id had an alias stored, then we clear it
7454
7462
 
7455
7463
 
7456
7464
  if (new_distinct_id !== previous_distinct_id && new_distinct_id !== this.get_property(ALIAS_ID_KEY)) {
@@ -7460,11 +7468,10 @@ var PostHog = /*#__PURE__*/function () {
7460
7468
  });
7461
7469
  }
7462
7470
 
7463
- var deviceIdMarksForIdentify = !this.get_property('$device_id');
7464
7471
  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
7465
7472
  // - logic on the server will determine whether or not to do anything with it.
7466
7473
 
7467
- if (new_distinct_id !== previous_distinct_id && (isKnownAnonymous || deviceIdMarksForIdentify)) {
7474
+ if (new_distinct_id !== previous_distinct_id && isKnownAnonymous) {
7468
7475
  this.persistence.set_user_state('identified');
7469
7476
  this.capture('$identify', {
7470
7477
  distinct_id: new_distinct_id,