RTP exposes a utility function to check if pattern matches certain string. The utility can’t be used in async way because it returns an indication if there is a match or not.
You must become a Web Personalization customer and have the RTP tag deployed on your site prior to using the User Context API.
Usage
rtp.checkPattern(check_against, pattern);
Parameter | Optional/Required | Type | Description |
check_against | Required | String | String to match the pattern against. For example: current page url, product name. |
pattern | Required | String | Add % for wildcard. The pattern can be:
|
Examples
Set custom variable in index 1 if current page URL ends with “productA”.
1 2 3 |
if (rtp.checkPattern(window.location.href, '%productA')) { rtp('set', 'custom1', 'productA'); } |
Lets say the current URL path is ‘/products/productB’. This example checks if path contains “products” and set custom variable.
1 2 3 4 |
var currentURLPath = '/products/productB'; if (rtp.checkPattern(currentURLPath, '%products%')) { rtp('set', 'custom1', 'products'); } |