Cloudflare Docs
Zaraz
Visit Zaraz on GitHub
Set theme to dark (⇧+D)

Triggers and rules

Triggers are a set of conditions that determine if and when Cloudflare Zaraz should send events to third-party tools . In most cases, your objective will be to capture specific site actions that are relevant to your business. A trigger will usually be based on an action the end user has taken on your website, like clicking a button.

These site actions can be passed to Cloudflare Zaraz in a number of ways. You can use the Track method of the Web API or the dataLayer to send them to specific events and tools. Refer to Zaraz Track and Data layer compatibility mode for more information on how to implement these options.

You can also use complex triggers to listen for these site actions, with different types of rules like Click Listeners or Form Submissions.

For most tools, the trigger will be a simple pageview event type, for which Cloudflare Zaraz offers a pageview preset configuration. If this is the case for the tool you need, add and configure the tool to your account to get started. For example, with the Facebook Pixel tool you only need to enter your account ID and access token, and Zaraz will configure the page view trigger for you.

A valid trigger has the following structure:

<RULE_TYPE> <VARIABLE_NAME> <COMPARISON_OPERATOR> <STRING_TO_MATCH>

The exact composition of the trigger will change depending on the type of rule you choose. Here is an example for a trigger based on a Match rule:

Rule typeVariable nameMatch operationMatch string
Match rule{{ client.__zarazTrack }}Containspurchase

Refer to Rule types below for more information on the types of rules available, and Zaraz event and system properties for more information on the variables you can use to create triggers.

Rule types

The rule type determines the kind of conditions Zaraz should listen for in your web page. Zaraz supports different rule types which allow you to create complex rules.

Match rule

Zaraz tracks the variable you input in Variable name. For a complete list of supported variables, refer to Zaraz event and system properties .

Trigger example: Click listener

Rule typeVariable nameMatch operationMatch string
Match rule{{ client.__zarazTrack }}Containspurchase
Click listener

Tracks clicks in a web page. You can set up click listeners using CSS selectors or XPath expressions. Wait for events (in milliseconds) tells Zaraz to prevent the page from changing for the amount of time specified. This allows all requests triggered by the click listener to reach their destination.

Trigger example for CSS selector:

Rule typeTypeSelectorWait for events
Click listenerCSS#my-button500

To improve the performance of the web page, you can limit a Click listener to a specific URL, by combining it with a Match rule. For example, to track button clicks on a specific page you can set up the following rules in a trigger:

Rule typeTypeSelectorWait for events
Click listenerCSS#myButton500
Rule typeVariable nameMatch operationMatch string
Match rule{{ system.page.url.pathname }}Contains/my-page-path

Refer to Create a trigger to learn how to add more than one condition to a trigger.


Trigger example for XPath:

Rule typeTypeSelectorWait for events
Click listenerXPath/html/body//*[contains(text(), 'Add To Cart')]500
Form submission

Tracks form submissions using CSS selectors. Click the Validate toggle button to only fire the trigger when the form has no validation errors.

Trigger example:

Rule typeCSS SelectorValidate
Form submission#my-formToggle on or off

To improve the performance of the web page, you can limit a Form submission trigger to a specific URL, by combining it with a Match rule. For example, to track a form on a specific page you can set up the following rules in a trigger:

Rule typeCSS SelectorValidate
Form submission#my-formToggle on or off
Rule typeVariable nameMatch operationMatch string
Match rule{{ system.page.url.pathname }}Contains/my-page-path

Refer to Create a trigger to learn how to add more than one condition to a trigger.

Timer

Set up an interval of time in milliseconds before activating the trigger in Interval. In Limit specify the number of times the trigger will fire before stopping. If you do not specify a limit, the timer will run every ten seconds.

Trigger example:

Rule typeIntervalLimit
Timer502

To improve the performance of a web page, you can limit a Timer trigger to a specific URL, by combining it with a Match rule. For example, to set up a timer on a specific page you can set up the following rules in a trigger:

Rule typeIntervalLimit
Timer502
Rule typeVariable nameMatch operationMatch string
Match rule{{ system.page.url.pathname }}Contains/my-page-path

Refer to Create a trigger to learn how to add more than one condition to a trigger.