I want to redirect to the store associated to the country where the user is browsing from in my shopify site, based on Slate (https://github.com/Shopify/slate).
Durring my research, I found a cookie named
_shopify_country which the value set to the country of the user, but I'm afraid to use this cookie since it is undocumented (https://www.google.com/search?q=shopify+_shopify_country).
I have two questions:
- Where is that
I've had a little look at a few Shopify sites, and can't find the
_shopify_country cookie. Seems is never set so I guess this is a custom modification to fetch it or possibly a deprecated function.
But if your goal is to determine what country the user is from, you can just submit an AJAX request to a GEOIP service. The API I tend to use for GEO lookups is https://www.geojs.io (https://www.geojs.io) which is a free non-authenticated GEO lookup,
Usually you would show a banner suggesting they change to their local site rather than redirecting youself though. For cases where they have a VPN/they are purchasing for someone abroad
Since AJAX requests are fired from the client, it will return his IP/Information from the example you can try these in your console.
fetch('https://canihazip.com/s') .then(response => response.text()) .then(body => alert(body))
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.