You can retrieve geolocation information for the current visitor using the $visitor.geo
object. The Visitor Geolocation information allows you to identify the user's location based on the user's IP address, and to retrieve specific location information such as the user's city, country, and time zone.
Usage
$visitor.geo
will give you geolocation information for the requesting IP and cache that for the remainder of the visitor's session.$visitor.getGeo("IP_ADDRESS")
will give you geolocation information for the IP_ADDRESS passed in.
All of the following information can be accessed via the properties of the $visitor.geo
object in your Velocity code:
Property | Data Type | Description | Example Values (for Miami, FL, USA) |
---|---|---|---|
city | String | The full name of the visitor's city. | "Miami" |
company | String | The name of the company the visitor's IP address is registered to. | null |
continent | String | The full name of the visitor's continent. | "North America" |
continentCode | String | The code for the visitor's continent. | "NA" |
country | String | The full name of the visitor's country. | "United States" |
countryCode | String | The code of the visitor's country. | "US" |
ipAddress | String | The visitor's IP address. | "172.222.239.137" |
latitude | Float | The latitude associated with the visitor's IP address. | 25.7617 |
longitude | Float | The longitude associated with the visitor's IP address. | -80.1918 |
subdivision | String | The full name of the visitor's state, province, or region. | "Florida" |
subdivisionCode | String | The code for the visitor's state, province, or region. | "FL" |
timezone | String | The location-based name of the visitor's time zone. | "America/Miami" |
Notes
- To access an individual property, append the property name to the
$visitor.geo
object, as in the following example:$visitor.geo.city
- You may display all the properties of the
$visitor.geo
object at once, by displaying the entire object to the screen.- However the geolocation information is not displayed if you display the entire
$visitor
object to the screen; you must explicitly reference the$visitor.geo
object for the geolocation information to be displayed.
- However the geolocation information is not displayed if you display the entire
- The visitor's latitude and longitude are determined from the IP address of the current visitor viewing the Page.
- All other values are determined based on this geolocated latitude and longitude.
- Any inaccuracies in determining the visitor's latitude and longitude will cause inaccuracies in the values of all other properties.
- The Example Value column provides example values for a user located in Miami, Florida, USA.
Updating the Geo IP database
Because dotCMS is open source, dotCMS ships with the last opensource compatible version of MaxMind's GEO_IP database, which is now more than 4 years old. It is possible to update the GEO_IP database with modern data by purchasing a new version of the database from MaxMind.
dotCMS provides a plugin that can be used to update the geoip
database in your dotCMS and dotCMS Cloud instances. Please see the instructions for using this plugin to upload and update GEO_IP in your dotCMS instances.