HELP FILE

Invitations with Regular Expressions

This section helps you understand how you can use regular expressions together with Custom Variables and Auto-Invite Rulesets to trigger invitations based on an almost inexhaustible set of values.

This material is intended for a technical audience. We assume that you have a working knowledge of HTML, JavaScript and regular expressions.

In essence, regular expressions (regex) are used to determine if characters, words or even a pattern of characters exist within a given string. By using Regular Expressions together with BoldChat’s Custom Variables and the Advanced Custom Field Rules (within an auto-invite rule), you gain the ability to check for an almost limitless number of data points that can form the basis of your rule criteria.

These values can be derived from HTML page elements or custom values by passing and concatenating multiple comma separated values into a single custom variable. Rules can then be set to look for multiple values within the variable text string and fire off an invitation based on the results.

Setting up the variables

Custom variables must be included in your HTML snippet, as described here: Collecting visitor data with Custom Visitor Info and Variables. Once custom variables are exposed in the HTML snippet, you must create local page variables with your preferred scripting language. The examples below use JavaScript, but any language will suffice.

Variables within the head of an HTML document can be used to set or associate values of web page elements. The maximum variable length is 65,000 characters. The script below demonstrates how you can create and set JavaScript variables to hold values. The sample uses JavaScript to extract the “innerHTML” (value between the div tag) values of the div elements and then passes the value into the newly created variables.


The div tags below represent page elements of interest, of which you want to use as a basis for your rule criteria.


The next example shows Visitor Monitoring HTML; you will need to edit it slightly in order to pass the div element values into BoldChat’s custom variables.


Here the VisitRef custom variable is set to contain a string value of Item Number = 123456789, Invoice Total = $20.00, Availability = 24, Product Name = Widget:

pageViewer.setParameter("VisitRef", "Item Number =" + itemNum + "," + "Invoice Total =" + invoiceTot + "," + "Availablity = " + avail + "," + "Product Name =" + productName);
Next you set up an Advanced Custom Field Rule that uses a regular expression to check for the desired value within the vr variable. For this example you place the regular expression within the Visit Ref Contain field, as shown below.
Fastpath: Setup > Account Setup > Invitations > Auto-Invite Rulesets > New > Rules List > New > Show/Hide Advanced Custom Field Rules

Take note that both the Visit Ref Contains and the Match Contains Rules using Regular Expressions are checked and the Visit Ref Contains field has a value of Item Number = 123456789. Availability = 24.

The .* operator is used to check if the Visit Ref Contains field has the values listed before and after the operator in that order. The value sequence is important. For instance; currently the VisitRef variable contains the string value of Item Number = 123456789, Invoice Total = $20.00, Availability = 24, Product Name = Widget. The regular expression operator checks to see if Item Number = 123456789 is contained in the variable. If so, it looks for a value of Availability = 24. The query equates true and an invitation is sent.

Remember: The order of the values being checked makes a difference! For example, if the two values are reversed in the Regular Expression, say: “Availability = 24.*Item Number = 123456789”, then this rule would equate to false (following the above example). Although both values are present, Availability comes before Item Number, so it is not found in the example above.