UTM and query string handling¶
Query parameters (UTM tags, referral codes, etc.) must survive locale redirects. This is handled in server/middleware/geo-locale.ts by splitting pathname and search from getRequestURL(event) before any path matching or redirect target is constructed.
Why this requires explicit handling¶
In Nitro, getRequestPath() returns the raw request path including the query string. Without parsing the URL first, /?utm_source=google would not match the root check, and query parameters would be silently dropped when building redirect targets.
Behaviour by visitor type¶
| Visitor type | Entry URL | Redirect handled by | Query params preserved |
|---|---|---|---|
| First-time (no locale cookie) | /?utm_source=google | geo-locale.ts | ✅ Always |
| First-time (no locale cookie) | /da-dk/?utm_source=google | geo-locale.ts | ✅ Always |
| Returning (locale cookie set) | /?utm_source=google | nuxt-i18n | Depends on nuxt-i18n |
| Returning (locale cookie set) | /da-dk/?utm_source=google | No redirect issued | ✅ No redirect needed |
For returning visitors hitting the root, geo-locale.ts skips (they have a stored locale cookie) and nuxt-i18n handles the redirect using that cookie. This is the same behaviour as before geo-locale.ts existed.
Test URLs¶
Use these on a Cloudflare Pages environment (staging or production) where CF geolocation headers are present. Clear cookies before each test and verify in the Network tab that the redirect target URL includes the full query string.
First-time visitor, root with UTM
Expected:→ /{cf-locale}/?utm_source=google&utm_medium=cpc&utm_campaign=test First-time visitor, wrong locale prefix with UTM
Expected:→ /{cf-locale}/products?utm_source=facebook&utm_medium=social Returning visitor with confirmed locale, root with UTM
Expected:→ /da-dk/?utm_source=email&utm_campaign=spring (nuxt-i18n uses stored locale cookie) Correct locale, no redirect
Expected: page renders directly, no redirect, query params remain in URLNote:
geo-locale.tsonly responds to the real CF context. The?cfcountry=XXdev override only affects the client-side modal inuseLocaleDetection— it does not trigger the Nitro middleware.