Back to Engineering Blog
Growth & Privacy7 min read•

How to Detect Visitor Country and City from a Short Link: Complete Geo-Targeting and Analytics Guide

Discover how to detect visitor country, region, and city from short link clicks using edge headers. Learn how to configure geo-targeted dynamic routing without invasive tracking cookies.

M

Maya Lin

Digital Campaign Producer

Why Detecting Visitor Country is Essential for Global Campaigns

When sharing links across global audiences on social media, newsletters, or ad networks, a single destination URL rarely fits every visitor.

A user clicking your link in the United Kingdom expects to see prices in GBP and inventory shipping from London. A user clicking in Germany expects German localization. A user in North America expects pricing in USD.

To deliver this experience seamlessly, modern marketing infrastructure relies on the ability to detect visitor country and city immediately upon link click:

  • **Regional Store Redirection:** Send UK visitors to your .co.uk shop and French visitors to .fr automatically from a single short link.
  • **Localized App Store Distribution:** Route mobile visitors to the regional storefront holding your authorized app license.
  • **Precise Budget Verification:** Confirm that your targeted ad spend in Tokyo, London, or Toronto actually generated clicks from those exact geographic boundaries.
  • How Edge Redirection Detects Visitor Country Without Cookies

    Legacy link shorteners attempted to detect visitor country by injecting heavy JavaScript trackers or querying third-party IP address databases after the page rendered. This introduced severe redirect latency (often delaying clicks by 800ms to 2 seconds) and triggered GDPR cookie compliance violations.

    Modern edge platforms like TLink take an entirely different approach:

  • **Edge Anycast Resolution:** When a visitor clicks a TLink short URL, their request hits the nearest edge data center across more than 300 points of presence globally.
  • **Stateless HTTP Header Extraction:** The edge proxy automatically enriches incoming request headers with ISO geographic attributes directly from the TCP/IP network layer:
  • * `cf-ipcountry` or `x-vercel-ip-country`: 2-letter ISO country code (e.g. US, GB, DE, JP).

    * `cf-ipcity` or `x-vercel-ip-city`: URL-encoded city name (e.g. London, Tokyo, New York).

    * `x-vercel-ip-country-region`: State or prefecture code.

  • **Instant Header-Based Routing:** The server checks your link's geo-routing rules in memory. If a country-specific destination is defined, the edge returns an immediate HTTP 302 redirect directly to that target in under 40 milliseconds.
  • **Zero-Cookie Privacy Telemetry:** Clicks, country codes, and city names are aggregated anonymously in real time without storing visitor IP addresses, browsing histories, or tracking cookies.
  • Configuring Geo-Targeted Links in TLink

    Setting up country-specific link routing takes less than a minute:

  • Create a short link in your TLink dashboard (or via the REST API).
  • Open the **Advanced Routing & Geo-Targets** drawer.
  • Select the target countries you want to customize (e.g., US, GB, CA, AU).
  • Enter the dedicated destination URL for each region.
  • Save your link.
  • When a visitor clicks your short code, TLink detects their country from the incoming HTTP request. If their country matches one of your rules, they are routed to their designated regional URL. All other visitors proceed smoothly to your primary fallback destination.

    Measuring Campaign Performance by City

    In addition to routing, TLink provides visual click distribution maps broken down by both country and city. You can see at a glance whether your clicks came from London, Manchester, New York, or Sydney:

  • Pinpoint top-performing metropolitan hubs.
  • Optimize publishing schedules around exact regional time zones.
  • Verify campaign reach with complete data integrity.
  • Best of all, geo-targeted routing and city analytics on TLink are completely free with zero subscription paywalls.

    Tags:#Detect Visitor Country#Geo Targeted Links#City Tracking#Edge Redirection#GDPR Compliance

    Try TLink Free Today

    Sub-100ms redirects, 50/50 A/B split routing, and lossless vector QR codes. 100% free forever.