Skip to content

Instantly share code, notes, and snippets.

@brandonsheppard
Last active October 10, 2018 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonsheppard/126879c6540438d64e0b to your computer and use it in GitHub Desktop.
Save brandonsheppard/126879c6540438d64e0b to your computer and use it in GitHub Desktop.
Query the location of a customer with MaxMind and produce a popup
// If country is AU, do nothing.
// If country is NZ, a NZ-specific pop-up
// If any other country (not AU or NZ), a generic international pop-up
var nzPopup = function() {
// Code to pop up the NZ popup
};
var internationalPopup = function() {
// Code for everyone else
};
var queryCountry = (function() {
var onSuccess = function(geoipResponse) {
var country = geoipResponse.country.iso_code
if(country != 'AU' && country != 'NZ') {
internationalPopup();
}
if(country == 'NZ') {
nzPopup();
}
};
var onError = function(error) {
var country = none
};
return function() {
geoip2.country(onSuccess, onError);
};
}());
queryCountry();
<script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment