Modules / Visibility & conditions

Condition: cookie

Show or hide an element by a cookie in the visitor's browser: whether it exists, what it equals, or what it contains. Use it for consent banners, returning visitors or A/B buckets.

#29 of 39 modules by votes

  • On by default
  • Needs Bricks 2.4 or newer
  • Tested with Bricks 2.4.3

Tile 29 of 39, ranked by votes · Recording in progress

Where to find it in the builder

Element conditions: Cookie, in the Kiln group.

How to use it

  1. Select the element and open its Conditions.
  2. Add the condition Cookie from the Kiln group.
  3. Choose how to compare: ==, !=, contains, does not contain, exists or does not exist.
  4. In the value field, type the cookie as name=value, or only name.

Examples:

  • cookie_consent=yes with ==: the element shows when the cookie cookie_consent equals yes.
  • returning_visitor with exists: the element shows when that cookie is present.
  • cookie_consent alone with !=: the element shows when the cookie is absent.

The name and the value accept dynamic data. Kiln renders it before it splits the text at the first =.

How it works with page caches

A cookie differs for every visitor, so a page that checks one cannot come from a shared cache. When the page evaluates a Cookie condition, Kiln tells page-cache plugins not to cache it (the DONOTCACHEPAGE constant, the LiteSpeed Cache no-cache call, and no-cache headers when they have not been sent yet).

A cache at the host or CDN level, such as nginx, Varnish or Cloudflare "cache everything", only sees the response headers. Those are usually sent before Bricks renders the page. Exclude the page from that cache, or make the cache vary by the cookie, or one visitor's version reaches everyone.

Limits

  • Matching is exact and case-sensitive. Kiln compares the raw cookie value.
  • With no value, == and contains mean the cookie exists. != and does not contain mean it does not.
  • With exists or does not exist, Kiln ignores any value.
  • An empty cookie name makes the condition false.
  • Kiln reads the cookies the browser sent with the request. A cookie your script sets in the browser shows up from the next page load.

Settings

None. Turn the module on in Bricks > Kiln (it is on by default).

Requirements

Bricks 2.4 or newer.