diff --git a/src/lib/metapixel/pixel-control.ts b/src/lib/metapixel/pixel-control.ts index 1a6cfce..fbe93e4 100644 --- a/src/lib/metapixel/pixel-control.ts +++ b/src/lib/metapixel/pixel-control.ts @@ -197,14 +197,15 @@ export class PixelControl { /** * Sends a PageView event + * @param disableCAPI If true, disables sending this event to the Conversion API * @throws Error if the Meta Pixel is not initialized. */ - pageView() { + pageView(disableCAPI: boolean = false) { if (!this.consentGuard()) return; let eventID: string | undefined = undefined; // Optionally, send to conversion API endpoint if configured - if (this._conversionClient) { + if (this._conversionClient && !disableCAPI) { eventID = crypto.randomUUID(); this._conversionClient .trackEvent('PageView', { eventID }) @@ -241,13 +242,22 @@ export class PixelControl { /** * Tracks a standard event for this pixel (uses `trackSingle` under the hood) + * @param event Standard event name + * @param params Event parameters + * @param eventID Optional event ID for deduplication with Conversion API + * @param disableCAPI If true, disables sending this event to the Conversion API * @throws Error if the Meta Pixel is not initialized. */ - track(event: K, params?: EventParamsByName[K], eventID?: string) { + track( + event: K, + params?: EventParamsByName[K], + eventID?: string, + disableCAPI: boolean = false + ) { if (!this.consentGuard()) return; // Optionally, send to conversion API endpoint if configured - if (this._conversionClient) { + if (this._conversionClient && !disableCAPI) { eventID = eventID ?? crypto.randomUUID(); this._conversionClient .trackEvent(event, { eventID: eventID, customData: pixelParamsToCustomData(params ?? {}) })