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
551 17 39

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 

Click here to Contact and Get Shopify Store Help
E-mail - hi@ecommercesmalltask.com
We are Shopify Experts in India
Google My Business - Ecommerce Small Task