add logging with loglevel

This commit is contained in:
Elijah Duffy
2025-12-16 18:21:39 -08:00
parent af1c423ccb
commit 802a825854
5 changed files with 37 additions and 5 deletions

View File

@@ -39,18 +39,21 @@
loadMetaPixel(); // Load the Meta Pixel script
}
this._baseLoaded = true;
log.debug('Meta Pixel base script loaded.');
}
/** Tells the Meta pixel that the user has given consent for tracking. */
static grantConsent() {
this.loadGuard();
window.fbq?.('consent', 'grant');
log.debug('Meta Pixel consent granted.');
}
/** Tells the Meta pixel that the user has revoked consent for tracking. */
static revokeConsent() {
this.loadGuard();
window.fbq?.('consent', 'revoke');
log.debug('Meta Pixel consent revoked.');
}
/**
@@ -89,6 +92,7 @@
fireInit(advancedMatching?: AdvancedMatching, initOptions?: InitOptions): PixelControl {
PixelControl.loadGuard();
window.fbq('init', this._pixelID, advancedMatching, initOptions);
log.debug(`Meta Pixel [${this._pixelID}] initialized.`);
return this;
}
@@ -111,6 +115,9 @@
pageView() {
if (!this.consentGuard()) return;
window.fbq('track', 'PageView', undefined, { test_event_code: this._testEventCode });
log.debug(
`Meta Pixel [${this._pixelID}] PageView event sent (test code: ${this._testEventCode}).`
);
}
/**
@@ -123,6 +130,9 @@
eventID,
test_event_code: this._testEventCode
});
log.debug(
`Meta Pixel [${this._pixelID}] ${event} event sent (test code: ${this._testEventCode}).`
);
}
/**
@@ -135,6 +145,9 @@
eventID,
test_event_code: this._testEventCode
});
log.debug(
`Meta Pixel [${this._pixelID}] ${event} custom event sent (test code: ${this._testEventCode}).`
);
}
}
</script>
@@ -154,6 +167,7 @@
import { loadMetaPixel } from './util/meta-pixel-loader.ts';
import { onNavigate } from '$app/navigation';
import { resolveGetter, type MaybeGetter } from './util/getter.ts';
import log from 'loglevel';
interface Props {
/** Meta Pixel ID */