title: How To Redirect Traffic Based On Country Using Maxmind Geoip2 Javascript
body: <p>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...</p>
  
  <p>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..</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script language="JavaScript"&gt;
  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
      }
  );
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>