pixel: fix $state usage, fix load ordering
This commit is contained in:
@@ -10,7 +10,7 @@ PixelControl interface.
|
||||
|
||||
import type { TrackingManager } from '../tracking.svelte.ts';
|
||||
import { onNavigate } from '$app/navigation';
|
||||
import { PixelControl, type PixelControlOptions } from './pixel-control.svelte.ts';
|
||||
import { PixelControl, type PixelControlOptions } from './pixel-control.ts';
|
||||
import { ensureFbc, type EnsureFbcOptions } from './fbc.ts';
|
||||
|
||||
interface Props {
|
||||
@@ -38,22 +38,20 @@ PixelControl interface.
|
||||
|
||||
let pixel = $state<PixelControl | null>(null);
|
||||
|
||||
const ensureFbcOptions: EnsureFbcOptions = $derived({
|
||||
sameSite: 'Lax',
|
||||
pixelLoaded: PixelControl.baseLoaded && !PixelControl.baseFailed
|
||||
});
|
||||
const fbcOptions: EnsureFbcOptions = {
|
||||
sameSite: 'Lax'
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
if (!trackingManager) {
|
||||
throw new Error('MetaPixel component requires a TrackingManager to manage consent.');
|
||||
}
|
||||
PixelControl.load();
|
||||
pixel = PixelControl.initialize(trackingManager, pixelID, pixelOptions);
|
||||
|
||||
trackingManager.runWithConsent(() => {
|
||||
if (autoPageView && pixel) {
|
||||
pixel.pageView();
|
||||
ensureFbc(ensureFbcOptions);
|
||||
ensureFbc(fbcOptions);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -62,7 +60,7 @@ PixelControl interface.
|
||||
trackingManager?.runWithConsent(() => {
|
||||
if (autoPageView && pixel) {
|
||||
pixel.pageView();
|
||||
ensureFbc(ensureFbcOptions);
|
||||
ensureFbc(fbcOptions);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user