Jump to content

How should geo-targeted content be handled?


Boost
 Share

Recommended Posts

Sure, just copy and paste this to your site

$http = new WireHttp();

$region = $http->getJson("http://ip-api.com/json/{$session->getIP()}?fields=city,countryCode");

user()->setLanguage($region['countryCode']); //well… it’s not *this* easy. you’ll have to connect your languages to ISO 3166-1 alpha-2 country codes somehow

echo '<marquee><blink>' . sprintf(__('Hot milfs looking to hook up in %s!'), $region['city']) . '</blink></marquee>';

 

  • Haha 4
Link to comment
Share on other sites

Thanks, but I'm not sure if that covers the case.

I believe that showing, say, a different homepage for US users should be simple, right? But what about displaying different content? I mean, the “page” remains the same; what changes, for example, is a paragraph or text on that page. Is that a possibility?

Link to comment
Share on other sites

Well, it’s kind of a broad question. If you’re talking about having different language versions of your pages, ProcessWire comes with built-in support for managing that content. You’ll have to figure out whom to show which language content yourself, though, for example by using the Accept-Language header.

If you only need region-specific content and no multi-language, you could abuse ProcessWire’s language system for that, too. If you need both dimensions, you’ll have to figure out how to manage all that content. Do you need everything for every region and language, or maybe just a sprinkle here and there such as “this site is not available in your country thanks to the S. Fischer Verlag GmbH”?

I guess the answer is, it’s up to you? ProcessWire doesn’t have a built-in feature that lets you connect content to predefined regions or detects users’ regions for you, but you’ll want to decide these things for yourself anyway. My example used an external service that looks up IP adresses. There are drawbacks to that technique that you may not want. Other options include just asking the user or using the browser’s geolocation API (AFAIK this will only give you coordinates, so again you’ll need to use a service to get the “region”, or calculate it yourself if you’re into geomatics).

  • Like 2
Link to comment
Share on other sites

I think in pages that need this paragraph changes you can use different fields for each region, and render the field according to the current region. Ex. body_america, body_europe, etc. You can create a function that determines to which region it belongs according to the country. If you have a license for ProFields you can use Textareas field type to handle that more easily.

Pseudo code:

$http = new WireHttp();
$country = $http->getJson("http://ip-api.com/json/{$session->getIP()}?fields=countryCode");
$region = getRegion($country);

echo $page->body_$region;

function getRegion($country) {
  // Set a default $output (europe)
  // Using an in_array, switch, etc. find the current related region to override it (america, asia, africa, etc.)
 return $output;
}

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...