Skip to content

Commit f73a0ce

Browse files
authored
fix(tiktokPixel): missing types (#773)
1 parent 6129314 commit f73a0ce

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎packages/script/src/runtime/registry/tiktok-pixel.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ type StandardEvents
1313
|'AddPaymentInfo'
1414
|'CompletePayment'
1515
|'PlaceAnOrder'
16+
|'Purchase'
1617
|'Contact'
1718
|'Download'
1819
|'SubmitForm'
1920
|'CompleteRegistration'
2021
|'Subscribe'
22+
|'StartTrial'
2123

2224
interfaceEventProperties{
2325
content_id?: string
@@ -37,8 +39,14 @@ interface IdentifyProperties {
3739
external_id?: string
3840
}
3941

42+
interfaceTrackOptions{
43+
/** Used to deduplicate events sent from both the browser Pixel and the server-side Events API. */
44+
event_id?: string
45+
[key: string]: any
46+
}
47+
4048
typeTtqFns
41-
=((cmd: 'track',event: StandardEvents|(string&{}),properties?: EventProperties)=>void)
49+
=((cmd: 'track',event: StandardEvents|(string&{}),properties?: EventProperties,options?: TrackOptions)=>void)
4250
&((cmd: 'page')=>void)
4351
&((cmd: 'identify',properties: IdentifyProperties)=>void)
4452
&((cmd: (string&{}), ...args: any[])=>void)

‎test/types/types.test-d.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importtype{ModuleOptions}from'../../packages/script/src/module'
22
importtype{CrispApi}from'../../packages/script/src/runtime/registry/crisp'
33
importtype{DefaultEventName}from'../../packages/script/src/runtime/registry/google-analytics'
4+
importtype{TikTokPixelApi}from'../../packages/script/src/runtime/registry/tiktok-pixel'
45
importtype{NuxtConfigScriptRegistry,NuxtConfigScriptRegistryEntry,NuxtUseScriptOptions,RegistryScriptInput,ScriptRegistry,UseScriptContext}from'../../packages/script/src/runtime/types'
56
import{describe,expectTypeOf,it}from'vitest'
67

@@ -157,3 +158,20 @@ describe('#nuxt-scripts/types exports', () => {
157158
expectTypeOf<ScriptRegistry>().toHaveProperty('clarity')
158159
})
159160
})
161+
162+
describe('tiktok pixel ttq',()=>{
163+
typeTtq=TikTokPixelApi['ttq']
164+
165+
it('track accepts the 4th options arg with event_id',()=>{
166+
expectTypeOf<Ttq>().toBeCallableWith('track','Purchase',{value: 10},{event_id: 'abc'})
167+
})
168+
169+
it('track accepts standard events including Purchase and StartTrial',()=>{
170+
expectTypeOf<Ttq>().toBeCallableWith('track','Purchase')
171+
expectTypeOf<Ttq>().toBeCallableWith('track','StartTrial')
172+
})
173+
174+
it('track still accepts arbitrary custom event names',()=>{
175+
expectTypeOf<Ttq>().toBeCallableWith('track','CustomEvent')
176+
})
177+
})

0 commit comments

Comments
 (0)