How to push the visitor country from the Analytics cookie to an Unbounce form?


Hi there,

I’d like to have the country a visitor is in pushed into a form (when the visitor submits a form on my landing-page powered by Unbounce).

Thus my questions is the followin: How to push the visitor country from the Analytics cookie to an Unbounce form? Any idea?

Thanks,

Adrien O’Leary


10 replies

Hey Adrien! Did you want to default a list of countries that the user can select from, or do you just want to push the country into a hidden form field?

Besides using values from an analytics system, you can also use the Maxmind GeoIP database. There’s an example over on this thread.

Fire a little more information our way and we’ll see if we can get you sorted out…

Hi Carl, I don’t want to get the visitor to tell me where she is. I want Unbounce to push the location - based on the IP - to be pushed into an hidden field when a visitor submits a form. Do you think that I could use the script you mention on https://getsatisfaction.com/unbounce/… to do the trick?

Thanks!

Yup! Actually, I couldn’t resist just whipping this one up. It’s really easy. Just add a hidden field to your Unbounce form named ‘country’, then in the Unbounce “Scripts” tool, add the following script to your page:

<script src="http://j.maxmind.com/app/country.js" charset="ISO-8859-1" type="text/javascript"> <br /> </script>   
<script type="text/javascript"> <br /> $(document).ready(function(){ <br />
$('#country').val(geoip_country_code()); <br /> }); <br /> </script>   

Et, voila! You should get the two-character country code along with each of your form submissions.

OMG. You make my day!

P.S : Please talk to Louise to make sure that she gets the answer you just gave me… as she initially couldn’t send me in the right direction. Thanks!

Hey Adrien, happy to help! Given that this one required custom scripting, it’s a tough one for our Success Team to handle. But I’ll definitely pass this one along to Louise and the rest of the team for next time. Good luck with your campaign!

The link to that script  doesn’t work anymore. Is there an updated link?

Hi Sidney - Which link are you referring to? I don’t see a link in Carl’s response that you commented on. 

Hey Justin,

I was referring to this. Cannot load the script

Hey there, it seems MaxMind has stopped offering their free product, so this solution will no longer work.  They do have an updated and reasonably priced offering though:  https://www.maxmind.com/en/geoip2-precision-country-service

Thanks, Carl! I’ll look into that.

Reply