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



Show first post

86 replies

Userlevel 6

@Akkysia great questions! This can be a little bit tricky if you’re not familiar with javascript, but you’ll want to place both the map and prefill snippets at the end of the function but not outside of the closing brackets });

Here’s a screenshot of what it looks like on the example page. You can see that the prefill and map snippets are near the bottom but still inside that function that’s pulling in the location from GeoIP-DB

Hope this helps!

Hi Rob - Thanks for sharing this script. Just installed and it’s working great.

Two quick questions if you’re ok to answer that would be awesome:

  1. Where exactly would I “paste the following code into the script”? This is in reference to the “Add a Google Map…”

  2. Likewise where exactly would I add the “Prefill Form Fields…” script.

I’ve got it to work (basic geo script) so thanks! But, I’m not a coder so dunno how to merge the other two scripts you’ve kindly provided.

Thanks a bunch!

Eddie

Can you share the code you are using for this?

Did you ever figure this one out? I am looking to do the same thing…

Userlevel 6

Hey @justinoon! The code could potentially work with https://ipgeolocation.io/ but will require a bit of work. You’ll need to change the value of the “url” field in the ajax request to be the endpoint for https://ipgeolocation.io/

url: "URL FROM IP GEO LOCATION",

You’ll also want to review how the data being returned from IP Geo Location is named and formatted. I’ve had a quick look at their docs and the data is formatted as JSON which is good. You will need to make some small edits though based on the naming conventions. For example location.state would need to be changed to location.state_prov.

It does look like the naming conventions are very similar though so I don’t think there will be any huge updates to the code required. One thing I did notice though is that to authorize with https://ipgeolocation.io/ you’ll either need to use an API key (which this script does not have built in) or use a specific request origin (ie. domain). In order to get it working with the script here I’d recommend going with the request origin option.

Hope this helps a bit, let me know if you have any follow up Qs 🙂

can anyone let me know if the code above works for ipgeolocation.io? or must I write an extra line or change something for it to work

Hi @Stefano,

Nope but it could be the proxy that maybe causing this issue. Just a speculation. Can this script work with other API services? for example from ipgeolocation.io.

I mean technically the script should work the same with what ever API url and the only thing that needs to change is the ajax script on top right? 😁

Userlevel 7
Badge +4

Hi there!

Is your colleague on a VPN or using an adblocker?

Hi Stefano,

This is completely unrelated but after testing the API using postman, I can see that the data is showing on my landing page…but I am not able to produce the same results for my colleague in Thailand. Would you mind taking a look? the webpage is http://lp.storehub.com/tqpage-test/

Their ip address is [96.30.104.13]

Thank you 😁

Userlevel 7
Badge +4

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

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

Cheers! 🚀

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… 🙂

Thank you,
Ed

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

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 was using this feature successfully for the past couple months. Now my LPs are getting “Mixed Content” errors using this feature.

https://quote.hometownheatingandair.com/furnace-repair/a.html

whoa !

a big thanks for this big tips !!! 😃

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?

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.

Userlevel 6

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

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

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

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

thanks

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

Userlevel 6

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.

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/

Thank you @Rob

Userlevel 6

Hi @EthosData! You’d need to write some more code to conditionally display the phone number based on the country. Something like this might work:

if (country == “name of country”) {
// display phone number
} else if (country == “name of other country”) {
// display different phone number
}

The above is just some psuedo code to get you started. You’ll need to target the html that is displaying the phone number and change the content with javascript.

Hope this helps!

Reply