saasco-sdk 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -201,6 +201,7 @@ Any property that starts with `$` is a property that has been generated by the S
201
201
  | $latitude | Latitude | Latitude of the user's IP location. |
202
202
  | $longitude | Longitude | Longitude of the user's IP location. |
203
203
  | $timezone | Timezone | Timezone of the user parsed from the IP. |
204
+ | $locale | Locale | The most recent preferred language of the user. |
204
205
  | $screenHeight | Screen Height | The most recent height of the device screen in pixels |
205
206
  | $screenWidth | Screen Width | The most recent width of the device screen in pixels |
206
207
  | $screenDpi | Screen DPI | The most recent Pixel density of the device screen. |
package/index.cjs.js CHANGED
@@ -523,8 +523,8 @@ class Saasco {
523
523
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
524
524
  return;
525
525
  }
526
- this.initiAutoPageTracking();
527
526
  this.log('Saasco initialized', this.config);
527
+ this.initiAutoPageTracking();
528
528
  this.isInitialized = true;
529
529
  }
530
530
  debug(value) {
@@ -562,14 +562,14 @@ class Saasco {
562
562
  // Only has 96.63% global support, so we need to check for undefined
563
563
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
564
564
  const $location = isBrowser ? timezones[timezone] || ((_a = $locale === null || $locale === void 0 ? void 0 : $locale.split('-')) === null || _a === void 0 ? void 0 : _a[1]) || 'undefined' : undefined;
565
- const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
566
- const $title = isBrowser ? document.title : undefined;
567
- const $pathname = isBrowser ? window.location.pathname : undefined;
568
565
  const $href = isBrowser ? window.location.href : undefined;
566
+ const $pathname = isBrowser ? window.location.pathname : undefined;
567
+ const $referrer = isBrowser ? document.referrer : undefined;
568
+ const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
569
569
  const $screenHeight = isBrowser ? screen.height : undefined;
570
570
  const $screenWidth = isBrowser ? screen.width : undefined;
571
- const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
572
- const $referrer = isBrowser ? document.referrer : undefined;
571
+ const $title = isBrowser ? document.title : undefined;
572
+ const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
573
573
  const data = {
574
574
  id: uuid.v4(),
575
575
  timestamp: new Date().toISOString(),
@@ -611,8 +611,12 @@ class Saasco {
611
611
  // When the user gets identified as null this will reset the users session and anonymous id
612
612
  // This should only be called when distinctId is null and there is an existing userId.
613
613
  // This means the user has logged out and we should reset the session and anonymous IDs
614
- const reset = !distinctId && !!userId;
615
- if (reset) this.log('User logged out and session reset');
614
+ const userIdChangedToNull = !distinctId && !!userId;
615
+ if (userIdChangedToNull) this.log('User ID change to null. Session reset');
616
+ // If we have a userId, but a new user ID is provided, we should reset the session and anonymous IDs
617
+ const userIdChanged = !!userId && distinctId !== userId;
618
+ if (userIdChanged) this.log('User ID changed. Session reset');
619
+ const reset = userIdChangedToNull || userIdChanged;
616
620
  setSessionId({
617
621
  reset
618
622
  });
@@ -768,8 +772,7 @@ function coerceReservedProperties(properties) {
768
772
  schema: zod.z.coerce.string().url().optional()
769
773
  }, {
770
774
  key: 'displayName',
771
- coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username'],
772
- schema: zod.z.coerce.string().url().optional()
775
+ coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username']
773
776
  }];
774
777
  return coerce.reduce((acc, {
775
778
  key,
package/index.esm.js CHANGED
@@ -519,8 +519,8 @@ class Saasco {
519
519
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
520
520
  return;
521
521
  }
522
- this.initiAutoPageTracking();
523
522
  this.log('Saasco initialized', this.config);
523
+ this.initiAutoPageTracking();
524
524
  this.isInitialized = true;
525
525
  }
526
526
  debug(value) {
@@ -558,14 +558,14 @@ class Saasco {
558
558
  // Only has 96.63% global support, so we need to check for undefined
559
559
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
560
560
  const $location = isBrowser ? timezones[timezone] || ((_a = $locale === null || $locale === void 0 ? void 0 : $locale.split('-')) === null || _a === void 0 ? void 0 : _a[1]) || 'undefined' : undefined;
561
- const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
562
- const $title = isBrowser ? document.title : undefined;
563
- const $pathname = isBrowser ? window.location.pathname : undefined;
564
561
  const $href = isBrowser ? window.location.href : undefined;
562
+ const $pathname = isBrowser ? window.location.pathname : undefined;
563
+ const $referrer = isBrowser ? document.referrer : undefined;
564
+ const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
565
565
  const $screenHeight = isBrowser ? screen.height : undefined;
566
566
  const $screenWidth = isBrowser ? screen.width : undefined;
567
- const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
568
- const $referrer = isBrowser ? document.referrer : undefined;
567
+ const $title = isBrowser ? document.title : undefined;
568
+ const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
569
569
  const data = {
570
570
  id: v4(),
571
571
  timestamp: new Date().toISOString(),
@@ -607,8 +607,12 @@ class Saasco {
607
607
  // When the user gets identified as null this will reset the users session and anonymous id
608
608
  // This should only be called when distinctId is null and there is an existing userId.
609
609
  // This means the user has logged out and we should reset the session and anonymous IDs
610
- const reset = !distinctId && !!userId;
611
- if (reset) this.log('User logged out and session reset');
610
+ const userIdChangedToNull = !distinctId && !!userId;
611
+ if (userIdChangedToNull) this.log('User ID change to null. Session reset');
612
+ // If we have a userId, but a new user ID is provided, we should reset the session and anonymous IDs
613
+ const userIdChanged = !!userId && distinctId !== userId;
614
+ if (userIdChanged) this.log('User ID changed. Session reset');
615
+ const reset = userIdChangedToNull || userIdChanged;
612
616
  setSessionId({
613
617
  reset
614
618
  });
@@ -764,8 +768,7 @@ function coerceReservedProperties(properties) {
764
768
  schema: z.coerce.string().url().optional()
765
769
  }, {
766
770
  key: 'displayName',
767
- coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username'],
768
- schema: z.coerce.string().url().optional()
771
+ coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username']
769
772
  }];
770
773
  return coerce.reduce((acc, {
771
774
  key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "@lukeed/uuid": "^2.0.1",