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/api.md
1# Zaraz Web API23Client-side JavaScript API for tracking events, setting properties, and managing consent.45## zaraz.track()67```javascript8zaraz.track('button_click');9zaraz.track('purchase', { value: 99.99, currency: 'USD', item_id: '12345' });10zaraz.track('pageview', { page_path: '/products', page_title: 'Products' }); // SPA11```1213**Params:** `eventName` (string), `properties` (object, optional). Fire-and-forget.1415## zaraz.set()1617```javascript18zaraz.set('userId', 'user_12345');19zaraz.set({ email: '[email protected]', plan: 'premium', country: 'US' });20```2122Properties persist for page session. Use for user identification and segmentation.2324## zaraz.ecommerce()2526```javascript27zaraz.ecommerce('Product Viewed', { product_id: 'SKU123', name: 'Widget', price: 49.99 });28zaraz.ecommerce('Product Added', { product_id: 'SKU123', quantity: 2, price: 49.99 });29zaraz.ecommerce('Order Completed', {30order_id: 'ORD-789', total: 149.98, currency: 'USD',31products: [{ product_id: 'SKU123', quantity: 2, price: 49.99 }]32});33```3435**Events:** `Product Viewed`, `Product Added`, `Product Removed`, `Cart Viewed`, `Checkout Started`, `Order Completed`3637Tools auto-map to GA4, Facebook CAPI, etc.3839## System Properties (Triggers)4041```42{{system.page.url}} {{system.page.title}} {{system.page.referrer}}43{{system.device.ip}} {{system.device.userAgent}} {{system.device.language}}44{{system.cookies.name}} {{client.__zarazTrack.userId}}45```4647## zaraz.consent4849```javascript50// Check51const purposes = zaraz.consent.getAll(); // { analytics: true, marketing: false }5253// Set54zaraz.consent.modal = true; // Show modal55zaraz.consent.setAll({ analytics: true, marketing: false });56zaraz.consent.set('marketing', true);5758// Listen59zaraz.consent.addEventListener('consentChanged', () => {60if (zaraz.consent.getAll().marketing) zaraz.track('marketing_consent_granted');61});62```6364**Flow:** Configure purposes in dashboard → Map tools to purposes → Show modal/set programmatically → Tools fire when allowed6566## zaraz.debug6768```javascript69zaraz.debug = true;70zaraz.track('test_event');71console.log(zaraz.tools); // View loaded tools72```7374## Cookie Methods7576```javascript77zaraz.getCookie('session_id'); // Zaraz namespace78zaraz.readCookie('_ga'); // Any cookie79```8081## Async Behavior8283All methods fire-and-forget. Events batched and sent asynchronously:8485```javascript86zaraz.track('event1');87zaraz.set('prop', 'value');88zaraz.track('event2'); // All batched89```9091## TypeScript Types9293```typescript94interface Zaraz {95track(event: string, properties?: Record<string, unknown>): void;96set(key: string, value: unknown): void;97set(properties: Record<string, unknown>): void;98ecommerce(event: string, properties: Record<string, unknown>): void;99consent: {100getAll(): Record<string, boolean>;101setAll(purposes: Record<string, boolean>): void;102set(purpose: string, value: boolean): void;103addEventListener(event: 'consentChanged', callback: () => void): void;104modal: boolean;105};106debug: boolean;107tools?: string[];108getCookie(name: string): string | undefined;109readCookie(name: string): string | undefined;110}111declare global { interface Window { zaraz: Zaraz; } }112```113