Created
May 18, 2017 16:44
-
-
Save jamesspittal/d693b1723e8e4c3eb83deac0269c76b5 to your computer and use it in GitHub Desktop.
Get region/state/city from Optimizely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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