Expand my Community achievements bar.

Join us for an upcoming in-person Adobe Target Skill Builders event ~~> We're hosting these live learning opportunities to equip you with the knowledge and skills to leverage Target successfully. Learn more to see if we'll be coming to a city near you!

Can Page Delivery use RegEx

Avatar

Level 4

How do I target all pages that match a pattern in Target's Page Delivery?
I'm needing to match 100's of pages that match like this for an A/B test:

example.com/path-name/
example.com/path-name/product-name

 

I tried example.com/* and example.com/*/*  but it didn't work.

 

Thanks!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies

Avatar

Community Advisor

Hi @JPFiber - I will suggest using profile scripts that support regular expressions and use current page URL value. 

Thanks

Rajneesh

Avatar

Level 4

Hi @Rajneesh_Gautam_ - I'm not familiar with this.  Can you provide more information?

Thanks.

Avatar

Community Advisor

Here's an example by @Ryan_Roberts_  from another thread.

1. Create a profile script - sample code using Regex given below

2. Use the profile script within your audience definition of your activity

 

if (page.path.match(/basketball\/nba\/\w+?-|football\/nfl\/\w+?-/) !== null ||

    '') {

    return true;

} else {

    return false;

}

 

Avatar

Level 4

Not sure if it's working, wrote this code and then created an audience for this.  It doesn't seem to be working.  Any further suggestions?

 

var urlRegex = new RegExp("^https://example\\.com(/pages)?/local/[a-zA-Z]+(/[a-zA-Z]+)?$");
var currentUrl = user.getLocal('pageURL'); // Assuming 'pageURL' is the variable that contains the full URL

// If the URL matches the pattern, set a profile parameter
if (urlRegex.test(currentUrl)) {
user.setLocal('profile.regexMatch', 'true'); // Sets a profile parameter 'regexMatch' to 'true'
} else {
user.setLocal('profile.regexMatch', 'false'); // Sets the profile parameter to 'false' if there is no match
}

 

I also have this as my audience setting:

JPFiber_0-1708698683957.png

 

Avatar

Level 3

Hi @JPFiber 

 

In Adobe Target, to target multiple pages that match a specific pattern, you can use regular expressions in the URL targeting section. Regular expressions allow for more flexible and precise matching of URLs.

For your case, where you want to target pages with URLs like example.com/path-name/ and example.com/path-name/product-name, you can use a regular expression like:



 

^https?:\/\/example\.com\/path-name(?:\/.*)?$

 


Here's what this regular expression does:

^ asserts the start of the line.
https? matches both "http" and "https".
:\/\/example\.com\/path-name matches the literal string "://example.com/path-name".
(?:\/.*)? is a non-capturing group that matches an optional forward slash followed by any characters.
$ asserts the end of the line.
This regular expression matches URLs that start with https://example.com/path-name/ and may optionally have additional characters after /path-name/.

To set up this targeting in Adobe Target:

Navigate to your A/B test in Adobe Target.
Go to the targeting section.
Choose URL as the targeting dimension.
Select "Matches Regular Expression" as the operator.
Enter the regular expression: ^https?:\/\/example\.com\/path-name(?:\/.*)?$
This setup will target all URLs that match the specified pattern. Make sure to test your regular expression thoroughly to ensure it's capturing the desired URLs correctly.