saasco-sdk 0.1.37 → 0.1.39
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 +12 -33
- package/index.esm.js +13 -32
- package/package.json +1 -1
- package/src/lib/integrations/facebook-pixel.d.ts +2 -2
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.39";
|
|
11
11
|
|
|
12
12
|
const timezones = {
|
|
13
13
|
'Asia/Barnaul': 'RU',
|
|
@@ -604,6 +604,13 @@ 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
|
+
// 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
|
+
}
|
|
607
614
|
// Initialize pixel
|
|
608
615
|
window.fbq('init', config.pixelId);
|
|
609
616
|
// If script loads synchronously, mark as ready
|
|
@@ -619,17 +626,17 @@ function createFacebookPixelIntegration(config) {
|
|
|
619
626
|
track: (eventName, properties, context) => {
|
|
620
627
|
if (!isPixelReady || !window.fbq) return;
|
|
621
628
|
const fbEventName = getFacebookEventName(eventName, config.eventMapping);
|
|
622
|
-
// Standard Facebook events that support parameters
|
|
623
629
|
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
630
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
631
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
624
632
|
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
625
|
-
// Extract standard Facebook parameters
|
|
626
633
|
const fbParams = {};
|
|
627
634
|
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
628
635
|
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
629
636
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
630
|
-
window.fbq(
|
|
637
|
+
window.fbq(trackType, fbEventName, fbParams);
|
|
631
638
|
} else {
|
|
632
|
-
window.fbq(
|
|
639
|
+
window.fbq(trackType, fbEventName);
|
|
633
640
|
}
|
|
634
641
|
},
|
|
635
642
|
identify: (userId, properties, context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -666,32 +673,6 @@ function getFacebookEventName(eventName, eventMapping) {
|
|
|
666
673
|
if (!eventMapping) return eventName;
|
|
667
674
|
return eventMapping[eventName] || eventName;
|
|
668
675
|
}
|
|
669
|
-
// Legacy functions for backward compatibility (deprecated)
|
|
670
|
-
function initializeFacebookPixel(pixelId) {
|
|
671
|
-
var _a;
|
|
672
|
-
console.warn('initializeFacebookPixel is deprecated. Use createFacebookPixelIntegration instead.');
|
|
673
|
-
const integration = createFacebookPixelIntegration({
|
|
674
|
-
pixelId
|
|
675
|
-
});
|
|
676
|
-
(_a = integration.init) === null || _a === void 0 ? void 0 : _a.call(integration);
|
|
677
|
-
}
|
|
678
|
-
function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
679
|
-
console.warn('trackFacebookEvent is deprecated. Use IntegrationManager instead.');
|
|
680
|
-
if (isServer$1 || !window.fbq) return;
|
|
681
|
-
const fbEventName = getFacebookEventName(eventName, eventMapping);
|
|
682
|
-
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
683
|
-
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
684
|
-
const fbParams = {};
|
|
685
|
-
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
686
|
-
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
687
|
-
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
688
|
-
window.fbq('track', fbEventName, fbParams);
|
|
689
|
-
} else {
|
|
690
|
-
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
691
|
-
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
692
|
-
window.fbq(trackType, fbEventName);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
676
|
function coerceMetaConversionsAmValues(properties) {
|
|
696
677
|
const coerce = [{
|
|
697
678
|
key: 'em',
|
|
@@ -1626,7 +1607,5 @@ exports.Saasco = Saasco;
|
|
|
1626
1607
|
exports.browserContextSchema = browserContextSchema;
|
|
1627
1608
|
exports.createFacebookPixelIntegration = createFacebookPixelIntegration;
|
|
1628
1609
|
exports.getBrowserContext = getBrowserContext;
|
|
1629
|
-
exports.initializeFacebookPixel = initializeFacebookPixel;
|
|
1630
1610
|
exports.standardFacebookEvents = standardFacebookEvents;
|
|
1631
1611
|
exports.timezones = timezones;
|
|
1632
|
-
exports.trackFacebookEvent = trackFacebookEvent;
|
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.39";
|
|
7
7
|
|
|
8
8
|
const timezones = {
|
|
9
9
|
'Asia/Barnaul': 'RU',
|
|
@@ -600,6 +600,13 @@ 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
|
+
// 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
|
+
}
|
|
603
610
|
// Initialize pixel
|
|
604
611
|
window.fbq('init', config.pixelId);
|
|
605
612
|
// If script loads synchronously, mark as ready
|
|
@@ -615,17 +622,17 @@ function createFacebookPixelIntegration(config) {
|
|
|
615
622
|
track: (eventName, properties, context) => {
|
|
616
623
|
if (!isPixelReady || !window.fbq) return;
|
|
617
624
|
const fbEventName = getFacebookEventName(eventName, config.eventMapping);
|
|
618
|
-
// Standard Facebook events that support parameters
|
|
619
625
|
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
626
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
627
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
620
628
|
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
621
|
-
// Extract standard Facebook parameters
|
|
622
629
|
const fbParams = {};
|
|
623
630
|
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
624
631
|
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
625
632
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
626
|
-
window.fbq(
|
|
633
|
+
window.fbq(trackType, fbEventName, fbParams);
|
|
627
634
|
} else {
|
|
628
|
-
window.fbq(
|
|
635
|
+
window.fbq(trackType, fbEventName);
|
|
629
636
|
}
|
|
630
637
|
},
|
|
631
638
|
identify: (userId, properties, context) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -662,32 +669,6 @@ function getFacebookEventName(eventName, eventMapping) {
|
|
|
662
669
|
if (!eventMapping) return eventName;
|
|
663
670
|
return eventMapping[eventName] || eventName;
|
|
664
671
|
}
|
|
665
|
-
// Legacy functions for backward compatibility (deprecated)
|
|
666
|
-
function initializeFacebookPixel(pixelId) {
|
|
667
|
-
var _a;
|
|
668
|
-
console.warn('initializeFacebookPixel is deprecated. Use createFacebookPixelIntegration instead.');
|
|
669
|
-
const integration = createFacebookPixelIntegration({
|
|
670
|
-
pixelId
|
|
671
|
-
});
|
|
672
|
-
(_a = integration.init) === null || _a === void 0 ? void 0 : _a.call(integration);
|
|
673
|
-
}
|
|
674
|
-
function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
675
|
-
console.warn('trackFacebookEvent is deprecated. Use IntegrationManager instead.');
|
|
676
|
-
if (isServer$1 || !window.fbq) return;
|
|
677
|
-
const fbEventName = getFacebookEventName(eventName, eventMapping);
|
|
678
|
-
const eventsWithParams = ['Purchase', 'StartTrial', 'Subscribe'];
|
|
679
|
-
if (eventsWithParams.includes(fbEventName) && properties) {
|
|
680
|
-
const fbParams = {};
|
|
681
|
-
if (properties['value'] !== undefined) fbParams['value'] = properties['value'];
|
|
682
|
-
if (properties['currency'] !== undefined) fbParams['currency'] = properties['currency'];
|
|
683
|
-
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
684
|
-
window.fbq('track', fbEventName, fbParams);
|
|
685
|
-
} else {
|
|
686
|
-
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
687
|
-
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
688
|
-
window.fbq(trackType, fbEventName);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
672
|
function coerceMetaConversionsAmValues(properties) {
|
|
692
673
|
const coerce = [{
|
|
693
674
|
key: 'em',
|
|
@@ -1616,4 +1597,4 @@ const browserContextSchema = z.object({
|
|
|
1616
1597
|
$utmAdId: z.string().nullable()
|
|
1617
1598
|
});
|
|
1618
1599
|
|
|
1619
|
-
export { IntegrationManager, Logger, Saasco, browserContextSchema, createFacebookPixelIntegration, getBrowserContext,
|
|
1600
|
+
export { IntegrationManager, Logger, Saasco, browserContextSchema, createFacebookPixelIntegration, getBrowserContext, standardFacebookEvents, timezones };
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ declare global {
|
|
|
11
11
|
loaded?: boolean;
|
|
12
12
|
version?: string;
|
|
13
13
|
disablePushState?: boolean;
|
|
14
|
+
allowDuplicatePageViews?: boolean;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
export type FacebookEventMapping = {
|
|
@@ -23,6 +24,7 @@ export type FacebookPixelIntegrationConfig = IntegrationConfigBase & {
|
|
|
23
24
|
export type FacebookPixelConfig = {
|
|
24
25
|
pixelId: string;
|
|
25
26
|
eventMapping?: FacebookEventMapping;
|
|
27
|
+
automaticConfiguration?: boolean;
|
|
26
28
|
};
|
|
27
29
|
export declare const standardFacebookEvents: readonly ["AddPaymentInfo", "AddToCart", "AddToWishlist", "CompleteRegistration", "Contact", "CustomizeProduct", "Donate", "FindLocation", "InitiateCheckout", "Lead", "Purchase", "Schedule", "Search", "StartTrial", "SubmitApplication", "Subscribe", "ViewContent", "PageView"];
|
|
28
30
|
export type StandardFacebookEvent = (typeof standardFacebookEvents)[number];
|
|
@@ -30,5 +32,3 @@ export type StandardFacebookEvent = (typeof standardFacebookEvents)[number];
|
|
|
30
32
|
* Create a Facebook Pixel integration instance
|
|
31
33
|
*/
|
|
32
34
|
export declare function createFacebookPixelIntegration(config: FacebookPixelConfig): Integration;
|
|
33
|
-
export declare function initializeFacebookPixel(pixelId: string): void;
|
|
34
|
-
export declare function trackFacebookEvent(eventName: string, properties?: Record<string, any>, eventMapping?: FacebookEventMapping): void;
|