GeoDirection is a free service that dynamically redirects internet users based on their geographic location. This JavaScript redirection tool is ideal for internet users that wish to redirect browsers based on their City, Region or Country, using Geobytes’ IP Address map technology. Further, it can also be used via the provided Geobytes’ JavaScript Variables to insert localized geographic content into a web page or JavaScript. Note: There is no need to install any special software on your web server.
Sample Redirection Script:
<script src="http://gd.geobytes.com/gd?pages=geobyteslocationcode&ext=html&after=5" language="Javascript"></script>
Sample Content Localization Script:
<script src="”http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity”" language="”Javascript”"></script><script language="”Javascript”"> document.write(“ Welcome to visitors from “+sGeobytesCity+”, “+sGeobytesCountry); </script>
Parameters:
pages:Specifies the page that a person will be re-directed to based on their location. For example: geobyteslocationcode would re-direct visitors from the city of geobytescity to a page called geobyteslocationcode.html, geobytesinternetgeobytescode would re-direct visitors from the geobytesregion region to a page called geobytesinternetgeobytescode.html, while geobytesinternet would re-direct visitors from the country of geobytescountry to a page called geobytesinternet.html. Note: The order of precedence is city, region, country, meaning a city match overrides region, and a region match overrides country. (Alternatively, you can also direct to any specific url – click here to see the sample below.)
ext:Specifies the file extension of the page you wish to re-direct to. The default is html.
after:Specifies how long to wait before re-directing the user. Default is 0 seconds (do not wait).-1= Do not re-direct (allows you to perform your own re-direct to any page, see example)
targetpage: Sets the target page that the user will be re-directed to. The default is to re-direct the user to a page of the same name as the matching location code in the “pages” parameter. see example
-r (radius):When following a city location code, cause the script to include all surrounding cities out to the given distance. see example
variables:Specifies the variable(s) to be initialized for use in later scripts on the page. For a complete reference of the available Geobytes’ JavaScript variables see Geobytes’ JavaScript variables.
Quick example:variables=GeobytesCountry,GeobytesCity would initialize the sGeobytesCountry and the sGeobytesCity JavaScript variablesfor later use.
Examples:
Code example using the Geobytes’ JavaScript variables to redirect visitors from a given Country, Region or City:
<script src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet" language="Javascript"></script><script language="Javascript"> if(typeof(sGeobytesLocationCode)=="undefined" ||typeof(sGeobytesCode)=="undefined" ||typeof(sGeobytesInternet)=="undefined") { // Something has gone wrong with the variables, so set them to some default value, // maybe set a error flag to check for later on. var sGeobytesLocationCode="unknown"; var sGeobytesCode="unknown"; var sGeobytesInternet="unknown"; } if(sGeobytesLocationCode=="geobyteslocationcode") { // Visitors from geobytescity would go here window.open("enter geobytescity URL here"); }else if(sGeobytesCode=="geobytescode") { // Visitors from geobytesregion would go here window.open("enter geobytesregion URL here"); }else if(sGeobytesInternet=="geobytesinternet") { // Visitors from geobytescountry would go here window.open("enter geobytescountry URL here"); } </script>
The re-direction script as shown in the examples below must be pasted into the <head></head> section of the page that you are re-directing your users from.
The following example would re-direct visitors from geobytescity to geobyteslocationcode.html, and would re-direct users from geobytesregion to geobytesinternetgeobytescode.html Any other visitors from geobytescountry would be re-directed to geobytesinternet.html. Visitors from other countries will not be re-directed.
<script src="http://gd.geobytes.com/gd?pages=geobyteslocationcode,geobytesinternetgeobytescode,geobytesinternet" language="Javascript"></script>
The following example re-directs to an .ASP page and waits for 5 seconds.
<script src="http://gd.geobytes.com/gd?pages=geobyteslocationcode,geobytesinternetgeobytescode,geobytesinternet&ext=ASP&after=5" language="Javascript"> </script>
Can you re-direct users to any page name you like?
Yes, there are a number of ways to do this. First you can use the targetpage parameter to specify the target page for the redirect. Here is an example:
<script src="http://gd.geobytes.com/gd?pages=USNYNYOR,UKENLOND&targetpage=BigCities&ext=ASP&after=5" language="Javascript"></script>
Notice, that you still need to set the file extension, if any. In the above example, all visitors from either New York or London would be redirected to BigCities.ASP.
Another approach is to use the “sGeobytesLocationCode” Javascript variable to detect where the user is from, and then issue your own re-direct to any other page you like. Re-directing your users this way enables you to have more control over which users are re-directed to which pages. For example:
<script src="http://gd.geobytes.com/Gd?pages=geobytesinternet&ext=html&after=-1" language="Javascript"></script><script language="javascript"> if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode.indexOf('geobytesinternet')==0) { document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=enter your url here'>"); } </script>
The script above would re-direct users from geobytescountry to any page that you specify, you can also specify a fully qualified url. Just replace “enter your url here” with the url of the page you are re-directing your users to.
Can you re-direct all users within a given radius?
Yes, there are at least two ways to do this, depending on whether you want to send the visitors from each of the cities within the specified radius to their own custom page or to a common page for all of the cities within the defined area.
This script uses the -r parameter to direct all visitors from within a 80 kilometre radius of to a target page called MyPage.html after 5 seconds.
<script src="http://gd.geobytes.com/gd?pages=geobyteslocationcode -r 80&targetpage=MyPage&ext=html&after=5" language="Javascript"></script>
The above approach will probably meet most application’s requirements, however, there is another way to use this ‘radius’ facility, and that is “without specifying a target page” as we did in the above example. If you omit the target page parameter from the above example, then GeoDirection will redirect each city’s traffic to its own page – you would need a landing page for each city within the radius – as the script will automatically redirect to the users ‘city page’. (A city page being something like – geobyteslocationcode.html) This option – without the targetpage parameter is more tedious as you would need to look up all of the location codes for all of the surrounding cities – and worse still create pages for each city. However, while this approach might seem like a complete waste of time, it is very handy when the server is dynamically creating the pages on the fly – the URI part of the URL tells the server which page to create.
Another option is to just include a comma-separated list of all of the location codes within the area of interest and then redirect to a nominated page manually – as shown in the “AlternatePageName” example above.: The advantage of this method, while more complex, is that you get more control.
See the FAQ below for further examples.
How to find out location codes for Cities, Regions, Countries?
The last point you need to know to get geo re-directs running is the location codes for the cities, regions, and countries that you wish to target.
The easiest way is to use our AJAX Cities API page, to look up the code for the nominated city, but as you have probably realised now you can pretty much guess the code of many of the countries and regions. For example: The region code is the first 4 characters of the location code, and the country code is the first 2 characters.
Using the sGeobytesLocationCode Javascript Variable
After the GeoDirection service processes your request it initialises a JavaScript string variable that is accessible by any JavaScript on the page. The variables name is “sGeobytesLocationCode” and its value is set to the location code of the user. For example: The location code for geobytescity is geobyteslocationcode. If the user’s location can’t be determined its value is “unknown”. You may wish to use this variable to tell the user something like: “We are now re-directing you to our geobytescity page… Please Wait…” Following is some sample code:
<script language="javascript"> if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode=="geobyteslocationcode") { document.write("We are now re-directing you to our geobytescity page..."); } </script>
How do I open the re-directed page in a new window?
Simply use JavaScript’s window.open method. For example, the code below would open a new page redirecting users from geobytesregion .
<script src="http://gd.geobytes.com/Gd?after=-1" language="Javascript"></script><script language="javascript"> if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode.indexOf('geobytesinternetgeobytescode')==0) { window.open("enter url here"); } </script>
How many Geobytes’ JavaScript variables are there and what are their names?
There are 30 Geobytes’ JavaScript variables in total to use, their names with a short summary describing each variable are in the table below:
|
*IANA – Internet Assigned Numbers Authority
For a comprehensive description of each of the above fields see the Understanding the Geo Tags & Geobytes Headerspage.
How could I redirect users from multiple countries to multiple pages respectively?
The code below would redirect users from the countries within each variable (ie. var sCountryLocations=”US”) to be redirected to any page of a webmasters choice.
<script src="http://gd.geobytes.com/Gd?after=-1" language="Javascript"></script><script language="javascript"> var sSpanishLocations="ES,MX,GT,SV,HN,NI,CR,EC,PE,CU,DO,PR,PA,VE,CO,BO,AR,CL,PY,UY"; var sGermanLocations="DE,AT,CH"; var sFrenchLocations="FR,BE"; var sPhilippineLocations="PH"; var sKoreanLocations="KP,KR"; var sChineseLocations="CN"; if(typeof(sGeobytesLocationCode)!="undefined") { var sCountryCode=sGeobytesLocationCode.substring(0,2); if(sCountryCode!="US"&&sCountryCode!="CA") { if(sSpanishLocations.indexOf(sCountryCode)>=0) { // Spanish Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Spanish.htm'>"); }else if(sGermanLocations.indexOf(sCountryCode)>=0) { // German Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=German.htm'>"); }else if(sFrenchLocations.indexOf(sCountryCode)>=0) { // French Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=French.htm'>"); }else if(sPhilippineLocations.indexOf(sCountryCode)>=0) { // Philippine Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Philippine.htm'>"); }else if(sKoreanLocations.indexOf(sCountryCode)>=0) { // Korean Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Korean.htm'>"); }else if(sChineseLocations.indexOf(sCountryCode)>=0) { // Chinese Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=Chinese.htm'>"); }else { // World Visitors would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=World.htm'>"); } } } </script>
How would I redirect users to two different pages?
The code below redirects users from the countries within Europe to one page and visitors from the United States to another page. The rest of the world stays on the current page that this code is pasted onto.
<script src="http://gd.geobytes.com/Gd?after=-1" language="Javascript"></script><script language="javascript"> var sLocations="US,AL,AD,AT,BE,BG,HR,CZ,DK,EE,FO,FI,FR,DE,GI,GR,"+ "GG,VA,HU,IE,IT,JE,LV,LI,LT,LU,MK,MT,IM,MC,NL,NO,PL,PT,RO,SM,SK,SI,ES,SE,CH,UK,YU"; if(typeof(sGeobytesLocationCode)!="undefined") { var sCountryCode=sGeobytesLocationCode.substring(0,2); if(sLocations.indexOf(sCountryCode)==0) { // Visitors from the US would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=enter url here'>"); }else if(sLocations.indexOf(sCountryCode)>0) { // Visitors from Europe would go here document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=enter url here'>"); } } </script>
How would I redirect visitors from the United States to “http://www.SomeDomain.com” and the rest of the world to “http://www.restoftheworld.com”?
The code below shows how to, by default let all the traffic go to “http://www.restoftheworld.com” then re-direct people from the United States to “http://www.SomeDomain.com”.
<script src="http://gd.geobytes.com/Gd?after=-1" language="Javascript"></script><script language="javascript"> if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode.indexOf('US')==0) { document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.SomeDomain.com'>"); } </script>