Pattern Match

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:

  • start with
  • end with
  • contains
  • full match

Examples

Set custom variable in index 1 if current page URL ends with “productA”.

Lets say the current URL path is ‘/products/productB’. This example checks if path contains “products” and set custom variable.