All Collections
Content Personalization
Trigger action by Javacript
Trigger action by Javacript
Nir avatar
Written by Nir
Updated over a week ago

An action such as showing a popup or message bar can be triggered programmatically by Javascript code running in the browser.
To trigger an action by Javascript define 'By Javascript' in the rule schedule section.

Once 'By javascript' is selected you will be shown the line of code to run that will trigger the rule action. for example:
cbarApp.delayed.run(44344);

If the rule has been just created and never saved you will see this:
cbarApp.delayed.run(SAVE RULE TO SEE RULE ID HERE !);
Save the rule to see the complete javascript code.


How to test

When using standard rule preview, the action is always triggered even if the rule is set to trigger by javascript. Therefore it is not a good way to check if the javascript triggering works well.
To test that triggering by javascript actually work you need to run the rule without preview mode. Here are the recommended steps:
1. add a segment to the rule with IP address restricted to your IP address (which makes sure the rule runs only for you).

2. Activate the rule so it will apply to your IP only.
3. Visit a relevant page on the website which matches the rule segment (if any).
4. In the browser console paste the JS code line and click enter to run it.

For example:

cbarApp.delayed.run(44344);
You should see the rule action triggered.

5. Don't forget to deactivate the rule or remove the IP address restriction if you are happy with the rule and want to publish it.

Note:

Not all actions can be triggered by Javascript. It is important to test any rule using it and make sure it performs as expected.




Did this answer your question?