saasco-sdk 0.1.33 → 0.1.35
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 +18 -13
- package/index.esm.js +18 -14
- package/package.json +1 -1
- package/src/lib/integrations/facebook-pixel.d.ts +2 -1
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.35";
|
|
11
11
|
|
|
12
12
|
const timezones = {
|
|
13
13
|
'Asia/Barnaul': 'RU',
|
|
@@ -556,6 +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
560
|
/**
|
|
560
561
|
* Create a Facebook Pixel integration instance
|
|
561
562
|
*/
|
|
@@ -566,7 +567,9 @@ function createFacebookPixelIntegration(config) {
|
|
|
566
567
|
environments: ['client'],
|
|
567
568
|
init: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
568
569
|
if (isServer$1) {
|
|
569
|
-
|
|
570
|
+
// On server, Facebook Pixel is a no-op but doesn't throw
|
|
571
|
+
// This allows the integration to be registered but remain inactive
|
|
572
|
+
return;
|
|
570
573
|
}
|
|
571
574
|
// Check if Facebook Pixel is already loaded
|
|
572
575
|
if (window.fbq || window._fbq) {
|
|
@@ -659,7 +662,10 @@ function createFacebookPixelIntegration(config) {
|
|
|
659
662
|
}
|
|
660
663
|
function getFacebookEventName(eventName, eventMapping) {
|
|
661
664
|
// Convert default saasco page view event by default
|
|
662
|
-
if (eventName === 'Page View')
|
|
665
|
+
if (eventName === 'Page View') {
|
|
666
|
+
const mappedEvent = 'ViewContent';
|
|
667
|
+
return mappedEvent;
|
|
668
|
+
}
|
|
663
669
|
if (!eventMapping) return eventName;
|
|
664
670
|
return eventMapping[eventName] || eventName;
|
|
665
671
|
}
|
|
@@ -684,7 +690,9 @@ function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
|
684
690
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
685
691
|
window.fbq('track', fbEventName, fbParams);
|
|
686
692
|
} else {
|
|
687
|
-
|
|
693
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
694
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
695
|
+
window.fbq(trackType, fbEventName);
|
|
688
696
|
}
|
|
689
697
|
}
|
|
690
698
|
function coerceMetaConversionsAmValues(properties) {
|
|
@@ -945,10 +953,9 @@ class IntegrationManager {
|
|
|
945
953
|
if (integration.init) {
|
|
946
954
|
try {
|
|
947
955
|
state.status = 'loading';
|
|
948
|
-
this.logger.log(`init ${integration.name}`);
|
|
949
956
|
yield integration.init();
|
|
950
957
|
state.status = 'ready';
|
|
951
|
-
this.logger.log(
|
|
958
|
+
this.logger.log(`${integration.name} integration ready`);
|
|
952
959
|
this.flush();
|
|
953
960
|
} catch (e) {
|
|
954
961
|
state.status = 'error';
|
|
@@ -1055,11 +1062,9 @@ class IntegrationManager {
|
|
|
1055
1062
|
if (this.config.flushInterval <= 0) return;
|
|
1056
1063
|
this.flushTimer = setInterval(() => {
|
|
1057
1064
|
if (this.globalQueue.length > 0) {
|
|
1058
|
-
this.logger.log('periodic flush triggered');
|
|
1059
1065
|
this.flush();
|
|
1060
1066
|
}
|
|
1061
1067
|
}, this.config.flushInterval);
|
|
1062
|
-
this.logger.log(`periodic flushing enabled: ${this.config.flushInterval}ms`);
|
|
1063
1068
|
}
|
|
1064
1069
|
/**
|
|
1065
1070
|
* Setup page unload handler for client environment
|
|
@@ -1075,7 +1080,6 @@ class IntegrationManager {
|
|
|
1075
1080
|
// Use both beforeunload and pagehide for better coverage
|
|
1076
1081
|
window.addEventListener('beforeunload', this.unloadHandler);
|
|
1077
1082
|
window.addEventListener('pagehide', this.unloadHandler);
|
|
1078
|
-
this.logger.log('page unload handlers registered');
|
|
1079
1083
|
}
|
|
1080
1084
|
/** Debug helpers */
|
|
1081
1085
|
getStats() {
|
|
@@ -1317,6 +1321,10 @@ class Saasco {
|
|
|
1317
1321
|
});
|
|
1318
1322
|
// Set initial context
|
|
1319
1323
|
this.integrationManager.setContext({});
|
|
1324
|
+
// Initialize integrations immediately (works on both client and server)
|
|
1325
|
+
this.initIntegrations().catch(error => {
|
|
1326
|
+
this.logger.log('Error initializing integrations:', error);
|
|
1327
|
+
});
|
|
1320
1328
|
}
|
|
1321
1329
|
init() {
|
|
1322
1330
|
if (this.isInitialized) {
|
|
@@ -1332,10 +1340,6 @@ class Saasco {
|
|
|
1332
1340
|
this.logger.log('Saasco initialized', this.config);
|
|
1333
1341
|
if (this.config.debug) this.logger.log('Debug mode active. This will log all events to the console.');
|
|
1334
1342
|
if (!this.config.enabled) this.logger.log('Analytics is disabled. No requests will be sent to the server.');
|
|
1335
|
-
// Initialize integrations asynchronously
|
|
1336
|
-
this.initIntegrations().catch(error => {
|
|
1337
|
-
this.logger.log('Error initializing integrations:', error);
|
|
1338
|
-
});
|
|
1339
1343
|
this.initAutoPageTracking();
|
|
1340
1344
|
this.isInitialized = true;
|
|
1341
1345
|
}
|
|
@@ -1626,5 +1630,6 @@ exports.browserContextSchema = browserContextSchema;
|
|
|
1626
1630
|
exports.createFacebookPixelIntegration = createFacebookPixelIntegration;
|
|
1627
1631
|
exports.getBrowserContext = getBrowserContext;
|
|
1628
1632
|
exports.initializeFacebookPixel = initializeFacebookPixel;
|
|
1633
|
+
exports.standardFacebookEvents = standardFacebookEvents;
|
|
1629
1634
|
exports.timezones = timezones;
|
|
1630
1635
|
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.35";
|
|
7
7
|
|
|
8
8
|
const timezones = {
|
|
9
9
|
'Asia/Barnaul': 'RU',
|
|
@@ -552,6 +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
556
|
/**
|
|
556
557
|
* Create a Facebook Pixel integration instance
|
|
557
558
|
*/
|
|
@@ -562,7 +563,9 @@ function createFacebookPixelIntegration(config) {
|
|
|
562
563
|
environments: ['client'],
|
|
563
564
|
init: () => __awaiter(this, void 0, void 0, function* () {
|
|
564
565
|
if (isServer$1) {
|
|
565
|
-
|
|
566
|
+
// On server, Facebook Pixel is a no-op but doesn't throw
|
|
567
|
+
// This allows the integration to be registered but remain inactive
|
|
568
|
+
return;
|
|
566
569
|
}
|
|
567
570
|
// Check if Facebook Pixel is already loaded
|
|
568
571
|
if (window.fbq || window._fbq) {
|
|
@@ -655,7 +658,10 @@ function createFacebookPixelIntegration(config) {
|
|
|
655
658
|
}
|
|
656
659
|
function getFacebookEventName(eventName, eventMapping) {
|
|
657
660
|
// Convert default saasco page view event by default
|
|
658
|
-
if (eventName === 'Page View')
|
|
661
|
+
if (eventName === 'Page View') {
|
|
662
|
+
const mappedEvent = 'ViewContent';
|
|
663
|
+
return mappedEvent;
|
|
664
|
+
}
|
|
659
665
|
if (!eventMapping) return eventName;
|
|
660
666
|
return eventMapping[eventName] || eventName;
|
|
661
667
|
}
|
|
@@ -680,7 +686,9 @@ function trackFacebookEvent(eventName, properties, eventMapping) {
|
|
|
680
686
|
if (properties['predicted_ltv'] !== undefined) fbParams['predicted_ltv'] = properties['predicted_ltv'];
|
|
681
687
|
window.fbq('track', fbEventName, fbParams);
|
|
682
688
|
} else {
|
|
683
|
-
|
|
689
|
+
const isStandardEvent = standardFacebookEvents.includes(fbEventName);
|
|
690
|
+
const trackType = isStandardEvent ? 'track' : 'trackCustom';
|
|
691
|
+
window.fbq(trackType, fbEventName);
|
|
684
692
|
}
|
|
685
693
|
}
|
|
686
694
|
function coerceMetaConversionsAmValues(properties) {
|
|
@@ -941,10 +949,9 @@ class IntegrationManager {
|
|
|
941
949
|
if (integration.init) {
|
|
942
950
|
try {
|
|
943
951
|
state.status = 'loading';
|
|
944
|
-
this.logger.log(`init ${integration.name}`);
|
|
945
952
|
yield integration.init();
|
|
946
953
|
state.status = 'ready';
|
|
947
|
-
this.logger.log(
|
|
954
|
+
this.logger.log(`${integration.name} integration ready`);
|
|
948
955
|
this.flush();
|
|
949
956
|
} catch (e) {
|
|
950
957
|
state.status = 'error';
|
|
@@ -1051,11 +1058,9 @@ class IntegrationManager {
|
|
|
1051
1058
|
if (this.config.flushInterval <= 0) return;
|
|
1052
1059
|
this.flushTimer = setInterval(() => {
|
|
1053
1060
|
if (this.globalQueue.length > 0) {
|
|
1054
|
-
this.logger.log('periodic flush triggered');
|
|
1055
1061
|
this.flush();
|
|
1056
1062
|
}
|
|
1057
1063
|
}, this.config.flushInterval);
|
|
1058
|
-
this.logger.log(`periodic flushing enabled: ${this.config.flushInterval}ms`);
|
|
1059
1064
|
}
|
|
1060
1065
|
/**
|
|
1061
1066
|
* Setup page unload handler for client environment
|
|
@@ -1071,7 +1076,6 @@ class IntegrationManager {
|
|
|
1071
1076
|
// Use both beforeunload and pagehide for better coverage
|
|
1072
1077
|
window.addEventListener('beforeunload', this.unloadHandler);
|
|
1073
1078
|
window.addEventListener('pagehide', this.unloadHandler);
|
|
1074
|
-
this.logger.log('page unload handlers registered');
|
|
1075
1079
|
}
|
|
1076
1080
|
/** Debug helpers */
|
|
1077
1081
|
getStats() {
|
|
@@ -1313,6 +1317,10 @@ class Saasco {
|
|
|
1313
1317
|
});
|
|
1314
1318
|
// Set initial context
|
|
1315
1319
|
this.integrationManager.setContext({});
|
|
1320
|
+
// Initialize integrations immediately (works on both client and server)
|
|
1321
|
+
this.initIntegrations().catch(error => {
|
|
1322
|
+
this.logger.log('Error initializing integrations:', error);
|
|
1323
|
+
});
|
|
1316
1324
|
}
|
|
1317
1325
|
init() {
|
|
1318
1326
|
if (this.isInitialized) {
|
|
@@ -1328,10 +1336,6 @@ class Saasco {
|
|
|
1328
1336
|
this.logger.log('Saasco initialized', this.config);
|
|
1329
1337
|
if (this.config.debug) this.logger.log('Debug mode active. This will log all events to the console.');
|
|
1330
1338
|
if (!this.config.enabled) this.logger.log('Analytics is disabled. No requests will be sent to the server.');
|
|
1331
|
-
// Initialize integrations asynchronously
|
|
1332
|
-
this.initIntegrations().catch(error => {
|
|
1333
|
-
this.logger.log('Error initializing integrations:', error);
|
|
1334
|
-
});
|
|
1335
1339
|
this.initAutoPageTracking();
|
|
1336
1340
|
this.isInitialized = true;
|
|
1337
1341
|
}
|
|
@@ -1615,4 +1619,4 @@ const browserContextSchema = z.object({
|
|
|
1615
1619
|
$utmAdId: z.string().nullable()
|
|
1616
1620
|
});
|
|
1617
1621
|
|
|
1618
|
-
export { IntegrationManager, Logger, Saasco, browserContextSchema, createFacebookPixelIntegration, getBrowserContext, initializeFacebookPixel, timezones, trackFacebookEvent };
|
|
1622
|
+
export { IntegrationManager, Logger, Saasco, browserContextSchema, createFacebookPixelIntegration, getBrowserContext, initializeFacebookPixel, standardFacebookEvents, timezones, trackFacebookEvent };
|
package/package.json
CHANGED
|
@@ -17,7 +17,8 @@ export type FacebookPixelConfig = {
|
|
|
17
17
|
pixelId: string;
|
|
18
18
|
eventMapping?: FacebookEventMapping;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export declare const standardFacebookEvents: readonly ["AddPaymentInfo", "AddToCart", "AddToWishlist", "CompleteRegistration", "Contact", "CustomizeProduct", "Donate", "FindLocation", "InitiateCheckout", "Lead", "Purchase", "Schedule", "Search", "StartTrial", "SubmitApplication", "Subscribe", "ViewContent"];
|
|
21
|
+
export type StandardFacebookEvent = (typeof standardFacebookEvents)[number];
|
|
21
22
|
/**
|
|
22
23
|
* Create a Facebook Pixel integration instance
|
|
23
24
|
*/
|