Skip to content

Arcjet IP geolocation

Every decision provided by Arcjet includes IP address analysis. You can use this to customize your response based on the IP location.

Available fields

  • Latitude and longitude.
  • Postal code e.g. 94104.
  • City e.g. San Francisco.
  • Region e.g. California.
  • Country e.g. US.
  • Country name e.g. United States.
  • Continent e.g. NA.
  • Continent name e.g. North America.

Checking for data

The IP location fields may be undefined, but you can use various methods to check their availability. See the SDK reference for details.

Examples

// ... imports, client configuration, etc
// See https://docs.arcjet.com/get-started
const decision = await aj.protect(req);
if (decision.ip.hasCity() && decision.ip.city === "San Francisco") {
// Return a custom response for San Francisco
}
if (decision.ip.hasRegion() && decision.ip.region === "California") {
// Return a custom response for California
}
if (decision.ip.hasCountry() && decision.ip.country === "US") {
// Return a custom response for the United States
}
if (decision.ip.hasContinent() && decision.ip.continent === "NA") {
// Return a custom response for North America
}

Block all countries except US

// ... imports, client configuration, etc
// See https://docs.arcjet.com/get-started
const decision = await aj.protect(req);
if (decision.ip.hasCountry() && decision.ip.country !== "US") {
// Return 403 Forbidden
}

Block all countries except US, UK, Japan

// ... imports, client configuration, etc
// See https://docs.arcjet.com/get-started
const decision = await aj.protect(req);
if (
decision.ip.hasCountry() &&
!["US", "UK", "JP"].includes(decision.ip.country)
) {
// Return 403 Forbidden
}