Walkthrough: Using Cookies for audience segmentation

Learn how to segment visitors based on their cookies to personalize for logged-in users, affiliate traffic, on-site actions, and more.

Do you want to personalize for logged-in users? Maybe you identify affiliate traffic using cookies. Or maybe you fire cookies when a visitor perform certain actions. In this guide, you will learn how to segment visitors based on existing cookies and how to set up your own cookies to create behavior-based audiences (note: this article is an addition to our main article about behavior-based audiences.).

What are cookies?

A cookie is a small piece of data sent from a website and stored on the user's computer by the web browser. Cookies help your website remember information (e.g. items added to shopping cart, information entered in a form field,...) or record the user's browsing activity (e.g. clicking a button).

Prerequisite for using cookies

For security and performance reasons, your website doesn't send cookies to Unless by default. So, to create an audience based on a cookie, you need to whitelist the cookie you want to send us in your account settings. Also, bear in mind that the browser cookie can’t be set to httpOnly since we won’t be able to read the cookie or send it to our servers.

Basic: How to use existing cookies

Generally, you have two options - target based on the existence of a cookie or the value of a cookie.

How to personalize based on the existence of a cookie

When setting up your target audience, choose: behavior > cookie > is set > nameofyourcookie

audience-cookie-loggedin

Here, we target users for whom the cookie "isLoggedIn" is set.

How to personalize based on the value of a cookie

If you want to display a variation based on a specific value of a cookie, you'll have to enter both, the name of the cookie and its value → nameofyourcookie=value

audience-cookie-customerplan

Here, we target users for whom the cookie "customerPlan" has the value "basic"

Advanced: How to set a new cookie

By adding some custom Javascript, you can set up your own cookies. This way you can personalize based on landing page or pages viewed. Here are the two steps you need to take for this:

Step 1: Add a cookie

Use the advanced editor to add a cookie following this naming structure: Txt.setCookie(name, value, days)

cookie3 xero *In this example we set the cookie Txt.setCookie('solution', 'startup', 365);). *

Step 2: Define the cookie as a targeting condition

Now, use the cookie to define your target audience. Choose: behavior > cookie > is set > nameofyourcookie=value

audience-cookie-startup

For the "Startup" audience, we use the cookie as a targeting condition. Now, we can personalize for all visitors who initially arrived on the Startup landing page.