Geo-Customizing
Customize your content based on the visitor's location
What is Geo-Customizing ?
Geo-customizing is a tool provided with your Web-Stat account that allows you to automatically adapt and customize your web site's content to a visitor's geographical location ; there are many reasons why you might want to do this:
Prevent SPAM
Show a GDPR compliance message to EU visitors and EU visitors only
Target the products you present to your audience
Customize the banners you display on your site so that they are only shown to visitors from certain states or countries
Block people outside of your sales area from accessing your site (to cut down on useless support request for instance)
The list is long so we'll stop right here!
Here is what one of our clients had to say about Web-Stat Geo-customizing:
Thanks for your help on this. With the script you supplied I was able simply block the countries that I did not want to access my site. Since my site deals with camping and PopUp Campers, I blocked all countries that would not deal in those activities. I put up a nice screen that simply said “you can not access this site from your location”. This has blocked 90% of the spammer.
S.J.HaennPopUpPortal.com
And here is what another client says on her own site
What are the requirements ?
In order to use Geo-customizing, four conditions must be met :
You need to have a Premium account ; if necessary you can upgrade here.
Your site must accept JavaScript. This is pretty much standard but some blogs or social network sites may not allow this language to be used. Note that Wix sites do not accept JavaScript: as a result geo-customizing can not be used on them.
You must know basic JavaScript. No fancy skills are necessary, but a minimum of JavaScript knowledge is needed.
You need to use the tool on your own site. Geo-customizing for your account will only work for the URL that you entered in the Settings.
How do I implement Geo-customizing ?
Once these conditions are met you can start geo-customizing your content. The first thing to do is add a small piece of JavaScript code inside your HTML <head> area:
The script above will create a JavaScript array variable named geo. That array will contain the following data which can then be accessed with JavaScript anywhere on your page to display the appropriate content.
The geo array variable contains 10 elements :
- geo[0]: 2-letter country code - example: US (see list here)
- geo[1]: country name - example: United States
- geo[2]: 2-letter region/state code - example: SC
- geo[3]: region/state name - example: South Carolina
- geo[4]: city name - example: Charleston
- geo[5]: zip code - example: 29200
- geo[6]: latitude - example: 32.8255
- geo[7]: longitude - example: -79.968
- geo[8]: name of organization owning the IP# - example: AT&T
- geo[9]: IP of visitor - example: 74.244.143.12
- geo[10]: IP name if available - example: adsl-065-013-032-075.sip.mia.bellsouth.net (*) see note below
- geo[11]: the referrer's URL if any - example: http://www.yahoo.com
- geo[12]: UNIX timestamp of previous visit by this visitor
- geo[13]: number of visits by this visitor
- geo[14]: whether the visitor is connecting from the EU: 1 if he is, 0 if he is not
You can then use these elements in JavaScript to display customized content.
Important! When using Geo-Customizing you need to remember that the geographic information we use is derived from IP addresses. While we do everything to make it as precise and complete as possible, we can not, for technical reasons, have a 100% accuracy rate, so it is possible for the data contained in the geo array to sometimes be incomplete or inaccurate. You need to plan for that possibility in your application.
Example 1
Imagine that you have two banner ads : one for California (banner_ca.gif) and one for Texas (banner_tx.gif). You want to display the Texas banner to visitors from Texas, the California banner to visitors from California, a generic banner (banner_generic.gif) to anyone else in the US and nothing at all for people who are not in the US. Here would be the code to add to your page at the place where you want the banner to appear :
<script> var geo = disp(); if (geo[0] == 'US'){ if (geo[2] == 'CA'){ document.write('<a href="https://site1.com"><img src="/banner_ca.gif"></a>'); } else if (geo[2] == 'TX'){ document.write('<a href="https://site2.com"><img src="/banner_tx.gif"></a>'); } else { document.write('<a href="https://site3.com"><img src="/banner_generic.gif"></a>'); } } </script>
Example 2
You want your site to be accessible only from the US, Canada and the UK. You don't sell in other countries and you don't want people to write to support asking for your product when you can not fullfill their orders
<script> var geo = disp(); if (geo[0] != 'US' && geo[0] != 'CA' && geo[0] != 'GB'){ alert('Sorry this site is only accessible from the USA, Canada and Great Britain'); window.location = 'https://www.wikipedia.com'; } </script>
Example 3
Display a message to all EU visitors to inform them of your use of cookies and/or the collection of IP addresses
Note: to prevent this message from being shown multiple times to the same visitor we are writing a cookie when first shown, then reading the cookie when the user comes back. If the cookie is set we do not show the message again.
(...) <div id="my_gdpr_info_message">Insert here the message you wish to display to your visitors. This section goes anywhere you wish on your page</div> (...) <script> var geo = disp(); if (geo[14] && ! getCookie("gdpr_info_message_shown")){ document.getElementById("my_gdpr_info_message").style.display="block"; document.cookie = "gdpr_info_message_shown=1; expires=Thu, 18 Dec 2113 12:00:00 UTC"; } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(";"); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } </script>