---
updatedAt: 2025-11-11T22:57:55.000Z
agentTools:
  projectIndex: https://docs.ipdata.co/llms.txt
---

# Redirect by Country

This example shows you how to redirect users based on their country. You could for example redirect the user to a country-specific store from your international store.

```javascript
// Getting the country code from the user's IP
$.get("https://api.ipdata.co?api-key=<<apiKey>>", function (response) {
  if (response.country_code == 'UK') {
    window.location.href = "https://uk.store.ipdata.co";
    } else if (response.country_code == 'DE') {
    window.location.href = "https://de.store.ipdata.co";
    } else if (response.country_code == 'AU') {
    window.location.href = "https://au.store.ipdata.co";
    }
}, "jsonp");
```

This example will redirect users from the UK to <https://uk.store.ipdata.co>, users from Germany to <https://de.store.ipdata.co> and users from Australia to <https://au.store.ipdata.co>.

This an incredibly common usecase for geolocation.