File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const initConversionTracking = ( ) => {
2- const { a : API_HOST , k : PUBLISHABLE_KEY } = window . _dubAnalytics || { } ;
2+ const {
3+ a : API_HOST ,
4+ k : PUBLISHABLE_KEY ,
5+ c : cookieManager ,
6+ i : DUB_ID_VAR ,
7+ } = window . _dubAnalytics || { } ;
38
49 if ( ! API_HOST ) {
510 console . warn ( '[dubAnalytics] Missing API_HOST' ) ;
@@ -13,13 +18,20 @@ const initConversionTracking = () => {
1318
1419 // Track lead conversion
1520 const trackLead = async ( input ) => {
21+ const clickId = cookieManager ?. get ( DUB_ID_VAR ) ;
22+
23+ const requestBody = {
24+ ...( clickId && { clickId } ) ,
25+ ...input ,
26+ } ;
27+
1628 const response = await fetch ( `${ API_HOST } /track/lead/client` , {
1729 method : 'POST' ,
1830 headers : {
1931 'Content-Type' : 'application/json' ,
2032 Authorization : `Bearer ${ PUBLISHABLE_KEY } ` ,
2133 } ,
22- body : JSON . stringify ( input ) ,
34+ body : JSON . stringify ( requestBody ) ,
2335 } ) ;
2436
2537 const result = await response . json ( ) ;
Original file line number Diff line number Diff line change @@ -166,24 +166,24 @@ export interface TrackClickInput {
166166}
167167
168168export interface TrackLeadInput {
169- clickId : string ;
169+ clickId ? : string ; // falls back to dub_id cookie
170170 eventName : string ;
171171 customerExternalId : string ;
172- customerName ?: string | null ;
173- customerEmail ?: string | null ;
174- customerAvatar ?: string | null ;
172+ customerName ?: string ;
173+ customerEmail ?: string ;
174+ customerAvatar ?: string ;
175175 mode ?: string ;
176- metadata ?: Record < string , any > ;
176+ metadata ?: Record < string , unknown > ;
177177}
178178
179179export interface TrackSaleInput {
180180 eventName : string ;
181181 customerExternalId : string ;
182- paymentProcessor : string ;
182+ paymentProcessor ? : string ;
183183 amount : number ;
184- invoiceId ?: string | null ;
184+ invoiceId ?: string ;
185185 currency ?: string ;
186- metadata ?: Record < string , any > ;
186+ metadata ?: Record < string , unknown > ;
187187}
188188
189189export interface Partner {
You can’t perform that action at this time.
0 commit comments