-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
export const ReferrerTracker = () => { | ||
useEffect(() => { | ||
try { | ||
const existingReferrer = localStorage.getItem('userReferrer'); | ||
|
||
if (!existingReferrer) { | ||
const referrer = document.referrer; | ||
|
||
const url = new URL(window.location.href); | ||
const utmSource = url.searchParams.get('utm_source'); | ||
const utmMedium = url.searchParams.get('utm_medium'); | ||
const utmCampaign = url.searchParams.get('utm_campaign'); | ||
const urlRef = url.searchParams.get('ref'); | ||
|
||
if (referrer || utmSource || urlRef) { | ||
const referrerData = { | ||
referrer, | ||
utmSource, | ||
utmMedium, | ||
utmCampaign, | ||
urlRef, | ||
firstVisit: new Date().toISOString(), | ||
}; | ||
console.log('Referrer tracking:', referrerData); | ||
localStorage.setItem('userReferrer', JSON.stringify(referrerData)); | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Referrer tracking failed:', error); | ||
} | ||
}, []); | ||
|
||
return null; | ||
}; |