Skip to content

Commit 3ba8a98

Browse files
authored
fix(meta-pixel): refine fbq type definitions (#464)
1 parent fb2d62b commit 3ba8a98

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

docs/content/scripts/tracking/meta-pixel.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,23 @@ export interface MetaPixelApi {
107107
}
108108
_fbq: MetaPixelApi['fbq']
109109
}
110-
type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void)
111-
& ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void)
112-
& ((event: 'init', id: number, data?: Record<string, any>) => void)
113-
& ((event: 'init', id: string) => void)
114-
& ((event: string, ...params: any[]) => void)
110+
type FbqArgs =
111+
| ['track', StandardEvents, EventObjectProperties?]
112+
| ['trackCustom', string, EventObjectProperties?]
113+
| ['trackSingle', string, StandardEvents, EventObjectProperties?]
114+
| ['trackSingleCustom', string, string, EventObjectProperties?]
115+
| ['init', string]
116+
| ['init', number, Record<string, any>?]
117+
| ['consent', ConsentAction]
118+
| [string, ...any[]]
119+
type FbqFns = (...args: FbqArgs) => void
115120
type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent'
116121
interface EventObjectProperties {
117122
content_category?: string
118123
content_ids?: string[]
119124
content_name?: string
120125
content_type?: string
121-
contents: { id: string, quantity: number }[]
126+
contents?: { id: string, quantity: number }[]
122127
currency?: string
123128
delivery_category?: 'in_store' | 'curbside' | 'home_delivery'
124129
num_items?: number
@@ -128,6 +133,7 @@ interface EventObjectProperties {
128133
value?: number
129134
[key: string]: any
130135
}
136+
type ConsentAction = 'grant' | 'revoke'
131137
```
132138
133139
### Config Schema

src/runtime/registry/meta-pixel.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface EventObjectProperties {
88
content_ids?: string[]
99
content_name?: string
1010
content_type?: string
11-
contents: { id: string, quantity: number }[]
11+
contents?: { id: string, quantity: number }[]
1212
currency?: string
1313
delivery_category?: 'in_store' | 'curbside' | 'home_delivery'
1414
num_items?: number
@@ -18,8 +18,19 @@ interface EventObjectProperties {
1818
value?: number
1919
[key: string]: any
2020
}
21+
type ConsentAction = 'grant' | 'revoke'
2122

22-
type FbqFns = ((event: 'track', eventName: StandardEvents, data?: EventObjectProperties) => void) & ((event: 'trackCustom', eventName: string, data?: EventObjectProperties) => void) & ((event: 'init', id: number, data?: Record<string, any>) => void) & ((event: 'init', id: string) => void) & ((event: string, ...params: any[]) => void)
23+
type FbqArgs =
24+
| ['track', StandardEvents, EventObjectProperties?]
25+
| ['trackCustom', string, EventObjectProperties?]
26+
| ['trackSingle', string, StandardEvents, EventObjectProperties?]
27+
| ['trackSingleCustom', string, string, EventObjectProperties?]
28+
| ['init', string]
29+
| ['init', number, Record<string, any>?]
30+
| ['consent', ConsentAction]
31+
// fallback: allow any fbq call signature not covered above
32+
| [string, ...any[]]
33+
type FbqFns = (...args: FbqArgs) => void
2334

2435
export interface MetaPixelApi {
2536
fbq: FbqFns & {

0 commit comments

Comments
 (0)