saasco-sdk 0.1.4 → 0.1.6
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 +8 -4
- package/index.cjs.js +23 -34
- package/index.esm.js +23 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
- [Privacy](#privacy)
|
|
6
6
|
- [Getting Started](#initiate-the-lib)
|
|
7
|
-
- [Naming Conflict](#naming-conflict)
|
|
8
7
|
- [Automatic Page View Tracking](#automatic-page-view-tracking)
|
|
9
8
|
- [Tracking Events](#tracking-events)
|
|
10
9
|
- [Identifying Users](#identifying-users)
|
|
@@ -17,7 +16,7 @@
|
|
|
17
16
|
|
|
18
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.
|
|
19
18
|
|
|
20
|
-
## Getting Started
|
|
19
|
+
## Getting Started
|
|
21
20
|
|
|
22
21
|
Install by running:
|
|
23
22
|
`npm install saasco-sdk`
|
|
@@ -202,6 +201,7 @@ Any property that starts with `$` is a property that has been generated by the S
|
|
|
202
201
|
| $latitude | Latitude | Latitude of the user's IP location. |
|
|
203
202
|
| $longitude | Longitude | Longitude of the user's IP location. |
|
|
204
203
|
| $timezone | Timezone | Timezone of the user parsed from the IP. |
|
|
204
|
+
| $locale | Locale | The most recent preferred language of the user. |
|
|
205
205
|
| $screenHeight | Screen Height | The most recent height of the device screen in pixels |
|
|
206
206
|
| $screenWidth | Screen Width | The most recent width of the device screen in pixels |
|
|
207
207
|
| $screenDpi | Screen DPI | The most recent Pixel density of the device screen. |
|
|
@@ -247,14 +247,18 @@ Our SDKs automatically collect certain properties on every event or user profile
|
|
|
247
247
|
| $latitude | Latitude | Latitude of the user's IP location. |
|
|
248
248
|
| $longitude | Longitude | Longitude of the user's IP location. |
|
|
249
249
|
| $timezone | Timezone | Timezone of the user parsed from the IP. |
|
|
250
|
+
| $locale | Locale | The preferred language of the user. |
|
|
251
|
+
| $pathname | Pathname | The path of the page on which the event was tracked. |
|
|
252
|
+
| $title | Page Title | The title of the page on which the event was tracked. |
|
|
253
|
+
| $userAgent | User Agent | The user agent string of the browser. |
|
|
250
254
|
| $screenHeight | Screen Height | The height of the device screen in pixels |
|
|
251
255
|
| $screenWidth | Screen Width | The width of the device screen in pixels |
|
|
252
256
|
| $screenDpi | Screen DPI | Pixel density of the device screen. |
|
|
253
257
|
| $currentUrl | Current URL | The URL of the page on which the event was tracked. |
|
|
254
258
|
| $os | Operating System | The most recent OS of the user. |
|
|
255
259
|
| $browser | Browser | The most recent browser of the user. |
|
|
256
|
-
| $browserVersion | Browser Version | The most recent
|
|
257
|
-
| $device | Device Type | The most recent
|
|
260
|
+
| $browserVersion | Browser Version | The most recent browser version of the user. |
|
|
261
|
+
| $device | Device Type | The most recent device type of the user. eg `Mobile`, `Tablet`, `Desktop` |
|
|
258
262
|
| $referrer | Last Touch Referrer | Referring URL when the user last interacted with your site. Defaults to "direct" |
|
|
259
263
|
| $referringDomain | Last Touch Referring Domain | Referring domain at the user's last interaction. Defaults to "direct" |
|
|
260
264
|
| $utmSource | UTM Source | The UTM source tag from the URL a customer clicked to arrive at your domain. |
|
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) {
|
|
@@ -546,7 +546,10 @@ class Saasco {
|
|
|
546
546
|
var _a;
|
|
547
547
|
// Prevent duplicate Page View tracking
|
|
548
548
|
if (name === 'Page View') {
|
|
549
|
-
if (!isBrowser)
|
|
549
|
+
if (!isBrowser) {
|
|
550
|
+
console.warn('Saasco page tracking is only available in the browser');
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
550
553
|
const pageViewHref = window.location.href;
|
|
551
554
|
if (pageViewHref === this.lastPageViewHref) return;
|
|
552
555
|
this.lastPageViewHref = pageViewHref;
|
|
@@ -554,52 +557,38 @@ class Saasco {
|
|
|
554
557
|
setSessionId();
|
|
555
558
|
setAnonmousId();
|
|
556
559
|
const customNavigator = isBrowser ? navigator : undefined;
|
|
557
|
-
const locale = isBrowser ? (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages) && (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages.length) ? customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages[0] : (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.userLanguage) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.language) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.browserLanguage) || 'en' : undefined;
|
|
560
|
+
const $locale = isBrowser ? (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages) && (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages.length) ? customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages[0] : (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.userLanguage) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.language) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.browserLanguage) || 'en' : undefined;
|
|
558
561
|
// https://caniuse.com/?search=Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
559
562
|
// Only has 96.63% global support, so we need to check for undefined
|
|
560
563
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
561
|
-
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;
|
|
562
|
-
const
|
|
563
|
-
const
|
|
564
|
-
const
|
|
565
|
-
const
|
|
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 $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;
|
|
566
569
|
const $screenHeight = isBrowser ? screen.height : undefined;
|
|
567
570
|
const $screenWidth = isBrowser ? screen.width : undefined;
|
|
568
|
-
const $
|
|
569
|
-
const $
|
|
570
|
-
const $utm_source = this.getSearchParam('utm_source');
|
|
571
|
-
const $utm_medium = this.getSearchParam('utm_medium');
|
|
572
|
-
const $utm_campaign = this.getSearchParam('utm_campaign');
|
|
573
|
-
const $utm_content = this.getSearchParam('utm_content');
|
|
574
|
-
const $utm_term = this.getSearchParam('utm_term');
|
|
575
|
-
const $gclid = this.getSearchParam('gclid');
|
|
576
|
-
const $fbclid = this.getSearchParam('fbclid');
|
|
571
|
+
const $title = isBrowser ? document.title : undefined;
|
|
572
|
+
const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
577
573
|
const data = {
|
|
578
574
|
id: uuid.v4(),
|
|
579
575
|
timestamp: new Date().toISOString(),
|
|
580
576
|
action: name,
|
|
581
|
-
version: '
|
|
577
|
+
version: '2',
|
|
582
578
|
sessionId: getSessionId(),
|
|
583
579
|
anonymousId: getAnonymousId(),
|
|
584
580
|
projectId: this.config.projectId,
|
|
585
581
|
payload: JSON.stringify({
|
|
586
|
-
|
|
587
|
-
locale,
|
|
588
|
-
location,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
582
|
+
$href,
|
|
583
|
+
$locale,
|
|
584
|
+
$location,
|
|
585
|
+
$pathname,
|
|
586
|
+
$referrer,
|
|
587
|
+
$screenDPI,
|
|
592
588
|
$screenHeight,
|
|
593
589
|
$screenWidth,
|
|
594
|
-
$
|
|
595
|
-
$
|
|
596
|
-
$utm_source,
|
|
597
|
-
$utm_medium,
|
|
598
|
-
$utm_campaign,
|
|
599
|
-
$utm_content,
|
|
600
|
-
$utm_term,
|
|
601
|
-
$gclid,
|
|
602
|
-
$fbclid,
|
|
590
|
+
$title,
|
|
591
|
+
$userAgent,
|
|
603
592
|
properties: properties || {}
|
|
604
593
|
})
|
|
605
594
|
};
|
|
@@ -640,7 +629,7 @@ class Saasco {
|
|
|
640
629
|
projectId: this.config.projectId,
|
|
641
630
|
distinctId,
|
|
642
631
|
anonymousId,
|
|
643
|
-
version: '
|
|
632
|
+
version: '2',
|
|
644
633
|
payload: properties || {},
|
|
645
634
|
options: options || {}
|
|
646
635
|
};
|
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) {
|
|
@@ -542,7 +542,10 @@ class Saasco {
|
|
|
542
542
|
var _a;
|
|
543
543
|
// Prevent duplicate Page View tracking
|
|
544
544
|
if (name === 'Page View') {
|
|
545
|
-
if (!isBrowser)
|
|
545
|
+
if (!isBrowser) {
|
|
546
|
+
console.warn('Saasco page tracking is only available in the browser');
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
546
549
|
const pageViewHref = window.location.href;
|
|
547
550
|
if (pageViewHref === this.lastPageViewHref) return;
|
|
548
551
|
this.lastPageViewHref = pageViewHref;
|
|
@@ -550,52 +553,38 @@ class Saasco {
|
|
|
550
553
|
setSessionId();
|
|
551
554
|
setAnonmousId();
|
|
552
555
|
const customNavigator = isBrowser ? navigator : undefined;
|
|
553
|
-
const locale = isBrowser ? (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages) && (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages.length) ? customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages[0] : (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.userLanguage) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.language) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.browserLanguage) || 'en' : undefined;
|
|
556
|
+
const $locale = isBrowser ? (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages) && (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages.length) ? customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.languages[0] : (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.userLanguage) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.language) || (customNavigator === null || customNavigator === void 0 ? void 0 : customNavigator.browserLanguage) || 'en' : undefined;
|
|
554
557
|
// https://caniuse.com/?search=Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
555
558
|
// Only has 96.63% global support, so we need to check for undefined
|
|
556
559
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
557
|
-
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;
|
|
558
|
-
const
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
const
|
|
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 $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;
|
|
562
565
|
const $screenHeight = isBrowser ? screen.height : undefined;
|
|
563
566
|
const $screenWidth = isBrowser ? screen.width : undefined;
|
|
564
|
-
const $
|
|
565
|
-
const $
|
|
566
|
-
const $utm_source = this.getSearchParam('utm_source');
|
|
567
|
-
const $utm_medium = this.getSearchParam('utm_medium');
|
|
568
|
-
const $utm_campaign = this.getSearchParam('utm_campaign');
|
|
569
|
-
const $utm_content = this.getSearchParam('utm_content');
|
|
570
|
-
const $utm_term = this.getSearchParam('utm_term');
|
|
571
|
-
const $gclid = this.getSearchParam('gclid');
|
|
572
|
-
const $fbclid = this.getSearchParam('fbclid');
|
|
567
|
+
const $title = isBrowser ? document.title : undefined;
|
|
568
|
+
const $userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
573
569
|
const data = {
|
|
574
570
|
id: v4(),
|
|
575
571
|
timestamp: new Date().toISOString(),
|
|
576
572
|
action: name,
|
|
577
|
-
version: '
|
|
573
|
+
version: '2',
|
|
578
574
|
sessionId: getSessionId(),
|
|
579
575
|
anonymousId: getAnonymousId(),
|
|
580
576
|
projectId: this.config.projectId,
|
|
581
577
|
payload: JSON.stringify({
|
|
582
|
-
|
|
583
|
-
locale,
|
|
584
|
-
location,
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
578
|
+
$href,
|
|
579
|
+
$locale,
|
|
580
|
+
$location,
|
|
581
|
+
$pathname,
|
|
582
|
+
$referrer,
|
|
583
|
+
$screenDPI,
|
|
588
584
|
$screenHeight,
|
|
589
585
|
$screenWidth,
|
|
590
|
-
$
|
|
591
|
-
$
|
|
592
|
-
$utm_source,
|
|
593
|
-
$utm_medium,
|
|
594
|
-
$utm_campaign,
|
|
595
|
-
$utm_content,
|
|
596
|
-
$utm_term,
|
|
597
|
-
$gclid,
|
|
598
|
-
$fbclid,
|
|
586
|
+
$title,
|
|
587
|
+
$userAgent,
|
|
599
588
|
properties: properties || {}
|
|
600
589
|
})
|
|
601
590
|
};
|
|
@@ -636,7 +625,7 @@ class Saasco {
|
|
|
636
625
|
projectId: this.config.projectId,
|
|
637
626
|
distinctId,
|
|
638
627
|
anonymousId,
|
|
639
|
-
version: '
|
|
628
|
+
version: '2',
|
|
640
629
|
payload: properties || {},
|
|
641
630
|
options: options || {}
|
|
642
631
|
};
|