Rich-text Reply

Using a test cookie audience condition to QA your experiment before setting it live

Lyndsey 07-29-15

Using a test cookie audience condition to QA your experiment before setting it live

[ Edited ]

Test cookie audience conditions allow you to set an experiment live and view it, but scope it only to visitors that have the presence of the cookie - the rest of your traffic will remain unaffected by the experiment. This QA method does not override any conditions, so it’s helpful for checking that the intended url and audience conditions are working.


To set the test cookie you’ll just need to create a bookmark in your web browser. Edit the bookmark and change both its properties and set the “Name” property to “Test Cookie”,  and the “URL” to this code:



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()+";"; })();


Here's what it looks like in Chrome:

Screen Shot 2015-07-29 at 9.41.30 AM.png 


Now change the audience condition in the experiment you’d like to test. In the conditions section, drag Cookie into the Audience Conditions section, and then enter the name of our test cookie in the text box (i.e., 'optly_YOURDOMAINNAME_test'). So, if your URL was then the cookie name would looke like optly_tastydesserts_test. Don't forget to replace YOURDOMAINNAME with the correct domain. 


Screen Shot 2015-07-29 at 9.47.17 AM.png


Choose Has any value from the drop-down menu tells Optimizely to just check for the existence of this cookie. Once you have clicked “Apply”, “Save” and “Start Experiment” then you are ready to go!


Screen Shot 2015-07-29 at 9.43.32 AM.png


Navigate to the targeted url, click the “Test Cookie” bookmark and refresh the page. You will now meet the audience conditions for the experiment, allowing you to QA it live without affecting the rest of your site.



Let me know how this works for you and if you have any other methods of QA. Also, check out my post on using Optimizely force variation parameters so you can easily see certain variations and how it looks on a specific screen/browser etc. This is another helpful way to QA. 

Technical Support Engineer

JasonDahlin 03-23-16

Re: Using a test cookie audience condition to QA your experiment before setting it live

Note: This message board prevents the bookmarklet code from displaying correctly.  At the beginning of the line of code for the bookmarklet that sets the cookie, change the ":" to just a regular colon.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy

Experimentation Hero