Geo Location
loadGeo
The loadGeo
method in the SDK allows you to retrieve the visitor's geolocation.
This functionality can be leveraged to customize or restrict the experience based on visitor location,
ensuring that specific features or content are customized or limited by the visitor's geographical context.
Return Value
The loadGeo
method returns a Promise that resolves to an object containing the user's geolocation data.
This object includes key details such as latitude, longitude, and country information etc.
The Promise will resolve when the geolocation is successfully retrieved. In case of failure, the Promise may be rejected with an error.
city
: Contains the name of the visitor's city.country_code
: Contains the two-letter country code for the viewer's country. For a list of country codes, see ISO 3166-1 alpha-2.country_name
: Contains the name of the visitor's country.country_region
: Contains a code (up to three characters) that represent the visitor's region. The region is the first-level subdivision (the broadest or least specific) of the ISO 3166-2 code.country_region_name
: Contains the name of the visitor's region. The region is the first-level subdivision (the broadest or least specific) of the ISO 3166-2 code.latitude
: Contains the visitor's approximate latitude.longitude
: Contains the visitor's approximate longitude.postal_code
: Contains the visitor's postal code.
Example
Load the geo lcoation for the current visitor.
Usage
window.wyng['_WYNG_ID_'].loadGeo()
.then(function(geo) {
console.log(geo);
})
.catch(function(err) {
console.log(err);
});
Result
{
"city": "San Francisco",
"country_code": "US",
"country_name": "United States",
"country_region": "CA",
"country_region_name": "California",
"latitude": 37.7749,
"longitude": -122.4194,
"postal_code": "94103",
}