Country Specific Redirection

Shopify Partner
44 0 2

Hey Everyone,

Is there a best practice when it comes to redirecting a user to a particular shop. I have a US and non US shop, I would like to redirect the customer accordingly. I'm assuming IP is the best way to do this, but it doesn't work so well for the phone.

Any help is appreciated.

Thank you for your time

0 Likes
Shopify Partner
44 0 2

Anyone have an answer? Any help is appreciated.

Thanks

0 Likes
Shopify Partner
23 0 0

A great app for this is Country and Currency Redirect

 

You can easily set up redirects based on a users location or what currency they use

0 Likes
Tourist
21 0 3

Hi Manatarms,

 

You can redirect your user according to his location by using IP Geolocation API services such as IPGeolocation very easily. IP Geolocation is the technique of finding the approximate physical location of an internet-connected device through an IP address and IP Geolocation API is the availability of this technique in the form of an API.

 

 To redirect the US and non-US users to their specific shop, you have to follow these two steps:

 

  • First, you have to find the location of the user by using the IP Geolocation API service. (For details visit IP Geolocation API documentation)
  • Secondly, after that, redirect him on the basis of his location by using the following code.
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (4 === this.readyState && 200 === this.status) {
var json = JSON.parse(this.responseText);
if (json.country_code2 == "US" && window.location.hostname !== "http://us.exmaple.com"{
    window.location.href = "https://us.exmaple.com";
} else if (window.location.hostname !== "http://exmaple.com"
{
    window.location.href = "https://exmaple.com";
}
}
}
request.open("GET", "https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY&fields=country_code2", false);
request.setRequestHeader("Accept", "application/json");
request.send();

For more information, you can contact support@ipgeolocation.io.

0 Likes