---
title: Set a test cookie to preview a live campaign or experiment
slug: performance-edge/docs/DJR5-set-a-test-cookie-to-preview-a-live-campaign-or-experiment
docTags: 
createdAt: 2026-08-05T21:01:08.783Z
---

- Optimizely Web Experimentation
- Optimizely Personalization
- Optimizely Performance Edge

A test cookie lets you preview a **live** campaign or experiment on your site without exposing it to visitors. By targeting a test cookie in your audience conditions, you can view variations, navigate across pages, and trigger events as if you were part of the experiment.

Use a test cookie when you want to do the following:

- QA a campaign or experiment that is already live.
- Share a live experience with internal stakeholders.
- Navigate across multiple pages while staying in the same variation.
- Verify that events fire correctly.

In Optimizely Web Experimentation, the test cookie is a key tool in the [Pre-Launch Checklist](docId\:JU1Sh9PVLBMIW2_VDbTjx) for testing.

In Optimizely Personalization, the test cookie lets you share running campaigns. Use the [Preview tool](docId\:G6SR7VF02w5hyw2yj0BLr) to check that your campaign looks and works how you would like before publishing. Then, use the test cookie to share the live campaign with internal stakeholders for testing.

:::hint{type="info"}
**Note**

You can also share the campaign with internal holders for QA by using the[ Share Link ](docId:6B9usHa8Q-1CK-6HqARiP)and [Force Query Parameters](docId\:JBnItQ6McDJp9dg46hJiQ).
:::

Optimizely recommends using a browser bookmark to set a test cookie. The [Optimizely browser extension](docId\:jVu6U7iUVH_1tJ_orpAZI) can also set a test cookie for you.

## Set a test cookie using a bookmark

You set the test cookie in every browser used to QA with this method.

To set a test cookie, add a bookmark to the browser, then replace the URL for this bookmark with the block of JavaScript code below. 

1. Open a Chrome browser and create a bookmark on any page.
2. Click the bookmark to change the name t&#x6F;**&#x20;Set a test cookie**. Select **Done&#xA0;**&#x74;o confirm.

   ![set-test-cookie.png](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/XVzrzdUnZCmIK3aLf0KuC-20260720-150134.png)
3. Select **Bookmarks&#xA0;**> **Bookmark Manager&#x20;**&#x69;n the Chrome toolbar. Click to edit the bookmark.
   Swap the URL with the following JavaScript function:

```auto
javascript: 
  (function () 
    { var hostname = window.location.hostname; 
      var parts = hostname.split("."); 
      var publicSuffix = hostname; 
      var last = parts[parts.length - 1]; 
      var expireDate = new Date(); 
          expireDate.setDate(expireDate.getDate() + 7); 
      var TOP_LEVEL_DOMAINS = [ "com", "local", "net", "org", 
                                "top", "xxx", "edu", "es", 
                                "gov", "biz", "info", "fr",
                                "gr", "nl", "ca", "de", "kr",
                                "it", "in", "me", "ly", "tv",
                                "mx", "cn", "jp", "il", "in",
                                "iq", "ga", "tk", "us",];
      var SPECIAL_DOMAINS = ["bb", "ck", "cr", "in", "id", 
                             "jp", "uk", "au", "nz", "za",
                             "kr", "th", "il", "ve"];

      if (parts.length > 2 && SPECIAL_DOMAINS.indexOf(last) != -1)
        { publicSuffix = parts[parts.length - 3] 
                         + "." 
                         + parts[parts.length - 2] 
                         + "." 
                         + last; }
      else if (parts.length > 1 && TOP_LEVEL_DOMAINS.indexOf(last) != -1) 
        { publicSuffix = parts[parts.length - 2] 
                         + "." 
                         + last; }; 
      document.cookie = "optly_" 
                        + publicSuffix.split(".")[0] 
                        + "_test=true; domain=." 
                        + publicSuffix 
                        + "; path=/; expires=" 
                        + expireDate.toGMTString() 
                        + ";";
    })();
```

::Image[]{src="https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/Sob6aLmCiAnnNUa1ghTTO-20260720-150134.png" size="100" alt="set-test-cookie-2.png" isUploading="false" showCaption="false" indent="2"}

4. Go to the page of your site where you would like to set the test cookie.
5. Select the bookmark to create a test cookie.
   You now have a cookie set on whichever domain you are browsing. The cookie looks something like this: `optly_YOURDOMAINNAME_test=true`

   ![set-test-cookie-3.png](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/eDJtjHtKIsagS8X5BkIpe-20260720-150134.png)

When you reload the page, you can enter an experiment or campaigns that target that cookie.

:::hint{type="info"}
**Note**

To create a test cookie in Internet Explorer, you can apply the following JavaScript code to your [console](https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide/console). 

```auto
javascript: (function () {
    var a, domain;
    a = document.createElement("a");
    a.href = document.URL;
    domain = a.hostname;
    domain = domain.replace(/^www\\./, "");
    document.cookie = "optly_YOURDOMAINNAME_test=true;Domain=" + domain + ";Path=/";
})();
```
:::

## Target the test cookie

After you set your test cookie, use an audience condition to target it. Only visitors with the test cookie can enter the experiment or campaign.

1. Go to the **Experiments** dashboard and choose the experiment or campaign.
2. Click **Audiences&#x20;**&#x69;n the **Manage Experiments&#x20;**&#x73;idebar.
3. Click **Create New Audience**.
4. Select **Standard** > **Cookie** and drag it into the conditions.
5. Enter a name for the audience.
6. Enter the name of the test cookie, `optly_YOURDOMAINNAME_test`in the text box and set to **has any value**.

   ![set-test-cookie-4.png](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/j5awish69TiKHsvax7Rpw-20260720-150134.png)
7. Click **Save Audience**.

## Target a query parameter

You can also target using a query parameter instead. This works well when testing your experiment on a mobile device.

When you view your page live, append the query parameter that you selected. For instance, on Google's homepage, this may look like `https://www.google.com?optly_google_test` if you use the query parameter shown in the following image:

![query-param-audience.png](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/8n3CPyMOV1jCIzy0zne3x-20260720-150134.png)

:::hint{type="info"}
**Note**

If you use a query parameter instead of a cookie, you must re-add the query parameter to the URL when you go to another page.
:::

When you are done, click **Apply** and then save the experiment.

## Run the experiment or campaign

After you set the test cookie, start the experiment or campaign to view it live.

To see the experiment or campaign, you must meet all of the targeting conditions, but when you are bucketed into a variation or experience, you can go to the site and stay in that variation. You can also test whether your goals are firing correctly.

## Remove the test cookie

To make the experiment live for other visitors, return to targeting. Remove the cookie restriction by clicking **Cancel**. Click **Apply** to save the change to the experiment.

## Additional resources

- See [Metrics do not track correctly](docId\:Rv7KCRArlJGavaNIZj2SV) to verify that your goals are firing in Optimizely Web Experimentation.
- See [Force behaviors in query parameters](docId\:JBnItQ6McDJp9dg46hJiQ) to force yourself into a specific variation of your running experiment using query parameters in Optimizely Web Experimentation.
