Search
Clear search
Close search
Google apps
Main menu
true

First-party cookie targeting

Target the value of a first-party cookie in the visitor’s browser.

Optimize can check to see if a visitor has a first-party cookie from your website and use that information in targeting rules.

In this article:

When to use First-party cookie targeting

Cookie targeting is frequently used to check whether a user is logged-in or not, but it can also be used to retrieve the value of any first-party cookie that you set in the visitor’s browser. When your experiment is running and is targeted to a particular cookie value, Optimize checks the first-party cookie in the visitor's browser, allowing you to target a specific set of users with your experiment.

Note: If a cookie with same name is deployed on multiple paths or multiple levels of domain within the same domain, the first value will be chosen. This is the same as if you had called document.cookie from within a page and chosen the first result.

Example: Target signed-in visitors

To create a rule to check whether a user is signed-in to your website or not and serve experiment variations only to signed-in users you need to create a custom variable, then build a condition with it.

Step 1: Create a custom variable

  1. Create or edit an experiment.
  2. Click the TARGETING tab.
  3. Click AND to add a new targeting rule.
  4. Click First-party cookie rule type.
  5. Click Variable, then Create new...
    1. Optionally, click an existing variable to edit it.
  6. Enter a Cookie Name – For example, logged_in.
    1. Optionally, check URI-decode cookie if you URI encode the value of a cookie (Learn more).
  7. Name your variable something descriptive (for example, Logged in cookie).
  8. Click CREATE VARIABLE.

Optimize

Step 2: Build a condition with your custom variable

After creating your custom variable, Optimize will populate it in a new targeting condition which you can complete by adding a match type and value. For this example, build the following condition and click SAVE.

Variable Match type Value
Logged in cookie equals true

Optimize first-party cookie targeting condition builder.

The Logged in cookie variable returns the value for the first cookie with the name logged_in.

This condition will evaluate true if:

  • the value of the logged_in cookie is true.

This condition will evaluate false if:

  • the value of the logged_in cookie is false.

About URI-encoding cookie values

If you URI-encode the value of a cookie, check the URI-decode cookie checkbox during rule creation. This allows you to safely store an arbitrary string in the cookie value. For example, if you want to store a cookie value of a=b you would URI encode it as a%3Db because equals (=) is not a valid cookie value character.

Match types

The following match types are available in query parameter targeting:

Equals / does not equal

Every character in your query parameter, from beginning to end, must be an exact match of the entered value for the condition to evaluate as true. A condition using does not equal will evaluate as true when the query parameter does not equal any of the entered values.

Example:

Variable Match type Value
Logged in cookie equals true

Will evaluate true when the value of the logged in cookie is true.

 

Variable Match type Value
Logged in cookie does not equal true

Will evaluate true when the value of the logged in cookie is false.

Contains / does not contain

The contains match type (also known as a "substring match") allows you to target any occurrence of a substring with a longer string. Contains is useful when targeting a unique query string parameter that appears in multiple URLs.

Example:

Variable Match type Value
page contains 4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=4
Variable Match type Value
page does not contain page=4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=2

Starts with / does not start with

The starts with match type matches identical characters starting from the beginning of the query string up to and including the last character in the string you specify. Use the starts with match type when your query parameters are generally unvarying but can include strings at the end that you want to exclude.

Example:

Variable Match type Value
page starts with 4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=4
Variable Match type Value
page does not start with 4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=2

 

Ends with / doesn't end with

An exact match of the entered value with the end of the URL. You can target shopping cart pages that use /thankyou.html at the end of their URLs.

Example:

Variable Match type Value
page ends with 4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=24
Variable Match type Value
page does not end with 4

Will evaluate true for:

  • http://www.example.com/member.cgi?id=9&page=42

Regex matches / does not regex match

A regular expression uses special characters to enable wildcard and flexible matching. Regex matches are useful when the stem, trailing parameters, or both, can vary in the URLs for the same webpage. If a user could be coming from one of many subdomains, and your URLs use session identifiers, you could use a regular expression to define the constant element of your URL.

Example:

Variable Match type Value
page regex matches checkout.cgi\?page=1

Will evaluate true for:

  • http://sports.example.com/checkout.cgi?page=1&id=123
  • http://fishing.example.com/checkout.cgi?page=1&lang=en&id=123
Variable Match type Value
page does not regex match checkout.cgi\?page=1

Will evaluate true for:

  • http://sports.example.com/checkout.cgi?page=2&id=123

Operators

AND

The AND operator is useful when you wish to target a variation based on multiple rules that all need to be true. Conditions using the AND operator will only evaluate as true when all of the values are met.

Example:

To target users searching for nexus, while browsing from a tablet, create two rules joined by the AND operator.

A query parameter targeting rule:

Variable              Match type Value
search query equals nexus

...and a technology targeting rule:

Variable Match type Value
Device Category equals tablet              

OR

The OR operator is useful for targeting one kind of page with multiple URL configurations. Conditions using the OR operator will evaluate as true when any of the values are met. You can use OR by adding additional values in a URL targeting rule. When targeting URLs, OR is automatically appended to your first URL after pressing return. Simply type additional URLs (followed by return) to continue building conditions with the OR operator.

Example:

To target searches on your website for either nexus or chromecast, create a rule with two site search in the Value field. You'll notice that OR is automatically added after you press enter.

Variable Match type Value
search query equals nexus or... chromecast

The OR operator is supported within individual conditions but you can't use it to combine multiple conditions. For example, you can build a condition like this: "path equals /store OR /shop" but you can't use OR across multiple conditions like this: "path equals /store OR host equals example.com"

Related targeting articles

Was this article helpful?
How can we improve it?