Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/zaraz/patterns.md
1# Zaraz Patterns23## SPA Tracking45**History Change Trigger (Recommended):** Configure in dashboard - no code needed, Zaraz auto-detects route changes.67**Manual tracking (React/Vue/Next.js):**8```javascript9// On route change10zaraz.track('pageview', { page_path: pathname, page_title: document.title });11```1213## User Identification1415```javascript16// Login17zaraz.set({ userId: user.id, email: user.email, plan: user.plan });18zaraz.track('login', { method: 'oauth' });1920// Logout - set to null (cannot clear)21zaraz.set('userId', null);22```2324## E-commerce Funnel2526| Event | Method |27|-------|--------|28| View | `zaraz.ecommerce('Product Viewed', { product_id, name, price })` |29| Add to cart | `zaraz.ecommerce('Product Added', { product_id, quantity })` |30| Checkout | `zaraz.ecommerce('Checkout Started', { cart_id, products: [...] })` |31| Purchase | `zaraz.ecommerce('Order Completed', { order_id, total, products })` |3233## A/B Testing3435```javascript36zaraz.set('experiment_checkout', variant);37zaraz.track('experiment_viewed', { experiment_id: 'checkout', variant });38// On conversion39zaraz.track('experiment_conversion', { experiment_id, variant, value });40```4142## Worker Integration4344**Context Enricher** - Modify context before tools execute:45```typescript46export default {47async fetch(request, env) {48const body = await request.json();49body.system.userRegion = request.cf?.region;50return Response.json(body);51}52};53```54Configure: Zaraz > Settings > Context Enrichers5556**Worker Variables** - Compute dynamic values server-side, use as `{{worker.variable_name}}`.5758## GTM Migration5960| GTM | Zaraz |61|-----|-------|62| `dataLayer.push({event: 'purchase'})` | `zaraz.ecommerce('Order Completed', {...})` |63| `{{Page URL}}` | `{{system.page.url}}` |64| `{{Page Title}}` | `{{system.page.title}}` |65| Page View trigger | Pageview trigger |66| Click trigger | Click (selector: `*`) |6768## Best Practices69701. Use dashboard triggers over inline code712. Enable History Change for SPAs (no manual code)723. Debug with `zaraz.debug = true`734. Implement consent early (GDPR/CCPA)745. Use Context Enrichers for sensitive/server data75