Cloudflare Zaraz: Triggers, Actions and Consent -- Step-by-Step Guide
In this tutorial, you will learn how to create triggers and actions in Cloudflare Zaraz to control when third-party tools fire, manage Visitor consent for privacy Compliance, and build complex event-driven tracking workflows.
Why Triggers, Actions, and Consent Matter
Loading all third-party tools on every page is wasteful and privacy-invasive. A Facebook Pixel should only fire on pages where you run ads, a newsletter popup should only trigger after a Visitor scrolls 50%, and Google Analytics should only collect data from users who consent to analytics cookies. Cloudflare Zaraz provides a trigger-and-action system that gives you precise control over when and where each tool executes, combined with a built-in consent manager that enforces Visitor privacy choices before any data leaves the edge. This replaces the need for separate consent management platforms and complex tag manager configurations. Cloudflare Zaraz processes all of this at the edge, meaning if consent is denied, no data ever reaches the third-party provider -- not even from the server side. For sites built with Cloudflare Pages or Cloudflare Workers, this is the most performance-efficient way to manage third-party tooling.
Real-world use: A news website must serve ads via Google Ad Manager on article pages, track newsletter signups on the homepage, and run analytics only after the Visitor accepts the cookie consent banner. Zaraz triggers enforce all three conditions without browser-side JavaScript execution.
Trigger and Action Flow
flowchart LR
PV[Page View] --> T1[Trigger: All Pages]
PV --> T2["Trigger: /checkout/*"]
PV --> T3[Trigger: Scroll 50%]
T1 --> A1[Action: GA4 Page View]
T2 --> A2[Action: Facebook Pixel]
T3 --> A3[Action: Newsletter Popup]
C[Consent Check] --> T1
C --> T2
C --> T3
style PV fill:#f90,color:#fff
style C fill:#f90,color:#fff
Creating Triggers
Triggers define the conditions under which an action fires. Zaraz supports page view triggers, click triggers, scroll triggers, and custom event triggers.
# Create a page view trigger for checkout pages
# Zaraz Dashboard > Triggers > Create Trigger
# Name: Checkout Page View
# Trigger Type: Page View
# Condition: URL matches /checkout/*
# Rule: Load tools only on checkout-related pages
# Expected behavior: Tools assigned to this trigger
# only fire when the visitor reaches /checkout/
# or /checkout/success pages.
# Create a scroll depth trigger
# Name: 50% Scroll
# Trigger Type: Scroll Depth
# Condition: Vertical scroll reaches 50%
# Rule: Fire once per session
# Expected behavior: Tools assigned to this trigger
# fire when the visitor scrolls halfway down the page,
# useful for newsletter popups or exit-intent tools.
# Create a click trigger
# Name: Button Click
# Trigger Type: Click
# Condition: CSS selector matches #signup-button
# Rule: Fire on every click
# Expected behavior: Tools fire whenever the visitor
# clicks an element matching #signup-button.
Configuring Actions
Actions define what happens when a trigger condition is met. Each tool in Zaraz can have multiple actions with different configurations.
# Example: GA4 page view action with consent
# Tool: Google Analytics (GA4)
# Trigger: [Checkout Page View]
# Action Type: Page View
# Settings:
# Event Name: page_view
# Consent Category: Analytics
# Additional Parameters:
# page_type: checkout
# Expected behavior: When the trigger condition matches
# and consent for the "Analytics" category is granted,
# Zaraz sends a page_view event to GA4 with the
# custom page_type parameter.
# Example: Facebook Pixel purchase action
# Tool: Facebook Pixel
# Trigger: [Checkout Page View]
# Action Type: Track
# Settings:
# Event Name: Purchase
# Parameters:
# value: {{ client.variables.cartTotal }}
# currency: USD
# Consent Category: Marketing
# Expected behavior: Zaraz sends the Purchase event
# to Facebook with the cart value, but only if the
# visitor has consented to the Marketing category.
Configuring Consent Management
Zaraz includes a built-in consent manager that generates a consent banner and enforces Visitor choices before any tool fires.
# Enable consent management:
# Zaraz Dashboard > Consent > Enable Consent Manager
# Configure consent categories:
# - Necessary (always active)
# - Analytics (requires consent)
# - Marketing (requires consent)
# - Preferences (requires consent)
# Customize the consent banner:
# Position: Bottom-right (floating)
# Title: We value your privacy
# Description: We use cookies to improve your experience
# Accept All button: Text = Accept All
# Reject All button: Text = Reject All
# Customize button: Text = Customize
Mapping Tools to Consent Categories
Each tool must be assigned to a consent category. If consent is denied for a category, all tools in that category are blocked at the edge.
# Tool-to-category mapping example:
# Google Analytics -> Analytics
# Facebook Pixel -> Marketing
# Google Ads -> Marketing
# Hotjar -> Analytics
# Intercom -> Preferences
# Essential tracking -> Necessary
# When a visitor denies "Marketing", Facebook Pixel
# and Google Ads never fire for that <a href="/design-patterns/visitor/">Visitor</a>.
Debugging with Preview Mode
Zaraz provides a preview mode to test triggers and actions before publishing.
# Enable preview mode:
# Zaraz Dashboard > Preview
# A preview banner appears on your site
# Open browser DevTools > Console to see Zaraz logs
# Expected console output:
# [Zaraz] Trigger matched: Checkout Page View
# [Zaraz] Consent status for Analytics: granted
# [Zaraz] Action fired: Google Analytics - page_view
# [Zaraz] Request sent to https://www.google-analytics.com/g/collect
Common Errors
| Error | Cause | Fix |
|---|---|---|
Action not firing |
Trigger condition not matching page URL | Test trigger with preview mode; verify URL pattern syntax |
Consent required warning |
Tool assigned to non-consented category | Check Visitor consent status; verify category mapping |
Duplicate events |
Trigger fires multiple times per page | Enable "Fire once per pageview" on the trigger |
Custom parameter not sent |
Variable syntax incorrect | Use {{ client.variables.variableName }} syntax; verify variable exists |
Preview mode not working |
Browser cache blocking preview cookie | Clear cookies or use incognito mode for preview testing |
Practice Questions
- How does the consent manager in Zaraz block data from reaching third-party tools when consent is denied?
- What is the difference between a page view trigger and a scroll depth trigger?
- How do you pass custom data from your website to Zaraz actions using variables?
FAQ
Summary
Cloudflare Zaraz triggers, actions, and consent management give you precise control over when and how third-party tools execute on your website. Triggers define conditions (page views, clicks, scroll depth), actions define what tools do, and the consent manager enforces Visitor privacy choices at the edge before any data reaches third parties.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro -- security-first tools for the modern web.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro