From 0ab65b9e888fecdaf6d26e0124e859e66d01ce56 Mon Sep 17 00:00:00 2001 From: tsukiyama-3 Date: Sat, 7 Jun 2025 02:57:51 +0900 Subject: [PATCH] chore(meta-pixel): refine fbq type definitions --- docs/content/scripts/tracking/meta-pixel.md | 18 ++++++++++++------ src/runtime/registry/meta-pixel.ts | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/content/scripts/tracking/meta-pixel.md b/docs/content/scripts/tracking/meta-pixel.md index aec8e6b7..b1185f60 100644 --- a/docs/content/scripts/tracking/meta-pixel.md +++ b/docs/content/scripts/tracking/meta-pixel.md @@ -107,18 +107,23 @@ export interface MetaPixelApi { } _fbq: MetaPixelApi['fbq'] } -type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) - & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) - & ((event: 'init', id: number, data?: Record) => void) - & ((event: 'init', id: string) => void) - & ((event: string, ...params: any[]) => void) +type FbqArgs = + | ['track', StandardEvents, EventObjectProperties?] + | ['trackCustom', string, EventObjectProperties?] + | ['trackSingle', string, StandardEvents, EventObjectProperties?] + | ['trackSingleCustom', string, string, EventObjectProperties?] + | ['init', string] + | ['init', number, Record?] + | ['consent', ConsentAction] + | [string, ...any[]] +type FbqFns = (...args: FbqArgs) => void type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent' interface EventObjectProperties { content_category?: string content_ids?: string[] content_name?: string content_type?: string - contents: { id: string, quantity: number }[] + contents?: { id: string, quantity: number }[] currency?: string delivery_category?: 'in_store' | 'curbside' | 'home_delivery' num_items?: number @@ -128,6 +133,7 @@ interface EventObjectProperties { value?: number [key: string]: any } +type ConsentAction = 'grant' | 'revoke' ``` ### Config Schema diff --git a/src/runtime/registry/meta-pixel.ts b/src/runtime/registry/meta-pixel.ts index e0564962..f735a197 100644 --- a/src/runtime/registry/meta-pixel.ts +++ b/src/runtime/registry/meta-pixel.ts @@ -8,7 +8,7 @@ interface EventObjectProperties { content_ids?: string[] content_name?: string content_type?: string - contents: { id: string, quantity: number }[] + contents?: { id: string, quantity: number }[] currency?: string delivery_category?: 'in_store' | 'curbside' | 'home_delivery' num_items?: number @@ -18,8 +18,19 @@ interface EventObjectProperties { value?: number [key: string]: any } +type ConsentAction = 'grant' | 'revoke' -type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) & ((event: 'init', id: number, data?: Record) => void) & ((event: 'init', id: string) => void) & ((event: string, ...params: any[]) => void) +type FbqArgs = + | ['track', StandardEvents, EventObjectProperties?] + | ['trackCustom', string, EventObjectProperties?] + | ['trackSingle', string, StandardEvents, EventObjectProperties?] + | ['trackSingleCustom', string, string, EventObjectProperties?] + | ['init', string] + | ['init', number, Record?] + | ['consent', ConsentAction] + // fallback: allow any fbq call signature not covered above + | [string, ...any[]] +type FbqFns = (...args: FbqArgs) => void export interface MetaPixelApi { fbq: FbqFns & {