Last active
October 10, 2018 23:57
-
-
Save brandonsheppard/126879c6540438d64e0b to your computer and use it in GitHub Desktop.
Query the location of a customer with MaxMind and produce a popup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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