12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Feb 25, 2021

[Condition] Cookie-based GeoLocalization in Oxygen

Sridhar Katakam

In a recent project I completed, the requirements were

1) to show flags of certain South American countries on the splash page (site.com).

When the visitor clicks Brasil or Argentina or Espana, he/she should be taken to the corresponding country "homepage" i.e., site.com/brasil or site.com/argentina or site.com/espana.

Clicking on any of the other countries should take them to site.com/home.

2) to be able to output elements based on

  • selected country or not the selected country
  • whether the selected country is Brasil/Argentina/Espana or not

This can be done by

1) creating a cookie named say, actioncoach_visitorcountry and setting its value equal to the selected country using JS

Visitor selecting a country

Cookie set to the selected country

2) creating a custom Visitor Country condition that returns true or false depending on the value in the cookie

thereby allowing the site owner to output any element per the requirements.

Applying the Visitor Country condition. Available operators: = and !=

This members-only tutorial provides the steps covering how I've set up the above. You may want to treat this as a general guide, try to understand how the code works, and implement it whilst making any necessary changes per your project's requirements.

Warning: Cookie-based approach will not work with Varnish or other type of caching in place. You need to be able to exclude the cookie from the cache. With Flywheel where my client's site is hosted, we have to send them a support ticket and they will take care of it.

Step 1

Edit the splash page with Oxygen.

Add a Code Block.


	// echo "hello world!";


This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.