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



Show first post

86 replies

Hey Rob, Actually after updating to the new URL, script stopped working. I found out that my issue was the Wifi I was using prior, and not the URL. Do your own investigation, but I believe the old URL works fine.

Hi,

Is there a way to use Google Ads’ {loc_physical_ms} instead?

I understand the location ID would somehow need to be “translated” into an actual location name but not sure how to implement this.

Cheers

Hi @Rob ,

Thanks but unfortunately neither scripts work for me (Maxmind and Geolocation DB).

I know I’m late on the thread but could you please kindly assist?

Cheers

Userlevel 6

Hi @Michael_Granger I think the issue may been due to me updating the URL in the script which I believe may have broken the functionality. I’ve swapped it back to the previous URL and that should fix the issue.

The URL to use in the script is “https://geoip-db.com/jsonp/

So the (first three lines of the) code would look like:

 $.ajax({
    url: "https://geoip-db.com/jsonp/",
    jsonpCallback: "callback",

Let me know if that fixes it for ya!

Hi Rob,

Thanks a lot for assisting, it now works!

Is there any way to show a default text in lieu of “Not Found”?

Thanks again.

Cheers,

Mike

Userlevel 6

Good question Michael! To show some default text in the event that a location isn’t returned in the response you could use an “if” statement placed after the variables are set from the response from GeoLocation DB. So for example:

if (!city || city==“Not Found”) {
$("#cityField").val(“default text”);
}

The above code says if there is no value for city (!city) OR if the value for city is “Not Found” then display “default text” in the city form field.

You can add this immediately after the code setting the variables like so:

  var country = location.country_name;
  var state = location.state;
  var city = location.city;

if (!city || city==“Not Found”) {
$("#cityField").val(“default text”);
}

One thing to note is that this would need to be done for each field separately. Also the “Not Found” is case sensitive so you’d want to make sure that matches the exact not found message returned by Geolocation DB.

Hope this helps!

Hi Rob, I am having trouble using the geotargeting on my landing page. I copied the script provided and made all the necessary changes. It still doesn’t work. Wondering if you could help. Thanks!!

Hi, Rob Could you provide a code that would mark a radius on the map around the mapped city.

Thanks

Has this stopped working? It was working for me before but now defaults to placeholder text. The sample links in the original post don’t seem to work for me either.

Userlevel 6

Hi Scott! I just had a look and the code will still work. However it looks like Geolocation DB now requires a free signup in order to use their service and make requests via their API.

Signing up for a free account will get you an API key and a new URL to use when making a request to the API. After signing up all you need to do is paste in that new URL with the API key in the code and replace the URL in

url: "https://geoip-db.com/jsonp/"

Once that new URL is added everything should work as before 🙂

Userlevel 1
Badge

Thank you for this!

Reply