URL targeting allows you to pick the web pages where your experiments run. URL targeting is useful for presenting experiment variants on a specific set of pages, easily defined by their URL. You can target a single page, a narrow subset of pages, or even Hosts and Paths.
In this article:When to use URL targeting
To test whether larger images on /product
pages affect conversions, you could create a URL targeting rule. You could also use a URL targeting rule to test multiple variants of a landing page. In this instance, you'd use a sample product page as the Editor URL, then build the targeting rules below to target the experiment at all /product
pages.
Variables
The following Variables are available in URL targeting:
- URL (default) – The full document.location of a page. URL is the building block of Optimize's targeting conditions and is extremely flexible when combined with match types and operators.
- Host – Commonly referred to as the "domain" or "domain name." Used to target a variant to all pages on your site.
- Path – The portion of the URL following the host/domain name that doesn't include query parameters.
- URL fragment – A portion of a URL.
Match types
The following match types are available: matches, equals, contains, starts with, ends with, matches regex, as well as the inverse versions: does not equal, does not contain, does not start with, does not end with, and does not match regex.
Matches
Use matches when there are query string parameters in URLs that you don’t want to include in the matching. Matches can be more flexible than equals because it adheres to the following rules:
- Ignores query string parameters and fragments.
- Case insensitive.
- Normalized to remove a www. prefix.
- Normalized to remove a trailing slash.
- HTTP and HTTPS are optional (HTTP will match HTTPS).
Example:
Variable | Match type | Value |
URL | matches | http://www.example.com/prod_summary |
Will evaluate true for:
http://www.example.com/prod_summary
http://www.example.com/prod_summary?prod_id=1234
Will evaluate false for:
http://shopping.example.com/prod_summary
http://www.example2.com/prod_summary
Port numbers in URLs in the matches predicate are compared but will use the default value for the scheme if unspecified. e.g.:
http://example.com:80/
will matchhttp://www.example.com/
https://example.com:443/
will matchhttps://example.com/
However, http://example.com:443/
will NOT match https://example.com/
Equals
When using the URL targeting variable, every character in your URL, from beginning to end, must be an exact match of the entered value, in order for the condition to evaluate as true. Use equals when you wish to target URLs that never contain dynamic (changing) information such as session identifiers or query string parameters.
When using the Path targeting variable, every character in the document.path must be an exact match of the entered value in order for the condition to evaluate as true. As mentioned above, query parameters are not evaluated under the Path variable.
URL Example:
Variable | Match type | Value |
URL | equals | http://www.example.com/prod_summary |
Will evaluate true for:
http://www.example.com/prod_summary
Will evaluate false for:
http://www.example.com/prod_summary?prod_id=1234
Path example:
Variable | Match type | Value |
Path | equals | /prod_summary |
Will evaluate true for:
-
/prod_summary
AND/prod_summary?prod_id=1234
Will evaluate false for:
/prod_summary_final
Contains
The contains match type (also known as a "substring match") allows you to target any occurrence of a substring with a longer string. Contains is useful when targeting a unique query string parameter that appears in multiple URLs.
Example:
Variable | Match type | Value |
URL | contains | page=4 |
Will evaluate true for:
http://www.example.com/member.cgi?id=9&page=4
Will evaluate false for:
http://www.example.com/member.cgi?id=9&page=2
Starts with
The starts with match type matches identical characters starting from the beginning of the string up to and including the last character in the string you specify. Use the starts with match type when your URLs are generally unvarying but can include query string parameters at the end that you want to exclude.
Example:
Variable | Match type | Value |
URL | starts with | http://www.example.com/pages/ |
Will evaluate true for:
http://www.example.com/pages/subpage/
Will evaluate false for:
http://www.example.com/members/pages/
Ends with
An exact match of the entered value with the end of the URL. You can target shopping cart pages that use /thankyou.html
at the end of their URLs.
Example:
Variable | Match type | Value |
URL | ends with | /thankyou.html |
Will evaluate true for:
http://www.example.com/checkout/thankyou.html
Will evaluate false for:
http://www.example.com/checkout/thankyou.html?x=1&y=1
Regex matches
A regular expression uses special characters to enable wildcard and flexible matching. Regex matches are useful when the path, trailing parameters, or both, can vary in the URLs for the same webpage. If a user could be coming from one of many subdomains, and your URLs use session identifiers, you could use a regular expression to define the constant element of your URL.
Example:
Variable | Match type | Value |
Page Referrer | regex matches | checkout.cgi\?page=1 |
Will evaluate true for:
http://sports.example.com/checkout.cgi?page=1&id=123
http://fishing.example.com/checkout.cgi?page=1&lang=en&id=123
Will evaluate false for:
http://sports.example.com/checkout.cgi?page=2&id=123
Operators
AND
The AND operator is used to join multiple targeting rules so that you can target a variant to them. Conditions using AND will evaluate as true when all of the values are met.
Example:
To target users visiting your /nexus_9
page, while browsing from a tablet, create two rules joined by the AND operator.
A URL targeting rule:
Variable | Match type | Value |
URL | equals | https://store.google.com/product/nexus_9 |
...and a Technology targeting rule:
Variable | Match type | Value |
Device Category | equals | tablet |
OR
The OR operator is used within the values field of individual rules. Rules using the OR operator will evaluate as true when any of the values are met.
OR is useful for targeting one kind of page with multiple URL configurations. You can use OR by adding additional values in a URL targeting rule. When targeting URLs, OR is automatically appended to your first URL after pressing return. Simply type additional URLs (followed by return) to continue building rules with the OR operator.
Example:
To target a store page which has two different URLs, create a rule with two URLs in the Value field. OR is automatically added after you press Enter/Return.
Variable | Match type | Value |
Page Referrer | equals | http://store.google.com/ or... http://www.google.com/store/ |
Check your rule
Optimize includes a convenient ability to enter any URL and verify whether the page targeting condition(s) above it will apply. Enter a full URL (copied from your browser’s location bar and includes the prefix http://
or https://
) in the Enter URL field then click Check. If the condition you created above applies to the URL, you’ll see a green checkmark next to it. If the condition doesn't apply to the URL, you’ll see a red circle with a line through it.
To ensure that a condition applies to visitors of your regular website (http://
) and your SSL website (https://
) simply use the “or…” section of the condition builder to add both under page targeting. Then the condition will apply to visitors of both URLs.
Additional considerations
When entering a URL, you need to escape special characters. Use entity escape codes for the characters listed in the table below.
Character | Escape Code | |
Ampersand | & | & |
Single Quote | ' | ' |
Double Quote | " | " |
Greater Than | > | > |
Less Than | < | < |
For example, if your URL contains an ampersand ("&"), e.g.:
topic=1638563&rd=1
You must replace the ampersand in that portion of the URL with the "&" escape code:
-
topic=1638563&rd=1