This article will help you:
  • Use a "test cookie" or query parameter to browse an experiment or campaign as if it's live
  • Set a test cookie on your page, then target based on it
  • Show a live experiment or campaign to an internal audience

When you QA, it's often useful to be able to start an experiment or campaign live on your site but allow only internal employees to see it.

Setting a test cookie allows you to show a running campaign or experiment to a set of internal stakeholders. You'll create a bookmarklet in the browser that sets the cookie. Then, use audience conditions to target the cookie. Visitors who have the test cookie will be able to navigate across multiple pages, and fire events in the live experiment or campaign.

In Optimizely Testing, the test cookie is a key tool in the Pre-Launch Checklist for QA.

In Optimizely Personalization, the test cookie will help you share running campaigns. Use the Preview tool to check that your campaign looks and works the way you'd like, before you publish. Then, use the test cookie to share the live campaign with internal holders for QA.

Read on to learn how to set up and target a test cookie.


Cookie targeting isn't available to all plan types. If you don’t see this feature in your Optimizely account, please refer to our Optimizely X package matrices. You can also share the campaign with internal holders for QA by using the Share Link, Cross-Browser Testing, and Force Query Parameters

You'll 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. First, open a browser in Chrome and create a bookmark on any page.


  2. Click the bookmark to change the name to "Set test cookie." Select Done to confirm.

  3. In the Chrome toolbar, select Bookmarks Bookmark Manager. Click to edit the bookmark.

    Swap the URL with the following JavaScript function:

    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", "xxx", "edu", "es", "gov", "biz", "info", "fr", "gr", "nl", "ca", "de", "kr", "it", "me", "ly", "tv", "mx", "cn", "jp", "il", "in", "iq"]; var SPECIAL_DOMAINS = ["jp", "uk", "au"]; 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()+";"; })();

  4. Next, navigate to page your site where you'd like to set the test cookie.

  5. Click the bookmark to create a test cookie.

    You now have a cookie set on whichever domain you're browsing. The cookie will look something like this: optly_YOURDOMAINNAME_test=true

When you reload the page, you'll eligible to enter experiment or campaigns that target that cookie.

To create a test cookie in Internet Explorer, you can apply the following JavaScript code to your console

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've set your test cookie, use an audience condition to target it. Only visitors who have the test cookie will be eligible to enter the experiment or campaign.


  1. Navigate to the Experiments dashboard and choose the experiment or campaign.

  2. In the Manage Experiments sidebar, click Audiences.

  3. Click Create New Audience.

  4. Enter a name for the audience.

  5. Drag Cookie from the list of available conditions into the Audience Conditions.

  6. Enter the name of the test cookie, optly_YOURDOMAINNAME_test, in the text box and set to has any value.

  7. Click Save Audience.

Target a query parameter

If your Optimizely plan doesn't include targeting by cookie, you can use a query parameter instead. This also works well when QAing your experiment on a mobile device.

When you view your page live, you'll have to append the query parameter that you selected. For instance, on Google's homepage, this may look like if you use the following query parameter:


Just note that if you use a query parameter instead of a cookie, you'll have to re-add the query parameter to the URL when you browse to another page.

Once you're done, click Apply and then save the experiment.

Run the experiment or campaign

Now that you've set the test cookie, start the experiment or campaign to view it live.

To see the experiment or campaign, you still need to meet all of the targeting conditions. But once you're bucketed into a variation or experience, you can navigate around the site and stay in that variation. You can also test whether your goals are firing correctly.

Remove the test cookie

When you're ready to make the experiment live for other visitors, head back to targeting. Remove the cookie restriction by clicking the red x next to it. Remember to click Apply to save the change to the experiment.

For an in-depth tutorial on how to verify that your goals are firing in Optimizely X, check out this article.

To learn how to force yourself into a specific variation of your running experiment in Optimizely X, check out this article.