saasco-sdk 0.1.0 → 0.1.3

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
@@ -1,8 +1,5 @@
1
1
  [Saasco](https://www.saasco.com) is a platform of saas apps where members only pay the infrastructure cost of what they use. As a result Saasco apps are up to 99% cheaper than traditional saas products.
2
2
 
3
- The analytics package makes it easy for javascript projects to track website activity.
4
- Analytics is a core feature of Saasco and is used to power many other apps.
5
-
6
3
  ---
7
4
 
8
5
  - [Privacy](#privacy)
@@ -23,34 +20,23 @@ By default Saasco is privacy friendly, using no cookies and obscuring all activi
23
20
  ## Getting Started:
24
21
 
25
22
  Install by running:
26
- `npm install saasco-analytics`
23
+ `npm install saasco-sdk`
27
24
 
28
25
  Copy your Project ID from the project settings page in Saasco:
29
26
  [https://saasco.com/your-project/settings/project](https://saasco.com/your-projects/settings/project)
30
27
 
31
- Then import Analytics and initiate the lib with your Project ID.
32
-
33
- ```tsx
34
- import { Analytics } from 'saasco-analytics';
35
-
36
- // Initiate the lib
37
- export const analytics = new Analytics({ projectId: "YOUR-PROJECT-ID" });
38
- ```
28
+ Then import Saasco and initiate the lib with your Project ID.
39
29
 
40
- ### Naming Conflict
30
+ ```ts
41
31
 
42
- Because “Analytics” is a common name for analytics tools you can simply import with a different name such as “SaascoAnalytics” to avoid conflicts.
43
-
44
- For example:
45
-
46
- ```tsx
47
- import { Analytics as SaascoAnalytics } from 'saasco-analytics';
32
+ // lib/saasco.ts
33
+ import { Saasco } from 'saasco-sdk';
48
34
 
49
35
  // Initiate the lib
50
- const saascoAnalytics = new SaascoAnalytics({ projectId: "YOUR-PROJECT-ID" });
36
+ const saasco = new Saasco({ projectId: "YOUR-PROJECT-ID" });
37
+ saasco.init();
51
38
 
52
- // Track an event
53
- saascoAnalytics.track('Something happened');
39
+ export saasco;
54
40
  ```
55
41
 
56
42
  ## Automatic Page View Tracking
@@ -73,14 +59,14 @@ _We like to follow segments [Object Action Framework](https://segment.com/academ
73
59
  We currently have limited support for properties, but in the future we will support complex querying and actions based on event properties.
74
60
 
75
61
  ```tsx
76
- // Import analytics
77
- import { analytics } from '../your-analytics';
62
+ // Import saasco
63
+ import { saasco } from '../lib/saasco.ts';
78
64
 
79
65
  // Track an event
80
- analytics.track("Searched Movies");
66
+ saasco.track("Searched Movies");
81
67
 
82
68
  // Track an event with properties
83
- analytics.track("Searched Movies", {
69
+ saasco.track("Searched Movies", {
84
70
  query:"batman",
85
71
  sortBy:"relevancy"
86
72
  });
@@ -93,14 +79,14 @@ By default Saasco does not track any identifiable data about users, just anonymo
93
79
  To do this just identify a user with their DistinctId (usually the user ID from your database) and then any properties on the user.
94
80
 
95
81
  ```tsx
96
- // Import analytics
97
- import { analytics } from '../your-analytics';
82
+ // Import saasco
83
+ import { saasco } from '../lib/saasco.ts';
98
84
 
99
85
  // Inside your user logged in function identify a user
100
86
  // You should only identify users when they login, or their properties change
101
87
  function signedIn(){
102
88
  // Identify a user
103
- analytics.identify("USER-ID-FROM-YOUR-DB", {
89
+ saasco.identify("USER-ID-FROM-YOUR-DB", {
104
90
  // Any user properties you want to record with the user
105
91
  name:"Tony Hawk",
106
92
  email:"tony@xgames.com",
@@ -110,7 +96,7 @@ function signedIn(){
110
96
 
111
97
  // When a user logs out you can unidentify by identify null
112
98
  function signedOut(){
113
- analtyics.identify(null)
99
+ saasco.identify(null)
114
100
  }
115
101
  ```
116
102
 
@@ -124,7 +110,7 @@ For example:
124
110
 
125
111
  ```tsx
126
112
  // Identify a user only by their email
127
- analytics.identify({
113
+ saasco.identify({
128
114
  name:"Tony Hawk",
129
115
  email:"tony@xgames.com",
130
116
  bestTrick: 900
@@ -148,7 +134,7 @@ When setting up Saasco analytics you probably want to exclude your local environ
148
134
  To do so simply turn on dev mode.
149
135
 
150
136
  ```tsx
151
- export const analytics = new Analytics({
137
+ export const saasco = new Saasco({
152
138
  projectId: 'YOUR-PROJECT-ID',
153
139
 
154
140
  // use an env to only set enabled to true on production
@@ -158,10 +144,10 @@ export const analytics = new Analytics({
158
144
 
159
145
  #### Debugging
160
146
 
161
- You can turn on debugging when you initiate the repo or by running analytics.debug(true) in your code or the browser.
147
+ You can turn on debugging when you initiate the repo or by running saasco.debug(true) in your code or the browser.
162
148
 
163
149
  ```tsx
164
- export const analytics = new Analytics({
150
+ export const saasco = new Saasco({
165
151
  projectId: 'YOUR-PROJECT-ID',
166
152
  enabled: process.env['NODE_ENV'] === 'production',
167
153
  // Set to true to console log analytics events.
@@ -170,10 +156,10 @@ export const analytics = new Analytics({
170
156
  });
171
157
  ```
172
158
 
173
- You can also enable debug mode by calling `analytics.debug(true)` anywhere in your code.
159
+ You can also enable debug mode by calling `saasco.debug(true)` anywhere in your code.
174
160
 
175
161
  ```tsx
176
- analytics.debug(true);
162
+ saasco.debug(true);
177
163
  // will console log "debug mode activated"
178
164
  ```
179
165
 
@@ -305,7 +291,7 @@ Event triggered when a user signs up.
305
291
  Example:
306
292
 
307
293
  ```jsx
308
- analytics.track('Signed Up', {
294
+ saasco.track('Signed Up', {
309
295
  source: 'Referral by friend',
310
296
  });
311
297
  ```
@@ -320,7 +306,7 @@ Event triggered when a user signs in.
320
306
  Example:
321
307
 
322
308
  ```jsx
323
- analytics.track('Signed In', {
309
+ saasco.track('Signed In', {
324
310
  method: 'email',
325
311
  });
326
312
  ```
@@ -333,7 +319,7 @@ No optional properties.
333
319
  Example:
334
320
 
335
321
  ```jsx
336
- analytics.track('Signed Out');
322
+ saasco.track('Signed Out');
337
323
  ```
338
324
 
339
325
  #### Trial Started
@@ -347,7 +333,7 @@ Event triggered when a user starts a trial.
347
333
  Example:
348
334
 
349
335
  ```jsx
350
- analytics.track('Trial Started', { duration: 14, type: 'optOut' });
336
+ saasco.track('Trial Started', { duration: 14, type: 'optOut' });
351
337
  ```
352
338
 
353
339
  #### Trial Completed
@@ -360,7 +346,7 @@ Event triggered when a user successfully completes a trial.
360
346
  Example:
361
347
 
362
348
  ```jsx
363
- analytics.track('Trial Completed', { daysLeftInTrial: 4 });
349
+ saasco.track('Trial Completed', { daysLeftInTrial: 4 });
364
350
  ```
365
351
 
366
352
  #### Payment Completed
@@ -377,7 +363,7 @@ This is helpful for recording ongoing subscription payments.
377
363
  Example:
378
364
 
379
365
  ```jsx
380
- analytics.track('Payment Completed', { revenue: 29.99, currency: 'GBP' });
366
+ saasco.track('Payment Completed', { revenue: 29.99, currency: 'GBP' });
381
367
  ```
382
368
 
383
369
  #### Subscription Started
@@ -394,7 +380,7 @@ If you have integrated with stripe for revenue tracking or are doing server side
394
380
  Example:
395
381
 
396
382
  ```jsx
397
- analytics.track('Subscription Started', {
383
+ saasco.track('Subscription Started', {
398
384
  plan: 'Monthly',
399
385
  });
400
386
  ```
@@ -410,7 +396,7 @@ Event triggered when a subscription is cancelled.
410
396
  Example:
411
397
 
412
398
  ```jsx
413
- analytics.track('Subscription Cancelled', {
399
+ saasco.track('Subscription Cancelled', {
414
400
  reason: 'Not using it any more',
415
401
  });
416
402
  ```
@@ -430,7 +416,7 @@ Event triggered when a subscription is upgraded.
430
416
  Example:
431
417
 
432
418
  ```jsx
433
- analytics.track('Subscription Cancelled', {
419
+ saasco.track('Subscription Cancelled', {
434
420
  fromPlan: 'Monthly',
435
421
  toPlan: 'Annual',
436
422
  previousRevenue: 29,
@@ -453,7 +439,7 @@ Event triggered when a subscription is downgraded.
453
439
  Example:
454
440
 
455
441
  ```jsx
456
- analytics.track('Subscription Cancelled', {
442
+ saasco.track('Subscription Cancelled', {
457
443
  fromPlan: 'Annual',
458
444
  toPlan: 'Monthly',
459
445
  previousRevenue: 129,
@@ -470,7 +456,7 @@ All properties should be added as data attributes in the format data-[prop name]
470
456
 
471
457
  ```jsx
472
458
  <script
473
- src="https://saasco.com/sdk/analytics-sdk.js"
459
+ src="https://saasco.com/sdk/saasco-sdk.js"
474
460
  data-projectId="YOUR-PROJECT-ID"
475
461
  ></script>
476
462
  ```
@@ -479,7 +465,7 @@ All the properties for initiating the sdk can be passed in like this:
479
465
 
480
466
  ```jsx
481
467
  <script
482
- src="https://saasco.com/sdk/analytics-sdk.js"
468
+ src="https://saasco.com/sdk/saasco-sdk.js"
483
469
  data-projectId="YOUR-PROJECT-ID"
484
470
  data-debug="true" // pass any properties as data params
485
471
  ></script>
@@ -488,17 +474,17 @@ All the properties for initiating the sdk can be passed in like this:
488
474
  You can then call the track and identify methods like so:
489
475
 
490
476
  ```jsx
491
- analytics.track('Searched Movies');
477
+ saasco.track('Searched Movies');
492
478
  ```
493
479
 
494
480
  For type safety in your TypeScript project, you can use the following in an `index.d.ts` file
495
481
 
496
482
  ```jsx
497
- import { Analytics } from 'saasco-analytics';
483
+ import { Saasco } from 'saasco-sdk';
498
484
 
499
485
  declare global {
500
486
  interface Window {
501
- analytics?: Analytics;
487
+ saasco?: Saasco;
502
488
  }
503
489
  }
504
490
  ```
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";