dimanche 28 décembre 2014

How To Redirect Traffic Based On Country Using Maxmind Geoip2 Javascript


Vote count:

0




I bought Maxmind GeoIP2 a while and I want to do a simple redirect based on Countries but it seems there's no clear answer how to do it even in their website. I am not good in coding but I'm trying to understand how it works...


For example my website is google.com and I want to redirect some countries to yahoo.com, I came up with this code but it redirects everyone to yahoo.com. Can anyone help me or reconstruct this script to make it work for its purpose? Thanks a lot..





<script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"></script>
<script language="JavaScript">
var user_country = geoip2.country(
function (response) {
if (response.country.iso_code === "FR"){window.location = "http://yahoo.com"}
else {window.location = "http://google.com"}
if (response.country.iso_code === "BE"){window.location = "http://yahoo.com"}
else {window.location = "http://google.com"}
if (response.country.iso_code === "PH"){window.location = "http://yahoo.com"}
else {window.location = "http://google.com"}

},
function (error) {
// handle error
}
);
</script>




asked 41 secs ago







How To Redirect Traffic Based On Country Using Maxmind Geoip2 Javascript

Aucun commentaire:

Enregistrer un commentaire