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.
1
// Getting the country code from the user's IP
2
$.get("https://api.ipdata.co?api-key=test", function (response) {
3
if (response.country_code == 'UK') {
4
window.location.href = "https://uk.store.ipdata.co";
5
} else if (response.country_code == 'DE') {
6
window.location.href = "https://de.store.ipdata.co";
7
} else if (response.country_code == 'AU') {
8
window.location.href = "https://au.store.ipdata.co";
9
}
10
}, "jsonp");
Copied!
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.
Last modified 2yr ago
Copy link