Skip to main content
URL, Keyword and Data Layer Rules

Block/allow the widget to appear on specific URLs, where particular keywords are present, or based on the data present on the site

Nicky Knoesen avatar
Written by Nicky Knoesen
Updated over 4 years ago

Setting rules based on a URL or keyword

It's really easy to control where your widget will appear by using the URL and Keyword Rules in your Settings.

Keyword rules

You can enter URL strings where the keyword is present, or just the keyword itself (either will work):

URL rules

How to do it 

Setting rules based on Javascript data (advanced)

Note: This feature is available on request. Please drop a message to support@responseiq.com and we enable it for you.

If you are using Javascript on your site Data Layer Rules allow you show or hide the widget based on the value of a Javascript variable.

Adding a rule

To add a rule first choose the page(s) on your site where you want the Data Layer Rule to be evaluated. This is done the same way as specifying a URL or Keyword rule, described in the beginning of this article.

The next step is to set the actual rule, which consists of an Action which applies if the rule matches, a Javascript variable (via a JSON Path), a comparison and a value.

The variable can either be a single value (String, Number, Boolean) or a Javascript object. In both cases you specify the JSON Path to the variable or to the location in the Javascript object which contains the value you want to compare. The JSON Path starts with a $  sign, which stands for the global window  scope of the page the rule is evaluated on. Starting with the $  sign you use the dot-notation to reference the variable or the value within the Javascript object.

Here are two examples to illustrate this: 

Example 1 

For the simple case of a global Javascript variable var RIQ = 'holidays' the JSON Path to reference the holidays  value is: $.RIQ

Example 2

In case you want to use a value within a Javascript object you use the dot-notation to specify which part of the object you want to reference. So if your variable is
var RIQ = { campaign: { name: 'holidays' } } the JSON Path to reference the holidays  value is: $.RIQ.campaign.name 

After setting the JSON Path for the variable you choose one of the available comparisons - ===  (strict equal), !=  (not equal), <  (smaller), <= (smaller or equal), > (greater), >=  (greater or equal) - and the actual value the variable should be compared with.

After adding the rule it will be evaluated on the page(s) you specified and if the comparison matches the widget will either Show or Hide, depending on the action you selected. 

Rule evaluation

A Data Layer Rule is always evaluated for a matching URL/Keyword pattern, except if a URL/Keyword Rule is specified (see beginning of this article) which does blocks the widget for this page. In this case the Data Layer Rule is not evaluated at all.

If multiple Data Layer Rules are specified for a matching URL/Keyword pattern and at least a single rule matches the Show or Hide action is triggered (the rules are "Or" connected).

If a Show and a Hide rule match for the same URL/Keyword pattern the Hide rule wins.

Data and dynamic variables

The Javascript variable needs to be present on the page before the widget's installation code is run, because we evaluate the rules first when the widget loads. You can dynamically change this data and we will re-evaluate the rules every time the URL of your page changes (e.g. because of clicking on an anchor link where the user stays on the current page or when navigating in a single page application). This means that you can dynamically change the value of the variable via Javascript and then trigger a URL change (e.g. via the History API), which will run the rules again and Show or Hide the widget.

Did this answer your question?