Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesspittal/d693b1723e8e4c3eb83deac0269c76b5 to your computer and use it in GitHub Desktop.
Save jamesspittal/d693b1723e8e4c3eb83deac0269c76b5 to your computer and use it in GitHub Desktop.
Get region/state/city from Optimizely
/**
* Optimizely automatically works out the location of the visitor ('Country', 'Region' and 'City')
*
* ... so it can be used as an alternative to databases like GeoIP2 if you already have it on your site
*
* Simple example below.
*/
var visitorProfile = window.optimizely.get('visitor');
var country = visitorProfile.location.country; // "AU"
var region = visitorProfile.location.region; // "VIC"
var city = visitorProfile.location.city; // "MELBOURNE"
console.log("State: " + region);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment