Geo Dynamic Content

A client of mine has requested some minor geo specific-content. They want their testimonials to change from “Join teachers across Australia”, to “Join teachers across America”, dependant on where the visitor is viewing the page from.

Has anyone here achieved anything similar before?

I am trying to avoid using a service like Geotargetly, as their pricing structure does not make sense for a single client and a small change.

Cheers!

Sam


Hello Sam, I hope everything is good!

Yes it is possible using custom code, you can use Free Geo IP (https://freegeoip.app/) is free up to 15,000 requests per hour, so I think in this case is more than enough!

Here’s the code:

HTML:

<span> Join teachers across <span id="AU">Australia</span><span id="US">America</span><span id="fallBack"> (Fallback Text)</span></span>

The fallback text is in case someone doesn’t come from that country. Otherwise, it won’t display any text.

CSS:

#AU { display:none;} #US { display:none;} #fallBack { display:none;}

jQuery:

$.get("http://freegeoip.app/json/", function (response) {
    var country = response.country_code;
    if(country == 'US' || country == 'AU') {
    document.getElementById(country).style.display = "inline-block"
    } else {
    	document.getElementById('fallBack').style.display = "inline-block"
    }; 
}, "jsonp");

And don’t forget to call jQuery!

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

Hope this can help you! If you have any doubt I’m here!

Joaquin

FYI: jQuery is already loaded by Webflow. No need to load it again.

1 Like

Oh great, I didn’t know that. Thanks!