meta pixel: more robust loading & graceful failure with adblockers
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* @throws Error if the Meta Pixel API is not loaded.
|
||||
*/
|
||||
static loadGuard(): void {
|
||||
if (!this._baseLoaded || !window._fbq) {
|
||||
if (!this._baseLoaded || !window.fbq) {
|
||||
throw new Error('Meta Pixel API has not been loaded. Call PixelControl.load() first.');
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,14 @@
|
||||
}
|
||||
|
||||
/** Loads the Meta Pixel base script. */
|
||||
static load() {
|
||||
if (this._baseLoaded && window._fbq) return;
|
||||
if (!window._fbq) {
|
||||
PixelControl.revokeConsent(); // Initialize without consent
|
||||
loadMetaPixel(); // Load the Meta Pixel script
|
||||
static async load() {
|
||||
if (this._baseLoaded && !!window.fbq) return;
|
||||
if (!window.fbq) {
|
||||
try {
|
||||
await loadMetaPixel(); // Load the Meta Pixel script
|
||||
} catch (e) {
|
||||
log.warn('Failed to load Meta Pixel script, all events will be queued.', e);
|
||||
}
|
||||
}
|
||||
this._baseLoaded = true;
|
||||
log.debug('Meta Pixel base script loaded.');
|
||||
|
||||
Reference in New Issue
Block a user