cs-icon.svg

Geolocation Headers in Launch

Launch automatically includes geolocation headers in every incoming request. You can use these headers in Edge Functions, Cloud Functions, or backend APIs to personalize content, analyze traffic, or apply region-specific logic.

Available Headers

All requests on Launch include the following geolocation headers:

Location Header NameDescriptionExample
Visitor-IP-CountryThe 2-letter country code of the IP addressUS
Visitor-IP-RegionThe ISO 3166-2 name for the first-level region associated with the IPOregon
Visitor-IP-CityThe city name associated with the IP addressThe Dalles

Note: Launch’s Edge infrastructure automatically injects these headers. They are available across all Contentstack regions.

How to Access Geolocation Headers

Geolocation headers are included in each incoming request and can be accessed like any other HTTP headers using your runtime's API. See the following examples:

Edge Function Example (JavaScript)

// Edge Function
export default function handler(request, context) {
  const country = request.headers.get('visitor-ip-country');
  const region = request.headers.get('visitor-ip-region');
  const city = request.headers.get('visitor-ip-city');

  const parsedUrl = new URL(request.url);
  if (parsedUrl.pathname === '/appliances') {
    return new Response(JSON.stringify({
      location: `${city}, ${region}, ${country}`,
      timestamp: new Date().toISOString(),
    }), {
      headers: { 'Content-Type': 'application/json' }
    });
  }
  return fetch(request);
}

Cloud Function Example

// functions/hello.js

export default function handler(request, response) {
  const country = request.headers['visitor-ip-country'];
  const region = request.headers['visitor-ip-region'];
  const city = request.headers['visitor-ip-city'];

  response.status(200).json({
    location: `${city}, ${region}, ${country}`,
    method: request.method,
  });
}

Next.js API Route Example

// pages/api/geo.js

export default function handler(req, res) {
  const country = req.headers['visitor-ip-country'];
  const region = req.headers['visitor-ip-region'];
  const city = req.headers['visitor-ip-city'];

  res.status(200).json({
    location: `${city}, ${region}, ${country}`,
    timestamp: new Date().toISOString(),
  });
}

Troubleshooting

If a header value appears empty or inaccurate, it may be due to one of the following uncommon scenarios:

  • Privacy tools: The visitor is using a VPN, proxy, or privacy-focused browser.
  • New IP ranges: The IP address is recently allocated and not yet listed in global geolocation databases.
Was this article helpful?
^