saasco-sdk 0.1.23 → 0.1.25

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
@@ -3,8 +3,8 @@
3
3
  ---
4
4
 
5
5
  - [Privacy](#privacy)
6
- - [Getting Started](#initiate-the-lib)
7
- - [Init Automatic Page View Tracking](#init-automatic-page-view-tracking)
6
+ - [Getting Started](#getting-started)
7
+ - [Automatic Page View Tracking](#automatic-page-view-tracking)
8
8
  - [Tracking Events](#tracking-events)
9
9
  - [Identifying Users](#identifying-users)
10
10
  - [Debugging and Dev](#debugging-and-dev)
@@ -12,7 +12,7 @@
12
12
 
13
13
  <br />
14
14
 
15
- ## 🔒 Privacy
15
+ ## 🔒 Privacy
16
16
 
17
17
  By default Saasco is privacy friendly, using no cookies and obscuring all activity behind Anonymous IDs. However if you want to power more complex user tracking you can identify users and then all events they do will be attributed to them in your CRM. This can assist with customer support but also for things like drip campaigns and other marketing activities.
18
18
 
@@ -22,9 +22,9 @@ Install by running:
22
22
  `npm install saasco-sdk`
23
23
 
24
24
  Copy your Project ID from the project settings page in Saasco:
25
- [https://saasco.com/your-project/settings/project](https://saasco.com/your-projects/settings/project)
25
+ [https://www.saasco.com/projects/your-project/apps/dashboard/settings/project](https://www.saasco.com/projects/your-project/apps/dashboard/settings/project)
26
26
 
27
- Then import Saasco and initiate the lib with your Project ID.
27
+ Then import Saasco and initialize the lib with your Project ID.
28
28
 
29
29
  ```ts
30
30
  // lib/saasco.ts
@@ -35,7 +35,7 @@ export const saasco = new Saasco({ projectId: 'YOUR-PROJECT-ID' });
35
35
 
36
36
  ## Automatic Page View Tracking
37
37
 
38
- When you initiate the lib Saasco will automatically start tracking all page views in your app. By default, it tracks all URL changes, including query parameters and hash changes. You can customize this behavior using the `autoPageTracking` configuration object:
38
+ When you initialize the lib Saasco will automatically start tracking all page views in your app. By default, it tracks all URL changes, including query parameters and hash changes. You can customize this behavior using the `autoPageTracking` configuration object:
39
39
 
40
40
  ```typescript
41
41
  const analytics = new Saasco({
@@ -54,15 +54,15 @@ You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-i
54
54
 
55
55
  ## Tracking Events
56
56
 
57
- With events you can track custom actions users are taking on your site with event properties. The track method supports both client-side (oarameter-style) and server-side (object-style) usage patterns.
57
+ With events you can track custom actions users are taking on your site with event properties. The track method supports both client-side (parameter-style) and server-side (object-style) usage patterns.
58
58
 
59
59
  Each event has 2 components:
60
60
 
61
61
  **Name** - this is the name of the action that was taken.
62
62
 
63
- _We like to follow segments [Object Action Framework](https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/) for naming events._
63
+ _We like to follow Segment's [Object Action Framework](https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/) for naming events._
64
64
 
65
- **Properties** - This is an object with the values of the event. Such as a the value, currency, or query.
65
+ **Properties** - This is an object with the values of the event. Such as the value, currency, or query.
66
66
 
67
67
  We currently have limited support for properties, but in the future we will support complex querying and actions based on event properties.
68
68
 
@@ -88,18 +88,19 @@ saasco.track("Searched Movies", {
88
88
  ### Server Usage (Object Style)
89
89
 
90
90
  For server-side tracking, use the object-style syntax.
91
- You must provide a userId for server side tracking events.
91
+ You must provide a userId for server side tracking events so there is a contact to connect the events to.
92
92
 
93
93
  ```tsx
94
94
  // Import saasco
95
95
  import { saasco } from '../lib/saasco.ts';
96
96
 
97
- // Track an event with full control
97
+ // Track an event and associate it with a user
98
98
  saasco.track({
99
- event: "User Signed Up",
99
+ event: "Signed Up",
100
100
  userId: "user_123",
101
- properties: { plan: "Pro" },
102
- context: { source: "server" },
101
+ properties: {
102
+ provider: 'email',
103
+ }
103
104
  });
104
105
  ```
105
106
 
@@ -133,7 +134,7 @@ function signedOut(){
133
134
 
134
135
  ### Identifying users who don't have an ID
135
136
 
136
- Often times you have a users contact details before they sign up for your site. This could be part of the signup flow, or if they were to subscribe to marketing emails before they sign up as a customer
137
+ Often times you have a user's contact details before they sign up for your site. This could be part of the signup flow, or if they were to subscribe to marketing emails before they sign up as a customer
137
138
 
138
139
  Saasco allows identifying users without an id by simply skipping the `ID` part of the identify call. This will add contacts to the CRM for email marketing and other tools before users register.
139
140
 
@@ -152,7 +153,7 @@ By doing this users will get tracked and added to your contacts, and as soon as
152
153
 
153
154
  ### Soft vs Full identify
154
155
 
155
- When users are identified without a `ID` we call this is a "Soft Identify". Users who are soft identified can also be called "Leads".
156
+ When users are identified without an `ID` we call this a "Soft Identify". Users who are soft identified can also be called "Leads".
156
157
  Once a user signs up and you identify them with an `ID` they will be fully registered and can be called "Customers"
157
158
 
158
159
  In the CRM when you identify a user, either soft or full, they become a contact.
@@ -175,43 +176,50 @@ export const saasco = new Saasco({
175
176
 
176
177
  #### Debugging
177
178
 
178
- You can turn on debugging when you initiate the repo or by running saasco.debug(true) in your code or the browser.
179
+ You can turn on debugging when you initialize the repo or by running `saasco.enableDebug()` in your code or the browser.
179
180
 
180
181
  ```tsx
181
182
  export const saasco = new Saasco({
182
183
  projectId: 'YOUR-PROJECT-ID',
183
184
  enabled: process.env['NODE_ENV'] === 'production',
184
185
  // Set to true to console log analytics events.
185
- // This works even when enabled is false - it just wont send the data
186
+ // This works even when enabled is false - it just won't send the data
186
187
  debug: true,
187
188
  });
188
189
  ```
189
190
 
190
- You can also enable debug mode by calling `saasco.debug(true)` anywhere in your code.
191
+ You can also enable debug mode by calling `saasco.enableDebug()` anywhere in your code.
191
192
 
192
193
  ```tsx
193
- saasco.debug(true);
194
+ saasco.enableDebug();
194
195
  // will console log "debug mode activated"
195
196
  ```
196
197
 
198
+ You can disable debug mode by calling `saasco.disableDebug()`.
199
+
200
+ ```tsx
201
+ saasco.disableDebug();
202
+ // will console log "debug mode deactivated"
203
+ ```
204
+
197
205
  ## Reserved Properties
198
206
 
199
- Saasco has reserved some properties that have semantic meanings for contacts and, and will handle them in special ways.
207
+ Saasco has reserved some properties that have semantic meanings for contacts and will handle them in special ways.
200
208
  For example, Saasco always expects email to be a string of the user's email address, this is important for when sending emails using the marketing app.
201
209
  The SDK will do its best to match these properties, eg (created_at will be mapped to createdAt), but if possible you should use the reserved properties.
202
210
 
203
211
  ### Reserved Contact Properties
204
212
 
205
- | PROPTERTY | TYPE | DESCRIPTION |
213
+ | PROPERTY | TYPE | DESCRIPTION |
206
214
  | ----------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
207
215
  | age | Number | Age of a user |
208
216
  | avatar | String | URL to an avatar image for the user |
209
217
  | birthday | Date | User's birthday |
210
- | createdAt | Date | Date the user's account was first created. We recomend recommend using ISO-8601 date strings. |
218
+ | createdAt | Date | Date the user's account was first created. We recommend using ISO-8601 date strings. |
211
219
  | description | String | Description of the user |
212
220
  | email | String | Email address of a user |
213
221
  | firstName | String | First name of a user |
214
- | displayName | String | The prefered users display name, will default to "firstName lastName" |
222
+ | displayName | String | The preferred user's display name, will default to "firstName lastName" |
215
223
  | gender | String | Gender of a user |
216
224
  | lastName | String | Last name of a user |
217
225
  | name | String | Full name of a user. If you only pass a first and last name Segment automatically fills in the full name for you. |
@@ -236,11 +244,11 @@ Any property that starts with `$` is a property that has been generated by the S
236
244
  | $locale | Locale | The most recent preferred language of the user. |
237
245
  | $screenHeight | Screen Height | The most recent height of the device screen in pixels |
238
246
  | $screenWidth | Screen Width | The most recent width of the device screen in pixels |
239
- | $screenDpi | Screen DPI | The most recent Pixel density of the device screen. |
247
+ | $screenDpi | Screen DPI | The most recent pixel density of the device screen. |
240
248
  | $lastSeen | Last Seen | The last time a user was identified while active was not false in the context |
241
249
  | $os | Operating System | The most recent OS of the user. |
242
250
  | $browser | Browser | The most recent browser of the user. |
243
- | $browserVersion | Browser Version | The most recent bowser version of the user. |
251
+ | $browserVersion | Browser Version | The most recent browser version of the user. |
244
252
  | $initialReferrer | Initial Referrer | Referring URL when the user first arrived on your site. Defaults to "direct" |
245
253
  | $referrer | Last Touch Referrer | Referring URL when the user last interacted with your site. Defaults to "direct" |
246
254
  | $initialReferringDomain | Initial Referring Domain | Referring domain at first arrival. Defaults to "direct" |
@@ -272,11 +280,11 @@ Properties used to calculate revenue for different traffic sources and LTV for u
272
280
  | -------- | ------ | ----------------------------------------------------------------------------------------- |
273
281
  | revenue | Number | Amount of revenue an event resulted in. This should be a decimal value |
274
282
  | currency | String | Currency of the revenue an event resulted in. This should be sent in the ISO 4127 format. |
275
- | value | Number | An abstract numerical value used internally to score eventsm such as lead scoring. |
283
+ | value | Number | An abstract numerical value used internally to score events, such as lead scoring. |
276
284
 
277
285
  ### Default Event Properties
278
286
 
279
- Our SDKs automatically collect certain properties on every event or user profile. The default properties begin with a `$` and can be overwritten with your own identify calls, so we recomend avoiding leading `$` in your identify call properties to avoid conflicts.
287
+ Our SDKs automatically collect certain properties on every event or user profile. The default properties begin with a `$` and can be overwritten with your own identify calls, so we recommend avoiding leading `$` in your identify call properties to avoid conflicts.
280
288
 
281
289
  | Property | Display Name | Description |
282
290
  | ---------------- | --------------------------- | -------------------------------------------------------------------------------- |
@@ -343,16 +351,19 @@ saasco.track('Signed Up', {
343
351
  Event triggered when a user signs in.
344
352
  | Property | Description |
345
353
  |----------|--------------------------------------------------|
346
- | `method` | The method used for signing in (e.g., email, social media). |
354
+ | `provider` | The provider used for signing in (e.g., email, github, google). |
347
355
 
348
356
  Example:
349
357
 
350
358
  ```jsx
351
359
  saasco.track('Signed In', {
352
- method: 'email',
360
+ provider: 'email',
353
361
  });
354
362
  ```
355
363
 
364
+ Note:
365
+ When tracking Signed In events call identify('user_id', {email: '...'}) before the event to connect to the user.
366
+
356
367
  #### Signed Out
357
368
 
358
369
  Event triggered when a user signs out.
@@ -364,13 +375,16 @@ Example:
364
375
  saasco.track('Signed Out');
365
376
  ```
366
377
 
378
+ Note:
379
+ When tracking Signed Out events call identify(null) _after_ tracking the event to reset the session.
380
+
367
381
  #### Trial Started
368
382
 
369
383
  Event triggered when a user starts a trial.
370
384
  | Property | Description |
371
385
  |-------------------|---------------------------------------------------------------------|
372
386
  | `duration` | The duration of the trial in days |
373
- | `type`| Values can be `optIn` for then the user didn't provide a cc or `optOut` when the user provided a cc and it will automatically start and the end of the trial period|
387
+ | `type`| Values can be `optIn` for when the user didn't provide a cc or `optOut` when the user provided a cc and it will automatically start at the end of the trial period|
374
388
 
375
389
  Example:
376
390
 
@@ -380,10 +394,10 @@ saasco.track('Trial Started', { duration: 14, type: 'optOut' });
380
394
 
381
395
  #### Trial Ended
382
396
 
383
- Event triggered when a users trial ends.
397
+ Event triggered when a user's trial ends.
384
398
  | Property | Description |
385
399
  |-------------------|---------------------------------------------------------------------|
386
- | `daysLeftInTrial`| If a user manual upgrades before the end of the trial you can record this here|
400
+ | `daysLeftInTrial`| If a user manually upgrades before the end of the trial you can record this here|
387
401
 
388
402
  Example:
389
403
 
@@ -391,10 +405,10 @@ Example:
391
405
  saasco.track('Trial Ended', { daysLeftInTrial: 4 });
392
406
  ```
393
407
 
394
- #### Payment Ended
408
+ #### Payment Completed
395
409
 
396
410
  Event triggered when a payment is completed.
397
- This is may be called on the server side after a confirmation webhook.
411
+ This may be called on the server side after a confirmation webhook.
398
412
  This is helpful for recording ongoing subscription payments.
399
413
 
400
414
  | Property | Description |
@@ -458,7 +472,7 @@ Event triggered when a subscription is upgraded.
458
472
  Example:
459
473
 
460
474
  ```jsx
461
- saasco.track('Subscription Cancelled', {
475
+ saasco.track('Subscription Upgraded', {
462
476
  fromPlan: 'Monthly',
463
477
  toPlan: 'Annual',
464
478
  previousRevenue: 29,
@@ -475,13 +489,13 @@ Event triggered when a subscription is downgraded.
475
489
  | `toPlan` | The new plan. |
476
490
  | `previousRevenue` | The revenue from the previous plan. |
477
491
  | `newRevenue` | The revenue from the new plan. |
478
- | `revenue` | If the customer is refunded immediately then include a revenue number here, in the case of a downgrade this will be a negtive value. Only include the revenue here if it's not tracked on your backend or with a webhook |
492
+ | `revenue` | If the customer is refunded immediately then include a revenue number here, in the case of a downgrade this will be a negative value. Only include the revenue here if it's not tracked on your backend or with a webhook |
479
493
  | `currency` | The currency of the payment, assumed to be USD unless otherwise specified. |
480
494
 
481
495
  Example:
482
496
 
483
497
  ```jsx
484
- saasco.track('Subscription Cancelled', {
498
+ saasco.track('Subscription Downgraded', {
485
499
  fromPlan: 'Annual',
486
500
  toPlan: 'Monthly',
487
501
  previousRevenue: 129,
@@ -503,7 +517,7 @@ All properties should be added as data attributes in the format data-[prop name]
503
517
  ></script>
504
518
  ```
505
519
 
506
- All the properties for initiating the sdk can be passed in like this:
520
+ All the properties for initializing the sdk can be passed in like this:
507
521
 
508
522
  ```jsx
509
523
  <script
package/index.cjs.js CHANGED
@@ -6,7 +6,7 @@ var tslib = require('tslib');
6
6
  var uuid = require('@lukeed/uuid');
7
7
  var zod = require('zod');
8
8
 
9
- var version = "0.1.23";
9
+ var version = "0.1.25";
10
10
 
11
11
  const timezones = {
12
12
  'Asia/Barnaul': 'RU',
@@ -526,7 +526,7 @@ function setSessionId({
526
526
  function getAnonymousId() {
527
527
  return retrieveData(`anonymous-id`);
528
528
  }
529
- function setAnonmousId({
529
+ function setAnonymousId({
530
530
  reset
531
531
  } = {
532
532
  reset: false
@@ -582,7 +582,7 @@ class Saasco {
582
582
  this.log('Saasco initialized', this.config);
583
583
  if (this.config.debug) this.log('Debug mode active. This will log all events to the console.');
584
584
  if (!this.config.enabled) this.log('Analytics is disabled. No requests will be sent to the server.');
585
- this.initiAutoPageTracking();
585
+ this.initAutoPageTracking();
586
586
  this.isInitialized = true;
587
587
  }
588
588
  disableDebug() {
@@ -599,7 +599,7 @@ class Saasco {
599
599
  return Promise.resolve(response);
600
600
  }
601
601
  setSessionId();
602
- setAnonmousId();
602
+ setAnonymousId();
603
603
  const hasAction = typeof actionOrPayload === 'string';
604
604
  const hasPayload = typeof actionOrPayload === 'object';
605
605
  // Must do payload on the server
@@ -682,7 +682,7 @@ class Saasco {
682
682
  setSessionId({
683
683
  reset
684
684
  });
685
- const anonymousId = setAnonmousId({
685
+ const anonymousId = setAnonymousId({
686
686
  reset
687
687
  });
688
688
  // set the distinct Id to the userId
@@ -787,7 +787,7 @@ class Saasco {
787
787
  * It listens to url changes to track new pages every time the url changes
788
788
  * @returns
789
789
  */
790
- initiAutoPageTracking() {
790
+ initAutoPageTracking() {
791
791
  var _a, _b;
792
792
  // Disable auto page tracking if the config is set to false
793
793
  if (!((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.enabled)) return;
package/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { __awaiter } from 'tslib';
2
2
  import { v4 } from '@lukeed/uuid';
3
3
  import { z } from 'zod';
4
4
 
5
- var version = "0.1.23";
5
+ var version = "0.1.25";
6
6
 
7
7
  const timezones = {
8
8
  'Asia/Barnaul': 'RU',
@@ -522,7 +522,7 @@ function setSessionId({
522
522
  function getAnonymousId() {
523
523
  return retrieveData(`anonymous-id`);
524
524
  }
525
- function setAnonmousId({
525
+ function setAnonymousId({
526
526
  reset
527
527
  } = {
528
528
  reset: false
@@ -578,7 +578,7 @@ class Saasco {
578
578
  this.log('Saasco initialized', this.config);
579
579
  if (this.config.debug) this.log('Debug mode active. This will log all events to the console.');
580
580
  if (!this.config.enabled) this.log('Analytics is disabled. No requests will be sent to the server.');
581
- this.initiAutoPageTracking();
581
+ this.initAutoPageTracking();
582
582
  this.isInitialized = true;
583
583
  }
584
584
  disableDebug() {
@@ -595,7 +595,7 @@ class Saasco {
595
595
  return Promise.resolve(response);
596
596
  }
597
597
  setSessionId();
598
- setAnonmousId();
598
+ setAnonymousId();
599
599
  const hasAction = typeof actionOrPayload === 'string';
600
600
  const hasPayload = typeof actionOrPayload === 'object';
601
601
  // Must do payload on the server
@@ -678,7 +678,7 @@ class Saasco {
678
678
  setSessionId({
679
679
  reset
680
680
  });
681
- const anonymousId = setAnonmousId({
681
+ const anonymousId = setAnonymousId({
682
682
  reset
683
683
  });
684
684
  // set the distinct Id to the userId
@@ -783,7 +783,7 @@ class Saasco {
783
783
  * It listens to url changes to track new pages every time the url changes
784
784
  * @returns
785
785
  */
786
- initiAutoPageTracking() {
786
+ initAutoPageTracking() {
787
787
  var _a, _b;
788
788
  // Disable auto page tracking if the config is set to false
789
789
  if (!((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.enabled)) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "@lukeed/uuid": "^2.0.1",
@@ -11,11 +11,14 @@ type Identity = {
11
11
  anonymousId: string | number;
12
12
  userId?: string | number;
13
13
  };
14
+ type Context = {
15
+ active?: boolean;
16
+ };
14
17
  type TrackPayload = Identity & {
15
18
  event: string;
16
19
  sessionId?: string;
17
20
  properties?: Record<string, any>;
18
- context?: Record<string, any>;
21
+ context?: Context;
19
22
  };
20
23
  type DoRequestResponse = {
21
24
  success: boolean;
@@ -55,9 +58,7 @@ export declare class Saasco {
55
58
  * Client: track('User Signed Up', { plan: 'Pro' }, { source: 'client' })
56
59
  * Server: track({ event: 'User Signed Up', userId: 'user_123', properties: { plan: 'Pro' } })
57
60
  */
58
- track(action: string, properties?: Record<string, any>, context?: {
59
- active?: boolean;
60
- }): Promise<DoRequestResponse>;
61
+ track(action: string, properties?: Record<string, any>, context?: Context): Promise<DoRequestResponse>;
61
62
  track(payload: TrackPayload): Promise<DoRequestResponse>;
62
63
  /**
63
64
  * The page method lets you record page views on your website
@@ -75,12 +76,8 @@ export declare class Saasco {
75
76
  * @param properties A dictionary of traits you know about the user like their email, name, plan etc.
76
77
  * @param context Context for the identify call such as whether the user is active.
77
78
  */
78
- identify(properties: Record<string, any>, context?: {
79
- active?: boolean;
80
- }): Promise<DoRequestResponse>;
81
- identify(distinctId: string | number | null, properties?: Record<string, any>, context?: {
82
- active?: boolean;
83
- }): Promise<DoRequestResponse>;
79
+ identify(properties: Record<string, any>, context?: Context): Promise<DoRequestResponse>;
80
+ identify(distinctId: string | number | null, properties?: Record<string, any>, context?: Context): Promise<DoRequestResponse>;
84
81
  /**
85
82
  * This should only be called when the user logs out
86
83
  * It will reset the session, anonymous id, and user id
@@ -109,6 +106,6 @@ export declare class Saasco {
109
106
  * It listens to url changes to track new pages every time the url changes
110
107
  * @returns
111
108
  */
112
- private initiAutoPageTracking;
109
+ private initAutoPageTracking;
113
110
  }
114
111
  export {};