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.

// 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.


Did this page help you?