Support Center

How can I run an experiment on a group of pages not easily captured by a URL match?

Last Updated: Apr 16, 2013 08:10PM PDT

For many experiments you can use Optimizely's URL Matching feature to specify which page or pages the experiment should run on. However, on some sites, you may wish to run an experiment on a group of pages that are not easily captured in a substring or regular expression. This article explains how you can easily configure an experiment to run on a group of pages like this. We'll start with an example:

An example

Let's consider an ecommerce site in which the product detail pages all have urls like this:

http://www.example.com/acme-drink-mixer-item-148242.aspx
http://www.example.com/acme-specialty-fork-set-142313.aspx
http://www.example.com/shopco-salt-pepper-shakers-145525.aspx

If you wanted to run an experiment across all product pages, there's no obvious way of capturing all such URLs in a regular expression or substring.

A solution

A simple way to fix this problem is to add a JavaScript flag to all product page, and then target on that flag using a custom JavaScript targeting condition in Optimizely. Here's how you can do this.

Step 1 - add a JavaScript flag to all product pages. Add this above your Optimizely snippet:

	<script type="text/javascript">
    window.isProductPage = true;
</script>
<script src="//cdn.optimizely.com/js/XXXXXXX.js"></script>

Step 2 - Set your Optimizely experiment targeting as follows:

Note here that we've set the URL matching to "example.com" and that we're using a "Substring Match", meaning that we're actually going to run this experiment on any page on this site on which window.isProductPage page flag is set.

The nice part about using Optimizely as an AB testing tool is that you don't need to remove the flag from the page when you're done running a particular experiment. It's a relatively straightforward piece of code with zero side effects, and can be used for future experiments on the same group of pages!

desksupport@optimizely.com
http://assets0.desk.com/r1046ffeaa2233e531563a32d7edef6677d8a78b5/javascripts/
false
@Optimizely
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/portal/articles/autocomplete