Location
Detects and retrieves user's location data for geo-targeting and regional content customization. Automatically caches location information and integrates with user session data.
get
Fetches the user's current location data from the Pelcro API. Returns cached data if available, otherwise makes an API call and stores the result in session storage.
For a complete list of available properties, see Open API Location endpoint.
Example
// Basic usage
Pelcro.location.get((error, response) => {
if (error) {
console.error('Failed to get location:', error);
return;
}
console.log('countryCode:', response.data.location.countryCode);
console.log('RegregionCodeion:', response.data.location.regionCode);
console.log('isEUCountry:', response.data.location.isEUCountry);
});
Caching
- Response is cached in session storage as pelcro.user.location
- Returns cached data immediately if available
- Makes API call only if no cached data exists
Updated about 4 hours ago