Shopify return the user’s location

Vince Nguyen
2 min readNov 6, 2020

You are having a lot of sites, and each site for each country? And you want to redirect the user to correspond store based on their country?

In fact, there are some apps in the Shopify market, some of them are free, some of them are paid. For example

FREE APPS

PAID APPS

https://apps.shopify.com/cozy-country-redirect?

More and more in the market, but do you need all the functions in these apps? Also, it is worth to pay for this monthly? For 1 month is acceptable, but what if in 2,3…years?

Also, you can do it without an app by using this service: http://www.geoplugin.net/javascript.gp, like this:

<script language=”JavaScript” src=”http://www.geoplugin.net/javascript.gp" type=”text/javascript”></script>

<script>

if(geoplugin_countryCode() != ‘US’){

if(geoplugin_countryCode() == ‘CA’){

location.href = “//www.domain.ca";

}else{

location.href = “//www.domain.com";

}

}

</script>

But the problem here is that all most of them will need to connect to a third party. So surely that it will be slow down the speed on your site, Google will detect it as a minus point to reduce your site’s score.

So is there any native solution from Shopify? Lucky that we have. Recently Shopify already added the user’s location and return in the cookie of the browser. You can see the location here: https://www.shopify.com/legal/cookies, search with _shopify_country

Here is 1 of my example store

Shopify’s location variant

So you can totally use it to detect their location and implement these solutions:

  • Redirect the customer based on their locations
  • Show/Hide something based on their locations (for example landing pages, Free shipping rules,…)
  • and more…

That’s so interesting.

In the next article, I will guide you on how to use this variant to redirect the user based on their location.

Thank you and enjoy it!

--

--

Vince Nguyen

Shopify & Shopify Plus solutions — We help independent businesses overcome their capacity and capability challenges. Contact me at: vince@hamsa.co