Happening now | Office Hours: Customizing Your Theme with Moeed | Ask all your theme customization questions now!

Geolocation Redirect from Shopify to non-Shopify Website

Geolocation Redirect from Shopify to non-Shopify Website

jmarano
Visitor
1 0 0

We are looking to redirect users from our Shopify website to a third-party non-Shopify website based on their location, using the appropriate domain for that location. 

 

As an example: 

We saw third party apps that could somehow do this, but will these work from Shopify to non Shopify website?

  1. GeoIP Country Redirect - Redirect and Block Visitors based on Geolocation. | Shopify App Store
  2. MOD: GeoLocation Redirect

 

Reply 1 (1)

Small_Task_Help
Shopify Partner
909 31 83

Hi,

 

Geolocation API with JavaScript to Shopify theme (theme.liquid) may help

 

Example of javascript code

 

 

<script>
    // Replace with your chosen geolocation API endpoint and API key
    const geoApiUrl = 'https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY';

    fetch(geoApiUrl)
        .then(response => response.json())
        .then(data => {
            const userCountry = data.country_code2; // Get the country code from the response
            if (userCountry === 'AU') {
                window.location.href = 'https://www.yyyyy.com.au';
            } else if (userCountry === 'NZ') {
                window.location.href = 'https://www.yyyyy.com.nz';
            }
            // Add more conditions for other countries as needed
        })
        .catch(error => {
            console.error('Error fetching the geolocation data:', error);
        });
</script>

 

Hope this will help or if you still need help you can contact us 

To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad