Triggers and rules
Triggers define the conditions under which a tool will start an action . In most cases, your objective will be to create triggers that match specific website events that are relevant to your business. A trigger can be based on an event that happened on your website, like after clicking a button or loading a specific page.
These website events can be passed to Cloudflare Zaraz in a number of ways. You can use the Track method of the Web API or the dataLayer
call. Alternatively, if you do not want to write code to track events on your website, you can configure triggers to listen to browser-side website events, with different types of rules like Click Listeners or Form Submissions.
Rule types
The exact composition of the trigger will change depending on the type of rule you choose. Zaraz matches the variable you input in Variable name with the text under Match string. For a complete list of supported variables, refer to Zaraz event and system properties
. Trigger example: Match When matching based on a System property, you will often want to add a second rule that matches Trigger example: All pages under Trigger example: All logged in users Refer to the Zaraz event and system properties for more information on the variables you can use when using Match rule. Tracks clicks in a web page. You can set up click listeners using CSS selectors or XPath expressions. Wait for actions (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: 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: Refer to Create a trigger to learn how to add more than one rule to a trigger. Trigger example for XPath: 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: 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: Refer to Create a trigger to learn how to add more than one condition to a trigger. Set up a timer that will fire the trigger after each Interval. Set your interval time in milliseconds. In Limit specify the number of times the interval will run, causing the trigger to fire. If you do not specify a limit, the timer will repeat for as long as the page is on display. Trigger example: The above Timer will fire once, after five seconds. 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: Refer to Create a trigger to learn how to add more than one condition to a trigger.Match rule
zaraz.track("purchase")
Rule type Variable name Match operation Match string Match rule {{ client.__zarazTrack }}
Equals purchase
{{ client.__zarazTrack }}
to Pageview
. Otherwise, your trigger will be valid for every other event happening on this page too. Refer to Create a trigger to learn how to add more than one condition to a trigger./blog
Rule type Variable name Match operation Match string Match rule {{ system.page.url.pathname }}
Starts with /blog
Rule type Variable name Match operation Match string Match rule {{ client.__zarazTrack }}
Equals Pageview
Rule type Variable name Match operation Match string Match rule {{ system.cookies.isLoggedIn }}
Equals true
Rule type Variable name Match operation Match string Match rule {{ client.__zarazTrack }}
Equals Pageview
Click listener
Rule type Type Selector Wait for actions Click listener CSS #my-button
500
Rule type Type Selector Wait for actions Click listener CSS #myButton
500
Rule type Variable name Match operation Match string Match rule {{ system.page.url.pathname }}
Equals /my-page-path
Rule type Type Selector Wait for actions Click listener XPath /html/body//*[contains(text(), 'Add To Cart')]
500
Form submission
Rule type CSS Selector Validate Form submission #my-form
Toggle on or off Rule type CSS Selector Validate Form submission #my-form
Toggle on or off Rule type Variable name Match operation Match string Match rule {{ system.page.url.pathname }}
Equals /my-page-path
Timer
Rule type Interval Limit Timer 5000
1
Rule type Interval Limit Timer 5000
1
Rule type Variable name Match operation Match string Match rule {{ system.page.url.pathname }}
Equals /my-page-path