Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can I automatically display which countries my readers are from? If so, how would this be accomplished?

share|improve this question
Why is this a WordPress question? Oh, and welcome to WordPress Stack Exchange! – toscho Mar 22 '12 at 10:49

closed as off topic by toscho Feb 17 at 22:44

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

Yes but it can be very expensive, error prone, and unreliable, with false positives

  • IP based geolocation

    Can be done, but isn't reliable. Sometimes users will be running via a proxy or ISPs appear to be from the wrong country. E.g. AOL dialup users in the UK for a long time showed on most databases as coming from somewhere in the US. It's also trivial to get around this with SSH tunnels, proxy sites, or a VPN/VPS

  • Registering various domains for different countries

    This relies on the end users sense of correctness. There's nothing stopping them going to example.fr instead of example.co.uk, sure the details may be different but it still works

  • Sniffing user agents or the language via javascript

    This is bad practice, it could be done, but, all a user has to do is change their regional settings. Privacy modes of browsers may strip this data, and some clients may not send it at all.

  • Credit card details

    The most secure and reliable, but also very intrusive, and adds in the complication of data protection laws.

  • Google Analytics

    You can track where your users come from this way using the API, however, this will tell you about the people who have already visited, not the person currently browsing the page. I cannot offer any code examples on how this would be done, but I am aware the data is available.

If you need to restrict access to a form or product, just make it clear that it's only available in countries X Y and Z. The customer can ignore it and then find themselves stuck halfway through a form anyway as they don't have a British credit card to pay with or a US social security number, after all they knew full well they were in the wrong country to begin with.

If you're doing it as a purely visual exercise then the google analytics route is the way to go. You can either use the APIs or export the CSV from the relevant page and process it.

share|improve this answer

Yes and no. Your best bet is to get the readers country by their IP. To do this you'll need to use something like php-ip-2-country. Then store the results into a table then loop though to display them. Keeping in mind that people could always be spoofing their IP.

Depending on your needs you could also use something like maploco which is a hosted map service that shows your visitors location.

EDIT There are also have many plugins that do this for you.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.