( query: Record<string, string> | undefined, )
| 26 | } |
| 27 | |
| 28 | export function getReferrerWithQuery( |
| 29 | query: Record<string, string> | undefined, |
| 30 | ) { |
| 31 | if (!query) { |
| 32 | return null; |
| 33 | } |
| 34 | |
| 35 | const source = ( |
| 36 | query.utm_source ?? |
| 37 | query.ref ?? |
| 38 | query.utm_referrer ?? |
| 39 | '' |
| 40 | ).toLowerCase(); |
| 41 | |
| 42 | if (source === '') { |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | const match = |
| 47 | referrers[source] || |
| 48 | referrers[`${source}.com`] || |
| 49 | Object.values(referrers).find( |
| 50 | (referrer) => referrer.name.toLowerCase() === source, |
| 51 | ); |
| 52 | |
| 53 | if (match) { |
| 54 | return { |
| 55 | name: match.name, |
| 56 | type: match.type, |
| 57 | url: '', |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | return { |
| 62 | name: source, |
| 63 | type: '', |
| 64 | url: '', |
| 65 | }; |
| 66 | } |
no outgoing calls
no test coverage detected