saasco-sdk 0.1.11 → 0.1.13

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
@@ -35,8 +35,8 @@ export const saasco = new Saasco({ projectId: 'YOUR-PROJECT-ID' });
35
35
 
36
36
  ## Init Automatic Page View Tracking
37
37
 
38
- When you initial the lib Saasco will automatically start tracking all page views in your app. There is no other configuration. It will automatically track url changes, even for SPAs like NextJs and Vue.
39
- You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-in-SPAs-2442fc7586dc4208ae8f669eb7561b1a?pvs=21) by opting our of automatic page tracking. For most use cases you don't need to do this.
38
+ When you initiate the lib Saasco will automatically start tracking all page views in your app. There is no other configuration. It will automatically track url changes, even for SPAs like NextJs and Vue.
39
+ You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-in-SPAs-2442fc7586dc4208ae8f669eb7561b1a?pvs=21) by opting out of automatic page tracking. For most use cases you don't need to do this.
40
40
 
41
41
  ```ts
42
42
  // ./app/index
package/index.cjs.js CHANGED
@@ -434,7 +434,7 @@ const timezones = {
434
434
  'Asia/Calcutta': 'IN'
435
435
  };
436
436
 
437
- var version = "0.1.11";
437
+ var version = "0.1.13";
438
438
 
439
439
  const isBrowser = typeof window !== 'undefined';
440
440
  let userId = null;
@@ -547,6 +547,10 @@ class Saasco {
547
547
  this.config = config;
548
548
  this.lastPageViewHref = '';
549
549
  this.isInitialized = false;
550
+ if (!config.projectId) {
551
+ this.error("Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
552
+ return;
553
+ }
550
554
  // default enabled to true
551
555
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
552
556
  }
@@ -583,6 +587,9 @@ class Saasco {
583
587
  track(name,
584
588
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
585
589
  properties, context) {
590
+ if (!this.config.projectId) {
591
+ return this.error("Unable to track event. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
592
+ }
586
593
  // Prevent duplicate Page View tracking
587
594
  if (name === 'Page View') {
588
595
  if (!isBrowser) {
@@ -622,6 +629,9 @@ class Saasco {
622
629
  return this.track('Page View');
623
630
  }
624
631
  identify(distinctIdOrProperties, propertiesOrContext, contextOrNothing) {
632
+ if (!this.config.projectId) {
633
+ return this.error("Unable to identify user. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
634
+ }
625
635
  const hasId = typeof distinctIdOrProperties === 'string' || typeof distinctIdOrProperties === 'number' || distinctIdOrProperties === null;
626
636
  const distinctId = hasId ? distinctIdOrProperties === null || distinctIdOrProperties === void 0 ? void 0 : distinctIdOrProperties.toString() : `soft_${uuid.v4()}`;
627
637
  const properties = hasId ? propertiesOrContext : distinctIdOrProperties;
@@ -678,13 +688,13 @@ class Saasco {
678
688
  body: JSON.stringify(data)
679
689
  });
680
690
  if (!response.ok) {
681
- throw new Error(response.status.toString());
691
+ const errorBody = yield response.json();
692
+ throw new Error(`${errorBody.message}: ${errorBody.errors ? `[${errorBody.errors.join(', ')}]` : ''}` || JSON.stringify(errorBody));
682
693
  }
683
694
  return response;
684
695
  } catch (error) {
685
- const errorMessage = 'Error with Saasco request: ' + error.message;
686
- console.error(errorMessage, path, data);
687
- return errorMessage;
696
+ this.error(`\nError Message: "${error.message}"`, `\nPath: "/${path}"`, `\nRequest Data: ${JSON.stringify(data, null, 2)}`);
697
+ return error.message;
688
698
  }
689
699
  });
690
700
  }
@@ -698,6 +708,15 @@ class Saasco {
698
708
  // Message highlighted for easy finding
699
709
  ...args]);
700
710
  }
711
+ /**
712
+ * @param args Arguments to be logged
713
+ */
714
+ error(...args) {
715
+ const message = '◍ Saasco Error';
716
+ console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
717
+ // Message highlighted for easy finding
718
+ ...args]);
719
+ }
701
720
  /**
702
721
  * If autoPageTracking is enabled, this will automatically track page views
703
722
  * It listens to url changes to track new pages every time the url changes
package/index.esm.js CHANGED
@@ -430,7 +430,7 @@ const timezones = {
430
430
  'Asia/Calcutta': 'IN'
431
431
  };
432
432
 
433
- var version = "0.1.11";
433
+ var version = "0.1.13";
434
434
 
435
435
  const isBrowser = typeof window !== 'undefined';
436
436
  let userId = null;
@@ -543,6 +543,10 @@ class Saasco {
543
543
  this.config = config;
544
544
  this.lastPageViewHref = '';
545
545
  this.isInitialized = false;
546
+ if (!config.projectId) {
547
+ this.error("Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
548
+ return;
549
+ }
546
550
  // default enabled to true
547
551
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
548
552
  }
@@ -579,6 +583,9 @@ class Saasco {
579
583
  track(name,
580
584
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
581
585
  properties, context) {
586
+ if (!this.config.projectId) {
587
+ return this.error("Unable to track event. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
588
+ }
582
589
  // Prevent duplicate Page View tracking
583
590
  if (name === 'Page View') {
584
591
  if (!isBrowser) {
@@ -618,6 +625,9 @@ class Saasco {
618
625
  return this.track('Page View');
619
626
  }
620
627
  identify(distinctIdOrProperties, propertiesOrContext, contextOrNothing) {
628
+ if (!this.config.projectId) {
629
+ return this.error("Unable to identify user. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
630
+ }
621
631
  const hasId = typeof distinctIdOrProperties === 'string' || typeof distinctIdOrProperties === 'number' || distinctIdOrProperties === null;
622
632
  const distinctId = hasId ? distinctIdOrProperties === null || distinctIdOrProperties === void 0 ? void 0 : distinctIdOrProperties.toString() : `soft_${v4()}`;
623
633
  const properties = hasId ? propertiesOrContext : distinctIdOrProperties;
@@ -674,13 +684,13 @@ class Saasco {
674
684
  body: JSON.stringify(data)
675
685
  });
676
686
  if (!response.ok) {
677
- throw new Error(response.status.toString());
687
+ const errorBody = yield response.json();
688
+ throw new Error(`${errorBody.message}: ${errorBody.errors ? `[${errorBody.errors.join(', ')}]` : ''}` || JSON.stringify(errorBody));
678
689
  }
679
690
  return response;
680
691
  } catch (error) {
681
- const errorMessage = 'Error with Saasco request: ' + error.message;
682
- console.error(errorMessage, path, data);
683
- return errorMessage;
692
+ this.error(`\nError Message: "${error.message}"`, `\nPath: "/${path}"`, `\nRequest Data: ${JSON.stringify(data, null, 2)}`);
693
+ return error.message;
684
694
  }
685
695
  });
686
696
  }
@@ -694,6 +704,15 @@ class Saasco {
694
704
  // Message highlighted for easy finding
695
705
  ...args]);
696
706
  }
707
+ /**
708
+ * @param args Arguments to be logged
709
+ */
710
+ error(...args) {
711
+ const message = '◍ Saasco Error';
712
+ console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
713
+ // Message highlighted for easy finding
714
+ ...args]);
715
+ }
697
716
  /**
698
717
  * If autoPageTracking is enabled, this will automatically track page views
699
718
  * It listens to url changes to track new pages every time the url changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "@lukeed/uuid": "^2.0.1",
@@ -37,14 +37,14 @@ export declare class Saasco {
37
37
  */
38
38
  track(name: string, properties?: Record<string, any>, context?: {
39
39
  active?: boolean;
40
- }): Promise<string | Response | undefined> | undefined;
40
+ }): void | Promise<any>;
41
41
  /**
42
42
  * The page method lets you record page views on your website
43
43
  * This records the page title and path and names the event useing the reserved property "Page Viewed"
44
44
  *
45
45
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
46
46
  */
47
- page(): Promise<string | Response | undefined> | undefined;
47
+ page(): void | Promise<any>;
48
48
  /**
49
49
  * The identify method lets you tie a user to their actions and record traits about them.
50
50
  * We recommend you call this when the user logs in and when any traits get updated.
@@ -71,6 +71,10 @@ export declare class Saasco {
71
71
  * @param args Arguments to be logged
72
72
  */
73
73
  private log;
74
+ /**
75
+ * @param args Arguments to be logged
76
+ */
77
+ private error;
74
78
  /**
75
79
  * If autoPageTracking is enabled, this will automatically track page views
76
80
  * It listens to url changes to track new pages every time the url changes