Ip2Country
| Detects the country of the visitors of the wiki (using IpInfoDB) and puts it in a cookie to be used by scripts afterwards. |
| Type | XAR |
| Category | |
| Developed by | |
| Rating | |
| License | GNU Lesser General Public License 2.1 |
Description
Uses the IpInfoDB services to detect the country of the visitors of the wiki and sets this information in a cookie (the 2 letter country code, actually), to be used afterwards by the scripts to provide localized information / UI.
Note that you need your own IpInfoDB account (API Key) to use this extension, which you can get by registering. Then go to the dedicated administration section of Ip2Country extension in the wiki and fill in your API Key to activate the extension:
Also note that this extension relies on IpInfoDB "as is" meaning that querying limits are the same as the ones from IpInfoDB, the only "extra caching" that this extension is doing is to set the country cookie for 2 weeks, meaning that normally, for a regular user, his country is detected every two weeks not everytime he visits the wiki.
Usage
To use this from a velocity script:
#set($userCountry = "")
#foreach($cookie in $request.cookies)
#if($cookie.name == "country")
#set($userCountry = $cookie.value)
#break
#end
#endTo use this from a javascript:
var countryCode = XWiki.cookies.read('country');Note that since the functioning of this extension relies on an asynchronous javascript call to get the information and set the cookie when it's not present, the cookie will not be present on the first load of the first page of a client that hasn't visited the wiki in the past 2 weeks, it will be set with Ajax very shortly after the page is loaded. If you need to do something when the information is refreshed and set, you need to listen to the xwiki:ip2country:updated event in javascript as follows:
document.observe('xwiki:ip2country:updated', function(){
var countryCode = XWiki.cookies.read('country');
// code that handles the new countryCode goes here
});Multiwiki behaviour
If you use XEM in path based mode and you install the extension only on one of the wikis (say, the main wiki), detection will only be enabled on the wiki where the extension is installed, but the detected country set in the cookie will be available in all wikis.
If you use XEM in domain based mode, both detection and set cookie are available only in the subwiki where the extension is enabled.
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.
You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:
- Log in the wiki with a user having Administration rights
- Go to the Administration page and select the Import category
- Follow the on-screen instructions to upload the downloaded XAR
- Click on the uploaded XAR and follow the instructions
- You'll also need to install all dependent Extensions that are not already installed in your wiki
After installing the extension, set the XWiki.XWiki.Ip2CountryTranslations document in the Internationalization Document Bundles list in the "Localization" section in the administration of your wiki.