pixel: allow disabling conversion API forwarding
This commit is contained in:
@@ -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<K extends StandardEventName>(event: K, params?: EventParamsByName[K], eventID?: string) {
|
||||
track<K extends StandardEventName>(
|
||||
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 ?? {}) })
|
||||
|
||||
Reference in New Issue
Block a user