Rich-text Reply

Formatting city name from Optimizely Visitor object

tom-hanlon 12-19-18
Accepted Solution

Formatting city name from Optimizely Visitor object

[ Edited ]

I'm building a test in Optimizely X where I'm looking to include the name of a visitor's city on the page. To do this I need to format the name of a city from Optimizely's visitor location object

window.optimizely.get('visitor').location

. The problem is that it returns the city name as all one word. It's working fine for cities with one word like "Charlotte" but not including the proper spacing for cities with a space it's returning the city as one word ("Lasvegas") for instance. The problem is there are a ton of cities with multiple spaces in the name. 

 

Does anyone know of a way to format these names without the use of a (paid) third-party API? I can't just set a rule where I divide the string based on the prefix because there are a lot of cities with multiple words in the name ("Lake Placid, NY or Truth or Consequences, NM"). 

 

The obvious answer seems to pivot to remove the city and just include the state name but I wasn't sure if anyone has run into this issue in the past. 

 

Thanks

__
Optimizing Sales/Growth for eCommerce Clients through Multivariate & A/B Testing, Personalization & Analytics

Connect with me on Linkedin

Experimentation Hero

JasonDahlin 12-19-18
 

Re: Formatting city name from Optimizely Visitor object

I would suggest using the State ....
Identification by city is a crapshoot at best and the .location attribute seems incredibly unreliable

Looking at the results of

window.optimizely.get('visitor').location

across different browsers and even the same browser yields different results

 

Chrome - always "undefined"

IE 11- always "undefined"

FireFox - one page hit "COLUMBUS" the next page hit - literally refreshing the page - "GALENA".

 

Also, city name being all upper case is a UX issue too... so you'd need to put in spaces and apostrophes and add proper casing to it (edge case: McNulty Gulch, Colorado).
There are APIs out there that you can use, but you'll have to pay for a good reliable one (even so, you'll have extra delay in presenting them the content, so hopefully this isn't for presenting on "pageload")

 

Maybe there is an account setting that would make this work better...

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero
tom-hanlon 12-19-18
 

Re: Formatting city name from Optimizely Visitor object

Thanks for the quick response @JasonDahlin. I came across an old Optiverse post (for Optimizely classic) that showed by having one geolocation-targeted experiment running that that location data becomes available and in my experience that has worked reliably. I agree with you that state name seems to be the most accurate, especially because there are a lot of examples of cities with multiple words in the name. Thank you! 

__
Optimizing Sales/Growth for eCommerce Clients through Multivariate & A/B Testing, Personalization & Analytics

Connect with me on Linkedin

Experimentation Hero
JasonDahlin 12-19-18
 

Re: Formatting city name from Optimizely Visitor object

Ah yes - I remember that thread now... you have to use location in order for it to populate correctly (if there is no audience using it, it doesn't run).

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero
tom-hanlon 12-30-18
 

Re: Formatting city name from Optimizely Visitor object

[ Edited ]

Well, after looking at a few options I created an object from a list of cities with multiple names. Starting with Github user grammakov's list of US cities, I reduced the list to unique names with spaces to produce a list of approximately ~5600 US cities with multiple words in the name. For the object's keys I removed the spaces (as this is how Optimizely returns visitor city data) and for the values retained the proper formatting.

 

It's 48kb gzipped which I don't love but it seemed like a better solution than paying another third-party vendor when the data is accessible from Optimizely. Kind of a hassle but glad to cobble something together that works -- hope this helps someone in future. 

 

 

__
Optimizing Sales/Growth for eCommerce Clients through Multivariate & A/B Testing, Personalization & Analytics

Connect with me on Linkedin

Experimentation Hero