by Brett Andrew, Enterprise Architect 2023 (c)
So this has come up on a few projects over my lifetime, user browser language vs geo location, which one do you use?
This is a hugely debatable topic and I've spent countless hours discussing it, so here is a decades worth of learning in one page.
The problem? You want to display the right language to the user OR you want to make sure users in a specific country see website content or not.
If you are marketing to multiple counties then keep reading!
If all your users are only in one country and you are looking to target specific states or cities, then this page probably won't have what you are looking for and you should go straight to GEO locating for users. Use a 3rd party service like https://ip-api.com/ or https://www.iplocation.net/ to get the users city / state data if available.
For those marketing in different countries, the rest of this article is just for you, especially if you are targeting different languages for a user like English, German, Japanese and Spanish.
How do you know what language your user speaks? Well the good thing is that through javascript you can get the language setting directly from the users browser.
//this script ran when you opened this page, press f12 and view your console results
var userLang = navigator.language || navigator.userLanguage;
console.log("---------The browser language is: " + userLang);
But this is where the problem also starts. You see in most countries, users are selecting their default country for devices and this is coming through to the browsers they are using.
We looked at a random sample of over 164,000+ web visits and compared the google specified country (which tracks users by geo location) and compared with the users browser language setting.
Australia
In Australia for example 74.4% have their language set to en-au.
The rest was made up of
en-us 9.7% en-au 74.4% en-gb 13.0% en-nz 0.3% en-ca 0.2% de-de 0.2% es-us 0.0% zh-cn 0.3% en-in 0.2% en 0.5%
So this is pretty good, using the browsers language, you are 74.4% likely to target Australians. Now why would people have en-us or en-gb? Well perhaps they are originally from these countries and have relocated, others could be on holidays and others could just be older browsers not using the device or OS setting.
United States
The USA has a whopping 90.1% of match from USA to the language browser setting en-us.
What were the other values? en-au 0.70% en-gb 1.10% en-nz 0.10% en-ca 0.30% de-de 0.00% es-us 4.20% zh-cn 0.20% en-in 0.10% en 0.40% vi-vn 0.30% ja 0.00% fr-fr 0.00%
Those who haven't set their language to en-us are most likely travellers or people who originated from another country (and took their device with them).
New Zealand
It is not the same story for New Zealand and we don't know why! Perhaps being so used to never seeing NZ in the list of countries to pick from their is a habit of picking USA or Australia or England!
New Zealand (en-nz ) only matched 54.2%, so over half, which is good but still not a great match!
The rest of the traffic had these values
en-us 15.40% en-au 11.50% en-gb 17.70% en-ca 0.30% de-de 0.50% es-us 0.00% zh-cn 0.40% en-in 0.30% en 0.20% vi-vn 0.10% ja 0.10% fr-fr 0.20%
What about other countries?
Canada (en-ca) had a 70.4 % result of users matching the Geo location.
United Kingdom (en-gb) had a 90.2 % result of users matching the Geo location.
Fiji (en-fj) had a 0% match to en-fj (with the majority being en-us 32.3% en-au 21.8% en-gb 25.5% en-nz 11.5%)
Germany (de-de) had a 65.1 % result of users matching the Geo location.
India (en-in) had a 25.5 % result of users matching the Geo location.
Conclusion
Our sites default to the language the users browser specifies, but always give them the ability to change their language and then remember this setting for next time they return.
The language setting although sometimes accurate, can also be amiss. In our example if a user from New Zealand landed on the website with a browser language of en-us and it was readable, they may never change their language and so they might miss out on deals setup for travellers from New Zealand.
So just use geolocation all the time right? Nooooooo way! Why though?
Example 1
If a person was travelling from Japan and arrives in Australia for work and visits a webpage anywhere in the world and it is in English, they might not know how to read it or change the language setting.
Example 2
If a person was travelling from America and arrives in Germany for a holiday and visits a webpage anywhere in the world and it is in German, they might not know how to read it or change the language setting.
So, even if we know they are in another country and their geo location conflicts with this language, we have to respect the users language setting on their browser first and foremost.
What you can do however is to use logic to look for signs that perhaps this user is in a different country and provide suggestions through the UI to them.
e.g. If Browser Language =='en-us' but country (which you have to fetch via a 3rd party) = 'New Zealand')
Then a subtle page alert to ask user if they would like to see the New Zealand version of the website could be the answer.
Obviously coming up with the matrix that determines when this should appear or not is a pretty big project on its own, so you might want to create a table so you can add / remove these alerts dynamically for your project.
Being Realistic
In most cases I have worked on, due to costs and complexities, most projects I have worked on have just relied on the users browser language setting for setting the page language.
If my clients had an unlimited budget, they would probably elect for a combination approach I recommend, we will certainly be implementing some form of this into our mition portal, so if we do come up with a neat API solution that returns
browser language, actual country, suggest change language (y/n)
then we will post about it here.
Powered by mition