Different GEOs = Different $$ = JS for a fix

Erika in Glasses
2 min readApr 16, 2018

We build marketing landing pages for hot topic books and these landing pages can appear in different countries; sometimes it’s just CA and US, other times AU, NZ, and UK as well, and the fun fact about that is the book price is never the same. Sometimes the book cover is different as well. This used to mean creating a landing page code snippet for each country with the different information, it was time consuming and had a small chance for errors.

Then I got bored of having to do that and figured there had to be a better way to insert the information based on where the user is browsing from.

Thankfully our urls contain the geo and the lang the person is viewing the page in and I was able to use javascript to pull that information and have the correct price (for example) put in the price div.

This is what it looks like:

It’s pretty simple.

Location.pathname pulls the url path that appears after the domain, for example:

/ca/en/p/{page-url}

I used .substr to strips the first character and only keep two characters after

CA

Then using a quick if statement I am able to match the geo and the price and have the text inserted into the div ebook-price.

--

--

Erika in Glasses

Web developer. Twitch Affiliate (erikainglasses). Youtuber. Olympic lifter. I write about code and streamer.