How to get the visitors geo data or IP adress

In order to retrieve the visitors IP adress or geo data, just use this simple snippet:

sitegainer.getGeo([key]);
/*Like this*/
sitegainer.getGeo('query'); // Gives the IP adress
sitegainer.getGeo('country'); // Gives the country
/*
Examples:
as:"AS2119 Telenor Norge AS" 
city:"Stockholm"
country:"Sweden"
countryCode:"US"
isp:"Bredbandsbolaget AB"
lat:59.3333
lon:18.05
org:"Bredbandsbolaget AB"
query:"213.115.103.83"
region:"AB"
regionName:"Stockholm"
status:"success"
timezone:"Europe/Stockholm"
zip:"173 11"
*/

Notice: If you are trying to reach the sitegainer api before document ready, make sure you check that it exists. You can do this by using intervals:

var myInt = setInterval(function() {
   if(typeof sitegainer !== 'undefined') {
      console.log(sitegainer);
      clearInterval(myInt); 
   }
});