It is no big secret, but often visitors like it when they see a connection to their geographic location. Be it that the vendor they eventually deal with is local or that something else shows strong ties to the local town or city. These could be reviews or product recommendations from users of the same town or city. Imagine you visit a website and you are greeted with a personalized message mentioning your location.
“This offer is only valid for users in the <your town, state> area until midnight tomorrow.”
In the old days you had to install some geo-targeting scripts and database, but there is an easier way now (well, now … I don’t know since when it is available, but it is fairly new I think). Google as part of their API access for developers offers some JavaScript code that will use their technology to do the same thing. Here is the code that you would need to embed in your webpage where you want the city name and state abbreviation to appear. Here is the result if the code is used:
<script type="text/javascript"src="http://www.google.com/jsapi"></script><script type="text/javascript">if (typeof(google.loader.ClientLocation.address.city) != null) {document.write(google.loader.ClientLocation.address.city+", "+google.loader.ClientLocation.address.region);} else {document.write("Unknown location")}</script>
Now let’s look at the above example again and this time I am embeding the JavaScript code.
“This offer is only valid for users in the area until midnight tomorrow.”
PS: It really sucks how difficult it is to display code samples within a Wordpress blog posting.
Related posts: