[How-to] Use Geotargeting to Display a Visitors Location on a Page

Hey @Rob , Just tried this out and as far as I can tell it should be working. Can you take a look and let me know what’s going wrong? I’m really trying to pre-populate zip code into a field but I can’t seem to get even the display text to work. http://specials.zendyhealth.com/test-bed/

Hi @Justin_Frech I had a look and there were some syntax errors in the code (a few stray < > and a couple of missing ‘$’). I’ve fixed those for you and saved and it appears to work in Preview. Have a look and if you’re happy you can republish the page.

1 Like

I just tested it and it thought I was 113 miles away, so maybe not for me :slight_smile:

ok, but there is any way to display a section (not just some small text) only to one country?


Is it possible to update a button with the user’s location?

For example, a button would read “Request a Demo in {cityText}”

Hi @mike22rtn This is an awesome suggestion! It should be possible with some tweaks to the code above to target a button label. It might be tricky to only swap a section of the label due to how the Unbounce builder generated buttons. It would be easier perhaps to use a text link and you can edit the source code directly in the builder and add some <span> tags to target specific text.

A sneaky little workaround to still have it look like a button would be to layer the text link over the button and remove the button’s actual label. To the visitor the text link would still look like the button label.

I’ll try and find some time to add this into the existing workaround in the near future as it shouldn’t be too difficult

1 Like

Hey @Rob - this is great!

Is there any way to use it to show specific fields? Use case example is GDPR consent check box for EU visitors.

Would love it if we can show/hide this field depending on where visitor is located.

Is there a way to make the “fallback” text say something other than “not found” in the event the script can’t find a city, region or country name?

whoa !

a big thanks for this big tips !!! :smiley:

I was using this feature successfully for the past couple months. Now my LPs are getting “Mixed Content” errors using this feature.


For what it’s worth, after testing 3 different providers, I’m using ipgeolocation.io, and they’re definitely the best. Everything is SSL

I can’t get this to work on an exit popup. I’m not sure why. Any suggestions?

Hi @Rob, thanks for the Geotargeting script- works great on my LP. I want to push the location into a hidden field so that I can collect that data upon lead submission.

Could you please break that down step by step, what do I name the hidden field, then where exactly do I add the: $("#city").val(city);

Thanks so much- I am learning a lot, but don’t know enough to get past step by step and copy and paste yet… :slight_smile:

Thank you,

Hi there! Did you get this to work for you?

I can send you the tweaked code if you need it.

Cheers! :rocket: