saasco-sdk 0.1.15 → 0.1.16
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 +14 -13
- package/index.cjs.js +16 -10
- package/index.esm.js +16 -10
- package/package.json +1 -1
- package/src/lib/analytics.d.ts +5 -3
package/README.md
CHANGED
|
@@ -35,22 +35,23 @@ 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 configuration
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const analytics = new Saasco({
|
|
42
|
+
projectId: 'your-project-id',
|
|
43
|
+
autoPageTracking: {
|
|
44
|
+
enabled: true, // Set to false to disable automatic page tracking
|
|
45
|
+
trackQueryParams: true, // Set to false to ignore URL query parameter changes
|
|
46
|
+
trackHash: true, // Set to false to ignore URL hash changes
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
saasco.init();
|
|
50
|
+
analytics.init();
|
|
52
51
|
```
|
|
53
52
|
|
|
53
|
+
You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-in-SPAs-2442fc7586dc4208ae8f669eb7561b1a?pvs=21) by disabling automatic page tracking (`enabled: false`). For most use cases you don't need to do this.
|
|
54
|
+
|
|
54
55
|
## Tracking Events
|
|
55
56
|
|
|
56
57
|
With events you can track custom actions users are taking on your site with event properties.
|
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.
|
|
9
|
+
var version = "0.1.16";
|
|
10
10
|
|
|
11
11
|
const timezones = {
|
|
12
12
|
'Asia/Barnaul': 'RU',
|
|
@@ -562,9 +562,12 @@ class Saasco {
|
|
|
562
562
|
}
|
|
563
563
|
// default enabled to true
|
|
564
564
|
this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
|
|
565
|
-
// default
|
|
566
|
-
this.config.
|
|
567
|
-
|
|
565
|
+
// Set default auto page tracking config
|
|
566
|
+
this.config.autoPageTracking = Object.assign({
|
|
567
|
+
enabled: true,
|
|
568
|
+
trackQueryParams: true,
|
|
569
|
+
trackHash: true
|
|
570
|
+
}, this.config.autoPageTracking);
|
|
568
571
|
}
|
|
569
572
|
init() {
|
|
570
573
|
if (this.isInitialized) {
|
|
@@ -628,6 +631,7 @@ class Saasco {
|
|
|
628
631
|
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
629
632
|
*/
|
|
630
633
|
page() {
|
|
634
|
+
var _a, _b;
|
|
631
635
|
if (!isBrowser) {
|
|
632
636
|
console.warn('Saasco page tracking is only available in the browser');
|
|
633
637
|
return;
|
|
@@ -635,11 +639,11 @@ class Saasco {
|
|
|
635
639
|
const url = new URL(window.location.href);
|
|
636
640
|
let pathToCompare = url.pathname;
|
|
637
641
|
// Include search params if configured
|
|
638
|
-
if (this.config.
|
|
642
|
+
if ((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.trackQueryParams) {
|
|
639
643
|
pathToCompare += url.search;
|
|
640
644
|
}
|
|
641
645
|
// Include hash if configured
|
|
642
|
-
if (this.config.
|
|
646
|
+
if ((_b = this.config.autoPageTracking) === null || _b === void 0 ? void 0 : _b.trackHash) {
|
|
643
647
|
pathToCompare += url.hash;
|
|
644
648
|
}
|
|
645
649
|
// Only track if the path has changed
|
|
@@ -742,9 +746,9 @@ class Saasco {
|
|
|
742
746
|
* @returns
|
|
743
747
|
*/
|
|
744
748
|
initiAutoPageTracking() {
|
|
749
|
+
var _a, _b;
|
|
745
750
|
// Disable auto page tracking if the config is set to false
|
|
746
|
-
|
|
747
|
-
if (this.config.autoPageTracking === false) return;
|
|
751
|
+
if (!((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.enabled)) return;
|
|
748
752
|
// Prevent running on the server
|
|
749
753
|
if (!isBrowser) return console.warn('Saasco auto page tracking is only available in the browser');
|
|
750
754
|
// Prevent intitializing auto page tracking more than once
|
|
@@ -756,8 +760,10 @@ class Saasco {
|
|
|
756
760
|
this.log('Auto Page Tracking enabled');
|
|
757
761
|
// Track initial page load
|
|
758
762
|
this.page();
|
|
759
|
-
// Listen for hash changes
|
|
760
|
-
|
|
763
|
+
// Listen for hash changes if hash tracking is enabled
|
|
764
|
+
if ((_b = this.config.autoPageTracking) === null || _b === void 0 ? void 0 : _b.trackHash) {
|
|
765
|
+
window.addEventListener('hashchange', () => this.page());
|
|
766
|
+
}
|
|
761
767
|
// Listen to popstate for back and forward navigation
|
|
762
768
|
window.addEventListener('popstate', () => this.page());
|
|
763
769
|
// Wrap history push state to listen for URL changes
|
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.
|
|
5
|
+
var version = "0.1.16";
|
|
6
6
|
|
|
7
7
|
const timezones = {
|
|
8
8
|
'Asia/Barnaul': 'RU',
|
|
@@ -558,9 +558,12 @@ class Saasco {
|
|
|
558
558
|
}
|
|
559
559
|
// default enabled to true
|
|
560
560
|
this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
|
|
561
|
-
// default
|
|
562
|
-
this.config.
|
|
563
|
-
|
|
561
|
+
// Set default auto page tracking config
|
|
562
|
+
this.config.autoPageTracking = Object.assign({
|
|
563
|
+
enabled: true,
|
|
564
|
+
trackQueryParams: true,
|
|
565
|
+
trackHash: true
|
|
566
|
+
}, this.config.autoPageTracking);
|
|
564
567
|
}
|
|
565
568
|
init() {
|
|
566
569
|
if (this.isInitialized) {
|
|
@@ -624,6 +627,7 @@ class Saasco {
|
|
|
624
627
|
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
625
628
|
*/
|
|
626
629
|
page() {
|
|
630
|
+
var _a, _b;
|
|
627
631
|
if (!isBrowser) {
|
|
628
632
|
console.warn('Saasco page tracking is only available in the browser');
|
|
629
633
|
return;
|
|
@@ -631,11 +635,11 @@ class Saasco {
|
|
|
631
635
|
const url = new URL(window.location.href);
|
|
632
636
|
let pathToCompare = url.pathname;
|
|
633
637
|
// Include search params if configured
|
|
634
|
-
if (this.config.
|
|
638
|
+
if ((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.trackQueryParams) {
|
|
635
639
|
pathToCompare += url.search;
|
|
636
640
|
}
|
|
637
641
|
// Include hash if configured
|
|
638
|
-
if (this.config.
|
|
642
|
+
if ((_b = this.config.autoPageTracking) === null || _b === void 0 ? void 0 : _b.trackHash) {
|
|
639
643
|
pathToCompare += url.hash;
|
|
640
644
|
}
|
|
641
645
|
// Only track if the path has changed
|
|
@@ -738,9 +742,9 @@ class Saasco {
|
|
|
738
742
|
* @returns
|
|
739
743
|
*/
|
|
740
744
|
initiAutoPageTracking() {
|
|
745
|
+
var _a, _b;
|
|
741
746
|
// Disable auto page tracking if the config is set to false
|
|
742
|
-
|
|
743
|
-
if (this.config.autoPageTracking === false) return;
|
|
747
|
+
if (!((_a = this.config.autoPageTracking) === null || _a === void 0 ? void 0 : _a.enabled)) return;
|
|
744
748
|
// Prevent running on the server
|
|
745
749
|
if (!isBrowser) return console.warn('Saasco auto page tracking is only available in the browser');
|
|
746
750
|
// Prevent intitializing auto page tracking more than once
|
|
@@ -752,8 +756,10 @@ class Saasco {
|
|
|
752
756
|
this.log('Auto Page Tracking enabled');
|
|
753
757
|
// Track initial page load
|
|
754
758
|
this.page();
|
|
755
|
-
// Listen for hash changes
|
|
756
|
-
|
|
759
|
+
// Listen for hash changes if hash tracking is enabled
|
|
760
|
+
if ((_b = this.config.autoPageTracking) === null || _b === void 0 ? void 0 : _b.trackHash) {
|
|
761
|
+
window.addEventListener('hashchange', () => this.page());
|
|
762
|
+
}
|
|
757
763
|
// Listen to popstate for back and forward navigation
|
|
758
764
|
window.addEventListener('popstate', () => this.page());
|
|
759
765
|
// Wrap history push state to listen for URL changes
|
package/package.json
CHANGED
package/src/lib/analytics.d.ts
CHANGED
|
@@ -22,11 +22,13 @@ export declare class Saasco {
|
|
|
22
22
|
constructor(config: {
|
|
23
23
|
projectId: string;
|
|
24
24
|
proxy?: string;
|
|
25
|
-
autoPageTracking?:
|
|
25
|
+
autoPageTracking?: {
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
trackQueryParams?: boolean;
|
|
28
|
+
trackHash?: boolean;
|
|
29
|
+
};
|
|
26
30
|
enabled?: boolean;
|
|
27
31
|
debug?: boolean;
|
|
28
|
-
trackUrlParams?: boolean;
|
|
29
|
-
trackHashChanges?: boolean;
|
|
30
32
|
});
|
|
31
33
|
init(): void;
|
|
32
34
|
disableDebug(): void;
|