pixel: add ensure fbc fallback

This commit is contained in:
Elijah Duffy
2025-12-18 19:22:54 -08:00
parent f2d389ee64
commit 0cd3f10da6
5 changed files with 114 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ PixelControl interface.
import type { TrackingManager } from '../tracking.svelte.ts';
import { onNavigate } from '$app/navigation';
import { PixelControl, type PixelControlOptions } from './pixel-control.ts';
import { ensureFbc, type EnsureFbcOptions } from './fbc.ts';
interface Props {
/**
@@ -37,6 +38,11 @@ PixelControl interface.
let pixel = $state<PixelControl | null>(null);
const ensureFbcOptions: EnsureFbcOptions = $derived({
sameSite: 'Lax',
pixelLoaded: PixelControl.baseLoaded && !PixelControl.baseFailed
});
onMount(() => {
if (!trackingManager) {
throw new Error('MetaPixel component requires a TrackingManager to manage consent.');
@@ -47,6 +53,7 @@ PixelControl interface.
trackingManager.runWithConsent(() => {
if (autoPageView && pixel) {
pixel.pageView();
ensureFbc(ensureFbcOptions);
}
});
});
@@ -55,6 +62,7 @@ PixelControl interface.
trackingManager?.runWithConsent(() => {
if (autoPageView && pixel) {
pixel.pageView();
ensureFbc(ensureFbcOptions);
}
});
});