pixel: add ensure fbc fallback
This commit is contained in:
@@ -68,7 +68,8 @@ export class PixelControl {
|
||||
private _trackingManager: MaybeGetter<TrackingManager | undefined>;
|
||||
private _conversionClient?: ConversionClient = undefined;
|
||||
|
||||
private static _baseLoaded: boolean = false;
|
||||
private static _baseLoaded: boolean = $state(false);
|
||||
private static _baseFailed: boolean = $state(false);
|
||||
private static _registeredPixels: Record<string, PixelControl> = {};
|
||||
|
||||
/** Indicates whether the Meta Pixel base script has been loaded. */
|
||||
@@ -76,6 +77,11 @@ export class PixelControl {
|
||||
return this._baseLoaded;
|
||||
}
|
||||
|
||||
/** Indicates whether the Meta Pixel base script has failed to load. */
|
||||
static get baseFailed(): boolean {
|
||||
return this._baseFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the Meta Pixel base has been loaded before
|
||||
* allowing further operations.
|
||||
@@ -111,15 +117,18 @@ export class PixelControl {
|
||||
|
||||
/** Loads the Meta Pixel base script. */
|
||||
static async load() {
|
||||
if (this._baseLoaded && !!window.fbq) return;
|
||||
if (this._baseLoaded && !this.baseFailed && !!window.fbq) return;
|
||||
if (!window.fbq) {
|
||||
try {
|
||||
await loadMetaPixel(); // Load the Meta Pixel script
|
||||
} catch (e) {
|
||||
log.warn('[PixelControl] Failed to load Meta Pixel script, all events will be queued.', e);
|
||||
this._baseFailed = true;
|
||||
return;
|
||||
} finally {
|
||||
this._baseLoaded = true;
|
||||
}
|
||||
}
|
||||
this._baseLoaded = true;
|
||||
log.debug('[PixelControl] Meta Pixel base script loaded.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user