Hello Everyone…
I’m using the following approach to redirect my e-store visitors based on the country they are browsing from. It is working fine, however, the issue is, the full page has to be loaded first before the redirection kicks in. Which is not so good experience for the visitors. I’m trying to find a method to do the redirection before the page gets loaded.
I would appreciate any suggestions and recommendations on this regard.
P.S. I was exploring the “Wix .Router” function, however, it seems it would work well with a prefix only.
=========================================================
-
I created two separate e-stores (for two different countries).
-
The first e-store is created under the subdomain “country1 . mymaindomain . com”. It has the same products but with different prices. Sometimes, it has different promotions as well.
-
The second e-store is created under the subdomain “country2 . mymaindomain . com”. It has the same products but with different prices. Sometimes, it has different promotions as well.
-
I created a Landing-Page with my logo and a welcome message. My main domain is linked to this Landing-Page. So, when people from any country type “mymaindomain . com” they will be directed by DNS to my Landing-Page.
-
Then, I used the following code in the Landing-Page “masterPage . js” section to automatically identify the location where the visitors are coming from and redirect them to the correct website accordingly.
// The code in this file will load on every page of your site
import wixLocation from 'wix-location';
import {fetch} from 'wix-fetch';
$w.onReady(function () {
// Fetch the user's location details
fetch('https://extreme-ip-lookup. com/json', {
method: 'get'
})
// Check if the request was successful
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
})
.then((json) => {
// Set the user's countryCode as a const
const loc = json . countryCode;
// Check if location is from country1
//You have to replace "country1 with the (Internet country domains list (TLDs)) for country country1
if(loc === "country1" ){
// Redirect to WebSite1
wixLocation . to ("https://country1 . mymaindomain . com");
}
// Check if location is from country2
//You have to replace "country2 with the (Internet country domains list (TLDs)) for country country2
if(loc === "country2" ){
// Redirect to WebSite2
wixLocation . to ("https://country1 . mymaindomain . com");
}
});
});
=========================================================