Skip to content

Commit 15affd7

Browse files
committed
fallback to dub_id cookie for clickId
1 parent 4ed4f83 commit 15affd7

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

packages/script/src/extensions/conversion-tracking.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const 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();

packages/web/src/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,24 @@ export interface TrackClickInput {
166166
}
167167

168168
export 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

179179
export 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

189189
export interface Partner {

0 commit comments

Comments
 (0)