Last active
May 5, 2020 09:10
-
-
Save alewolf/275278f1da379b56512d to your computer and use it in GitHub Desktop.
MaxMind GeoIP city locator for unbounce forms
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 type="text/javascript"> | |
$( window ).load(function(){ | |
$.getScript("//geoip-js.com/js/apis/geoip2/v2.1/geoip2.js", function() { | |
var onSuccess = function(geoipResponse) { | |
// change '#lp-pom-form-64 #city' to match your form ID and field name | |
$('#lp-pom-form-64 #city')[0].value = geoipResponse.city.names.en; | |
}; | |
var onError = function(error) { | |
// do nothing | |
}; | |
geoip2.city(onSuccess, onError); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the country lookup this code works great, customized for my form ID of course. I used "country1" for the field name in Unbounce because I had a conflict with another application running on the site. Most will want to use just a new hidden form value of country.