- 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:
- 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 for testing.
In Optimizely Personalization, the test cookie lets you share running campaigns. Use the Preview tool 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.
Optimizely recommends using a browser bookmark to set a test cookie. The Optimizely browser extension can also set a test cookie for you.
Set a test cookie using a bookmark
You will 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.
- Open a Chrome browser and create a bookmark on any page.
-
Click the bookmark to change the name to Set a test cookie. Select Done to confirm.
-
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", "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() + ";"; })(); - Go to the page of your site where you would like to set the test cookie.
-
Select the bookmark to create a test cookie.
You now have a cookie set on whichever domain you are browsing. The cookie will look something like this:
optly_YOURDOMAINNAME_test=true
When you reload the page, you can enter an 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 set your test cookie, use an audience condition to target it. Only visitors with the test cookie can enter the experiment or campaign.
- Go to the Experiments dashboard and choose the experiment or campaign.
- In the Manage Experiments sidebar, click Audiences.
- Click Create New Audience.
- Select Standard > Cookie and drag it into the conditions.
- Enter a name for the audience.
-
Enter the name of the test cookie,
optly_YOURDOMAINNAME_testin the text box and set to has any value. - Click Save Audience.
Target a query parameter
You can also target using a query parameter instead. This also 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:
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 still need to 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 to verify that your goals are firing in Optimizely Web Experimentation.
- See Force behaviors in query parameters to force yourself into a specific variation of your running experiment using query parameters in Optimizely Web Experimentation.
Article is closed for comments.