How to increase conversions automatically serving the right content to the right audience with geo targeting


Published on

While working with Flexitol / Dermal Therapy, a leading skin care Australian brand, we realised we needed a better way to showcase different product offerings depending on the country the visitor was from. Originally, the user would visit different LTD’s (domain extensions eg: .com,, to go directly to the content they were after – but when searching in google, they could end up visiting a product that was indeed not available in their country of origin.

This will increase conversions, as you are actually showing content that is specifically aimed at that audience.

The technical bit.

Let us show you how we use a free API ( *free for 10k requests a month) and basic PHP to make our website ready to serve different content for audiences from different countries (and even cities if we want to…)

So the first step for us would be getting the users IP address.

To accomplish that we are using something along the lines like this.

// or for more advanced users


After we do that, we are going to send an API request with PHP’s file content function to which kinda looks like this.

$geo = json_decode(file_get_contents("" . $ip . "?access_key=" . $IPStack_apiKey . "&format=1"));
$country = $geo->country_name;

The geo variable contains the IP stack Response and looks like this.

  "continent_name":"North America",
  "country_name":"United States",
    "capital":"Washington D.C.",
    "country_flag_emoji_unicode":"U+1F1FA U+1F1F8",

Quite a nice set of information for a free API. Like mentioned before, the first 10k requests are for free which will never get expired by most small business websites but the fact that you can even serve different content to different Post Codes makes it extremely powerful.

If you have a website with a lot of traffic have a look at the pricing table

So, that gives us the User location. All that’s left to do is serve the right content.

For that reason, all we basically did is set a variable in PHP that looks like this.

if ($country == "united States" ){
   $_SESSION["SESScountry"] = 'United States';
   setcookie('SESScountry', 'United States');
   include 'states.tpl.php';
if ($country == 'Australia') {
   $_SESSION["SESScountry"] = 'United States';
   setcookie('SESScountry', 'United States');
   include 'australia.tpl.php';

And that’s it.

Multi-location content enabled website in less than 20 lines of PHP code.

Worth to mention on that point here is the Session and Cookie settings for PHP.

Of course, we don’t want our user to hit the API on every single request they are making so we set a cookie and a session when they first hit our website and all subsequent requests get’s served based on their cookie value. This not only increases the usability of our API service, even more, it also gives us the capability of user grouping, retention etc.

The possibilities are huge.

If you are using Drupal 7, Note that the cookies need to have the SESS letters followed by lowercase letters, otherwise the varnish cache will stripe them out and gives you not the desired result.




Book a free consultation to discuss your next project


We’ll discuss your goals and share our insights and expertise on your project design, helping you with scoping, implementation or innovating your digital services.