Skip to content
  • There are no suggestions because the search field is empty.

How to Trigger an Experience Based on a Cookie Value

You can launch an experience in Visually.io based on the value of a specific browser cookie. This is useful when targeting users who’ve completed an action that sets a cookie — like logging in, completing a form, or hitting a milestone on your site.

Follow the steps below to configure a Custom JS Trigger for your experience.

Step-by-Step Instructions

  1. Open your experience in the Visually.io editor.

  2. Click on the Trigger section.

  3. Select Custom JS Trigger.

  4. Paste the following code replacing your-cookie-name and your-expected-value with the actual cookie key and value you're targeting:

return new Promise(resolve => {
  const COOKIE_NAME = `your-cookie-name`;
  const COOKIE_VALUE = `your-expected-value`;

  const match = document.cookie
    .split('; ')
    .find(c => c.startsWith(`${encodeURIComponent(COOKIE_NAME)}=`));  
  
  if (!match) return;

  const cookieVal = decodeURIComponent(match.split('=').slice(1).join('='));
  const includes = cookieVal.includes(COOKIE_VALUE);  
  
  if (includes) {
    resolve();
  }
});

  • The experience will trigger only when the specified cookie exists and contains the value you define.

  • Test it in an incognito window or browser session with the right cookie set.

  • You can combine this with other triggers (like URL rules) for more advanced targeting.