Have a page set up to redirect users to certain pages based on their geo location. Works fine in preview mode but on the published website it redirects everyone to the same page. I’ve tested this with VPN and it redirects everyone to the same page. Help please!
Hi there …
After getting the JSON from the 3rd party service, you need to check the country code against an array of blocked countries, then redierct them back, we’ll log the answers so you can check them out in the site’s monitoring tools.
// Assuming we have the JSON response
const blocked = ['US', 'AU', 'GB', 'EU']; // Array of blocked country codes
const loc = json.countryCode; // The location of the visitor
// Log the location to the console - for reference
console.into(`Visitor country code is: ${loc}.`)
if (blocked.indexOf(loc) > -1) {
wixLocation.to('/not-available');
} else {
wixLocation.to('purcahse');
}
You should read the 6th line among the logs in the monitoring tools log, this code is much simpler, shorter, easier to understand and easier to debug.
Hope this helps~!
Ahmad