|
|
|
@ -1,3 +1,65 @@ |
|
|
|
|
type UtmParams = Partial<{ |
|
|
|
|
utmSource: string; |
|
|
|
|
utmMedium: string; |
|
|
|
|
utmCampaign: string; |
|
|
|
|
utmContent: string; |
|
|
|
|
utmTerm: string; |
|
|
|
|
}>; |
|
|
|
|
|
|
|
|
|
export function getUrlUtmParams(): UtmParams { |
|
|
|
|
if (typeof window === 'undefined') { |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const utmParams = new URLSearchParams(window.location.search); |
|
|
|
|
const utmSource = utmParams.get('utm_source') ?? undefined; |
|
|
|
|
const utmMedium = utmParams.get('utm_medium') ?? undefined; |
|
|
|
|
const utmCampaign = utmParams.get('utm_campaign') ?? undefined; |
|
|
|
|
const utmContent = utmParams.get('utm_content') ?? undefined; |
|
|
|
|
const utmTerm = utmParams.get('utm_term') ?? undefined; |
|
|
|
|
|
|
|
|
|
if (!utmSource || !utmCampaign) { |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
utmSource: utmCampaign ? utmSource.toLowerCase() : undefined, |
|
|
|
|
utmMedium: utmMedium ? utmMedium.toLowerCase() : undefined, |
|
|
|
|
utmCampaign: utmCampaign ? utmCampaign.toLowerCase() : undefined, |
|
|
|
|
utmContent: utmContent ? utmContent.toLowerCase() : undefined, |
|
|
|
|
utmTerm: utmTerm ? utmTerm.toLowerCase() : undefined, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function triggerUtmRegistration() { |
|
|
|
|
const utmParams = getStoredUtmParams(); |
|
|
|
|
console.log(utmParams); |
|
|
|
|
if (!utmParams.utmSource) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
localStorage.removeItem('utm_params'); |
|
|
|
|
|
|
|
|
|
window.fireEvent({ |
|
|
|
|
category: 'UserRegistration', |
|
|
|
|
action: `Registration: ${utmParams.utmSource || 'unknown'}-${utmParams.utmCampaign || 'unknown'}`, |
|
|
|
|
label: `Registration: ${utmParams.utmSource || 'unknown'}-${utmParams.utmCampaign || 'unknown'}`, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getStoredUtmParams(): UtmParams { |
|
|
|
|
if (typeof window === 'undefined') { |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const utmParams = localStorage.getItem('utm_params'); |
|
|
|
|
if (!utmParams) { |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return JSON.parse(utmParams); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getUrlParams() { |
|
|
|
|
if (typeof window === 'undefined') { |
|
|
|
|
return {}; |
|
|
|
|