saasco-sdk 0.1.4 → 0.1.5
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 +7 -4
- package/index.cjs.js +20 -31
- package/index.esm.js +20 -31
- 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`
|
|
@@ -247,14 +246,18 @@ Our SDKs automatically collect certain properties on every event or user profile
|
|
|
247
246
|
| $latitude | Latitude | Latitude of the user's IP location. |
|
|
248
247
|
| $longitude | Longitude | Longitude of the user's IP location. |
|
|
249
248
|
| $timezone | Timezone | Timezone of the user parsed from the IP. |
|
|
249
|
+
| $locale | Locale | The preferred language of the user. |
|
|
250
|
+
| $pathname | Pathname | The path of the page on which the event was tracked. |
|
|
251
|
+
| $title | Page Title | The title of the page on which the event was tracked. |
|
|
252
|
+
| $userAgent | User Agent | The user agent string of the browser. |
|
|
250
253
|
| $screenHeight | Screen Height | The height of the device screen in pixels |
|
|
251
254
|
| $screenWidth | Screen Width | The width of the device screen in pixels |
|
|
252
255
|
| $screenDpi | Screen DPI | Pixel density of the device screen. |
|
|
253
256
|
| $currentUrl | Current URL | The URL of the page on which the event was tracked. |
|
|
254
257
|
| $os | Operating System | The most recent OS of the user. |
|
|
255
258
|
| $browser | Browser | The most recent browser of the user. |
|
|
256
|
-
| $browserVersion | Browser Version | The most recent
|
|
257
|
-
| $device | Device Type | The most recent
|
|
259
|
+
| $browserVersion | Browser Version | The most recent browser version of the user. |
|
|
260
|
+
| $device | Device Type | The most recent device type of the user. eg `Mobile`, `Tablet`, `Desktop` |
|
|
258
261
|
| $referrer | Last Touch Referrer | Referring URL when the user last interacted with your site. Defaults to "direct" |
|
|
259
262
|
| $referringDomain | Last Touch Referring Domain | Referring domain at the user's last interaction. Defaults to "direct" |
|
|
260
263
|
| $utmSource | UTM Source | The UTM source tag from the URL a customer clicked to arrive at your domain. |
|
package/index.cjs.js
CHANGED
|
@@ -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 userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
563
|
-
const title = isBrowser ? document.title : undefined;
|
|
564
|
-
const pathname = isBrowser ? window.location.pathname : undefined;
|
|
565
|
-
const href = isBrowser ? window.location.href : undefined;
|
|
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 $userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
566
|
+
const $title = isBrowser ? document.title : undefined;
|
|
567
|
+
const $pathname = isBrowser ? window.location.pathname : undefined;
|
|
568
|
+
const $href = isBrowser ? window.location.href : undefined;
|
|
566
569
|
const $screenHeight = isBrowser ? screen.height : undefined;
|
|
567
570
|
const $screenWidth = isBrowser ? screen.width : undefined;
|
|
568
571
|
const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
|
|
569
572
|
const $referrer = isBrowser ? document.referrer : undefined;
|
|
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');
|
|
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
|
@@ -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 userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
559
|
-
const title = isBrowser ? document.title : undefined;
|
|
560
|
-
const pathname = isBrowser ? window.location.pathname : undefined;
|
|
561
|
-
const href = isBrowser ? window.location.href : undefined;
|
|
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 $userAgent = isBrowser ? window.navigator.userAgent : undefined;
|
|
562
|
+
const $title = isBrowser ? document.title : undefined;
|
|
563
|
+
const $pathname = isBrowser ? window.location.pathname : undefined;
|
|
564
|
+
const $href = isBrowser ? window.location.href : undefined;
|
|
562
565
|
const $screenHeight = isBrowser ? screen.height : undefined;
|
|
563
566
|
const $screenWidth = isBrowser ? screen.width : undefined;
|
|
564
567
|
const $screenDPI = isBrowser ? window.devicePixelRatio : undefined;
|
|
565
568
|
const $referrer = isBrowser ? document.referrer : undefined;
|
|
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');
|
|
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
|
};
|