Run Javascript action

How to run javascript using rules

Nir avatar
Written by Nir
Updated over a week ago

A Barilliance rule can optionally include Javascript code. This powerful capability can be used for various tasks such as manipulating, reporting, debugging or creating advanced events that trigger for the rule segment. For example it can allow any visual change to the rule output by manipulating css.

Using Run Javascript action

To apply Javascript to a rule add the 'run javascript' action.

Javascript can be run in three different points in time.


โ€‹Before rules triggering

If the rule meets the segment on the page view. this javascript and any 'Before rules triggering' javascript of other rules, will run before all the rules actions of the page are executed.

This can be useful to suppress a rule output of the current or other rule (see below).

After rule triggering
If the rule meets the segment on the page view. this javascript and any 'After rules triggering' javascript of other rules, will run after all the rules actions of the page are executed. This is useful for example to manipulate a popup created by one of the rules (including the current rule).

After delayed rule triggering

This code will trigger if the rule is a delayed rule, delayed rules are rules which do not automatically trigger in the page view but are dependent on some other event to trigger. For example rules with 'about to leave', 'close tab' 'time on page', 'time on site', 'run by_javascript' segments.
The code will trigger only if the delayed rule is actually triggered. For example if the rule include 'about to leave site' segment, the code will trigger only if there is an attempt from the visitor to leave the site.

Do not use this box for non delayed rules.

Suppressing a rule output

A rule output such as Banner or popup can be suppressed by another rule using Javascript. This applies to visual output such as Pop ups, Message Bars, Overlays Banner.
To suppress a rule output use this format
โ€‹cbar_suppress_rules.push (%rule_id%);
Where %rule_id% will be automatically replaced by the current rule id. If you want to suppress output of another rule use the corresponding rule_id as a number.

Using tokens in Javascript

The following tokens apply in javascript rules:

To learn about the automatic tokens which can be used in Javascript code please refer to https://support.barilliance.com/en/articles/2532734-showing-dynamic-content-in-popups-message-bar-javascript-rules

Did this answer your question?