-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathtrackConversions.ts
More file actions
61 lines (51 loc) · 1.54 KB
/
trackConversions.ts
File metadata and controls
61 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { linkedInTrack } from 'nextjs-linkedin-insight-tag'
export const LINKED_IN_CAMPAIGN_ID = 719181716 // 'Codebuff YC'
export const storeSearchParams = (searchParams: URLSearchParams) => {
const liFatId = searchParams.get('li_fat_id')
if (liFatId) {
localStorage.setItem('li_fat_id', liFatId)
}
const utm_source = searchParams.get('utm_source')
if (utm_source) {
localStorage.setItem('utm_source', utm_source)
}
const referrer = searchParams.get('referrer')
if (referrer) {
localStorage.setItem('referrer', referrer)
}
}
export const trackUpgrade = (
markConversionComplete: boolean
): URLSearchParams => {
const params = new URLSearchParams()
// Came from LinkedIn
const liFatId = localStorage.getItem('li_fat_id')
if (liFatId) {
if (markConversionComplete) {
linkedInTrack(LINKED_IN_CAMPAIGN_ID)
localStorage.removeItem('li_fat_id')
}
params.set('utm_source', 'linkedin')
params.set('li_fat_id', liFatId)
}
// utm campaign
const utm_source = localStorage.getItem('utm_source')
if (utm_source) {
if (markConversionComplete) {
console.log(`test campaign tracked: ${utm_source}`)
localStorage.removeItem('utm_source')
}
params.set('utm_source', utm_source)
}
// referrer
const referrer = localStorage.getItem('referrer')
if (referrer) {
if (markConversionComplete) {
console.log(`referrer tracked: ${referrer}`)
localStorage.removeItem('referrer')
}
params.set('referrer', referrer)
}
// Handle other campaigns
return params
}