saasco-sdk 0.1.36 → 0.1.38
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/index.cjs.js +15 -11
- package/index.esm.js +15 -11
- package/package.json +1 -1
- package/src/lib/integrations/facebook-pixel.d.ts +12 -3
package/index.cjs.js
CHANGED
|
@@ -7,7 +7,7 @@ var psl = require('psl');
|
|
|
7
7
|
var uuid$1 = require('@lukeed/uuid');
|
|
8
8
|
var zod = require('zod');
|
|
9
9
|
|
|
10
|
-
var version = "0.1.
|
|
10
|
+
var version = "0.1.38";
|
|
11
11
|
|
|
12
12
|
const timezones = {
|
|
13
13
|
'Asia/Barnaul': 'RU',
|
|
@@ -556,7 +556,7 @@ function getBrowserContext() {
|
|
|
556
556
|
|
|
557
557
|
const isBrowser$1 = typeof window !== 'undefined';
|
|
558
558
|
const isServer$1 = !isBrowser$1;
|
|
559
|
-
const standardFacebookEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Donate', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent'];
|
|
559
|
+
const standardFacebookEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Donate', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent', 'PageView'];
|
|
560
560
|
/**
|
|
561
561
|
* Create a Facebook Pixel integration instance
|
|
562
562
|
*/
|
|
@@ -604,7 +604,14 @@ function createFacebookPixelIntegration(config) {
|
|
|
604
604
|
s = b.getElementsByTagName(e)[0];
|
|
605
605
|
s.parentNode.insertBefore(t, s);
|
|
606
606
|
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
607
|
-
//
|
|
607
|
+
// Prevent automatic PageView tracking
|
|
608
|
+
window.fbq.disablePushState = true;
|
|
609
|
+
// Allow duplicate PageView events
|
|
610
|
+
window.fbq.allowDuplicatePageViews = true;
|
|
611
|
+
if (config.automaticConfiguration === false) {
|
|
612
|
+
window.fbq('set', 'autoConfig', false, config.pixelId);
|
|
613
|
+
}
|
|
614
|
+
// Initialize pixel
|
|
608
615
|
window.fbq('init', config.pixelId);
|
|
609
616
|
// If script loads synchronously, mark as ready
|
|
610
617
|
if (window.fbq && typeof window.fbq === 'function') {
|
|
@@ -661,11 +668,8 @@ function createFacebookPixelIntegration(config) {
|
|
|
661
668
|
};
|
|
662
669
|
}
|
|
663
670
|
function getFacebookEventName(eventName, eventMapping) {
|
|
664
|
-
// Convert default saasco
|
|
665
|
-
if (eventName === 'Page View')
|
|
666
|
-
const mappedEvent = 'ViewContent';
|
|
667
|
-
return mappedEvent;
|
|
668
|
-
}
|
|
671
|
+
// Convert default saasco Page View event by default
|
|
672
|
+
if (eventName === 'Page View') return 'PageView';
|
|
669
673
|
if (!eventMapping) return eventName;
|
|
670
674
|
return eventMapping[eventName] || eventName;
|
|
671
675
|
}
|
|
@@ -683,15 +687,15 @@ function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
|
683
687
|
if (isServer$1 || !window.fbq) return;
|
|
684
688
|
const fbEventName = getFacebookEventName(eventName, eventMapping);
|
|
685
689
|
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
690
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
691
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
686
692
|
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
687
693
|
const fbParams = {};
|
|
688
694
|
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
689
695
|
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
690
696
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
691
|
-
window.fbq(
|
|
697
|
+
window.fbq(trackType, fbEventName, fbParams);
|
|
692
698
|
} else {
|
|
693
|
-
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
694
|
-
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
695
699
|
window.fbq(trackType, fbEventName);
|
|
696
700
|
}
|
|
697
701
|
}
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isValid, parse } from 'psl';
|
|
|
3
3
|
import { v4 } from '@lukeed/uuid';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
|
-
var version = "0.1.
|
|
6
|
+
var version = "0.1.38";
|
|
7
7
|
|
|
8
8
|
const timezones = {
|
|
9
9
|
'Asia/Barnaul': 'RU',
|
|
@@ -552,7 +552,7 @@ function getBrowserContext() {
|
|
|
552
552
|
|
|
553
553
|
const isBrowser$1 = typeof window !== 'undefined';
|
|
554
554
|
const isServer$1 = !isBrowser$1;
|
|
555
|
-
const standardFacebookEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Donate', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent'];
|
|
555
|
+
const standardFacebookEvents = ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'CompleteRegistration', 'Contact', 'CustomizeProduct', 'Donate', 'FindLocation', 'InitiateCheckout', 'Lead', 'Purchase', 'Schedule', 'Search', 'StartTrial', 'SubmitApplication', 'Subscribe', 'ViewContent', 'PageView'];
|
|
556
556
|
/**
|
|
557
557
|
* Create a Facebook Pixel integration instance
|
|
558
558
|
*/
|
|
@@ -600,7 +600,14 @@ function createFacebookPixelIntegration(config) {
|
|
|
600
600
|
s = b.getElementsByTagName(e)[0];
|
|
601
601
|
s.parentNode.insertBefore(t, s);
|
|
602
602
|
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
603
|
-
//
|
|
603
|
+
// Prevent automatic PageView tracking
|
|
604
|
+
window.fbq.disablePushState = true;
|
|
605
|
+
// Allow duplicate PageView events
|
|
606
|
+
window.fbq.allowDuplicatePageViews = true;
|
|
607
|
+
if (config.automaticConfiguration === false) {
|
|
608
|
+
window.fbq('set', 'autoConfig', false, config.pixelId);
|
|
609
|
+
}
|
|
610
|
+
// Initialize pixel
|
|
604
611
|
window.fbq('init', config.pixelId);
|
|
605
612
|
// If script loads synchronously, mark as ready
|
|
606
613
|
if (window.fbq && typeof window.fbq === 'function') {
|
|
@@ -657,11 +664,8 @@ function createFacebookPixelIntegration(config) {
|
|
|
657
664
|
};
|
|
658
665
|
}
|
|
659
666
|
function getFacebookEventName(eventName, eventMapping) {
|
|
660
|
-
// Convert default saasco
|
|
661
|
-
if (eventName === 'Page View')
|
|
662
|
-
const mappedEvent = 'ViewContent';
|
|
663
|
-
return mappedEvent;
|
|
664
|
-
}
|
|
667
|
+
// Convert default saasco Page View event by default
|
|
668
|
+
if (eventName === 'Page View') return 'PageView';
|
|
665
669
|
if (!eventMapping) return eventName;
|
|
666
670
|
return eventMapping[eventName] || eventName;
|
|
667
671
|
}
|
|
@@ -679,15 +683,15 @@ function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
|
679
683
|
if (isServer$1 || !window.fbq) return;
|
|
680
684
|
const fbEventName = getFacebookEventName(eventName, eventMapping);
|
|
681
685
|
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
686
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
687
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
682
688
|
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
683
689
|
const fbParams = {};
|
|
684
690
|
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
685
691
|
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
686
692
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
687
|
-
window.fbq(
|
|
693
|
+
window.fbq(trackType, fbEventName, fbParams);
|
|
688
694
|
} else {
|
|
689
|
-
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
690
|
-
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
691
695
|
window.fbq(trackType, fbEventName);
|
|
692
696
|
}
|
|
693
697
|
}
|
package/package.json
CHANGED
|
@@ -2,8 +2,16 @@ import { IntegrationConfigBase } from '../analytics';
|
|
|
2
2
|
import { Integration } from './integration-manager';
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
|
-
fbq?:
|
|
6
|
-
_fbq?:
|
|
5
|
+
fbq?: Fbq;
|
|
6
|
+
_fbq?: Fbq;
|
|
7
|
+
}
|
|
8
|
+
interface Fbq {
|
|
9
|
+
(...args: any[]): void;
|
|
10
|
+
queue?: any[];
|
|
11
|
+
loaded?: boolean;
|
|
12
|
+
version?: string;
|
|
13
|
+
disablePushState?: boolean;
|
|
14
|
+
allowDuplicatePageViews?: boolean;
|
|
7
15
|
}
|
|
8
16
|
}
|
|
9
17
|
export type FacebookEventMapping = {
|
|
@@ -16,8 +24,9 @@ export type FacebookPixelIntegrationConfig = IntegrationConfigBase & {
|
|
|
16
24
|
export type FacebookPixelConfig = {
|
|
17
25
|
pixelId: string;
|
|
18
26
|
eventMapping?: FacebookEventMapping;
|
|
27
|
+
automaticConfiguration?: boolean;
|
|
19
28
|
};
|
|
20
|
-
export declare const standardFacebookEvents: readonly ["AddPaymentInfo", "AddToCart", "AddToWishlist", "CompleteRegistration", "Contact", "CustomizeProduct", "Donate", "FindLocation", "InitiateCheckout", "Lead", "Purchase", "Schedule", "Search", "StartTrial", "SubmitApplication", "Subscribe", "ViewContent"];
|
|
29
|
+
export declare const standardFacebookEvents: readonly ["AddPaymentInfo", "AddToCart", "AddToWishlist", "CompleteRegistration", "Contact", "CustomizeProduct", "Donate", "FindLocation", "InitiateCheckout", "Lead", "Purchase", "Schedule", "Search", "StartTrial", "SubmitApplication", "Subscribe", "ViewContent", "PageView"];
|
|
21
30
|
export type StandardFacebookEvent = (typeof standardFacebookEvents)[number];
|
|
22
31
|
/**
|
|
23
32
|
* Create a Facebook Pixel integration instance
|