Skip to content

Commit 09736d7

Browse files
bkboothclaude
andcommitted
fix(audience): add missing click IDs and attribution fields per event reference
Add dclid (Google DV360) and li_fat_id (LinkedIn) to match the Tracking Pixel Event Reference doc. Also add referral_code parsing and touchpoint_type derivation (set to 'click' when UTMs or click IDs are present). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b4c2c2f commit 09736d7

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

packages/audience/pixel/src/attribution.test.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ describe('collectAttribution', () => {
3131

3232
it('parses ad network click IDs', () => {
3333
setLocation(
34-
'https://example.com/?gclid=abc123&fbclid=fb456&ttclid=tt789&msclkid=ms000',
34+
'https://example.com/?gclid=abc&dclid=dc1&fbclid=fb2&ttclid=tt3&msclkid=ms4&li_fat_id=li5',
3535
);
3636

3737
const result = collectAttribution();
38-
expect(result.gclid).toBe('abc123');
39-
expect(result.fbclid).toBe('fb456');
40-
expect(result.ttclid).toBe('tt789');
41-
expect(result.msclkid).toBe('ms000');
38+
expect(result.gclid).toBe('abc');
39+
expect(result.dclid).toBe('dc1');
40+
expect(result.fbclid).toBe('fb2');
41+
expect(result.ttclid).toBe('tt3');
42+
expect(result.msclkid).toBe('ms4');
43+
expect(result.li_fat_id).toBe('li5');
4244
});
4345

4446
it('captures referrer and landing page', () => {
@@ -65,6 +67,35 @@ describe('collectAttribution', () => {
6567
expect(second.utm_source).toBe('google');
6668
});
6769

70+
it('parses referral_code from the URL', () => {
71+
setLocation('https://example.com/?referral_code=PARTNER42');
72+
73+
const result = collectAttribution();
74+
expect(result.referral_code).toBe('PARTNER42');
75+
});
76+
77+
it('sets touchpoint_type to click when UTMs are present', () => {
78+
setLocation('https://example.com/?utm_source=google');
79+
80+
const result = collectAttribution();
81+
expect(result.touchpoint_type).toBe('click');
82+
});
83+
84+
it('sets touchpoint_type to click when a click ID is present', () => {
85+
setLocation('https://example.com/?gclid=abc123');
86+
87+
const result = collectAttribution();
88+
expect(result.touchpoint_type).toBe('click');
89+
});
90+
91+
it('does not set touchpoint_type when no UTMs or click IDs are present', () => {
92+
setLocation('https://example.com/');
93+
Object.defineProperty(document, 'referrer', { value: 'https://other.com', configurable: true });
94+
95+
const result = collectAttribution();
96+
expect(result.touchpoint_type).toBeUndefined();
97+
});
98+
6899
it('returns empty attribution when no params are present', () => {
69100
setLocation('https://example.com/');
70101
Object.defineProperty(document, 'referrer', { value: '', configurable: true });

packages/audience/pixel/src/attribution.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ const UTM_PARAMS = [
88

99
const CLICK_ID_PARAMS = [
1010
'gclid',
11+
'dclid',
1112
'fbclid',
1213
'ttclid',
1314
'msclkid',
15+
'li_fat_id',
1416
] as const;
1517

1618
const STORAGE_KEY = '__imtbl_attribution';
@@ -22,11 +24,15 @@ export interface Attribution {
2224
utm_content?: string;
2325
utm_term?: string;
2426
gclid?: string;
27+
dclid?: string;
2528
fbclid?: string;
2629
ttclid?: string;
2730
msclkid?: string;
31+
li_fat_id?: string;
32+
referral_code?: string;
2833
referrer?: string;
2934
landing_page?: string;
35+
touchpoint_type?: string;
3036
}
3137

3238
type AttributionKey = keyof Attribution;
@@ -46,6 +52,12 @@ function parseParams(url: string): Attribution {
4652
result[key as AttributionKey] = value;
4753
}
4854
}
55+
56+
const referralCode = params.get('referral_code');
57+
if (referralCode) {
58+
result.referral_code = referralCode;
59+
}
60+
4961
return result;
5062
}
5163

@@ -79,10 +91,14 @@ export function collectAttribution(): Attribution {
7991
? window.location.href
8092
: undefined;
8193

94+
const hasClickId = CLICK_ID_PARAMS.some((key) => key in urlParams);
95+
const hasUtm = UTM_PARAMS.some((key) => key in urlParams);
96+
8297
const attribution: Attribution = {
8398
...urlParams,
8499
referrer,
85100
landing_page: landingPage,
101+
touchpoint_type: hasClickId || hasUtm ? 'click' : undefined,
86102
};
87103

88104
saveToStorage(attribution);

0 commit comments

Comments
 (0)