=== Zbridge - Integration for Cloudflare Zaraz ===
Contributors: wpzbridgecom
Tags: cloudflare, zaraz, analytics, woocommerce, tracking
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Enterprise-grade Cloudflare Zaraz server-side tracking, zero-loss WooCommerce conversion recovery, and Google Consent Mode v2 for WordPress.

== Description ==

Stop losing 15% to 30% of your store's sales attribution to ad blockers, iOS Safari privacy restrictions, and early-closed checkout tabs.

**WP Zbridge** shifts third-party marketing pixels and tracking scripts away from your visitors' devices and runs them directly on **Cloudflare Zaraz** across 330+ cities worldwide.

### Why WP Zbridge?

* **⚡ 100/100 Google Core Web Vitals**: Replaces hundreds of kilobytes of heavy third-party JavaScript (Meta Pixel, GA4 gtag.js, TikTok, Snapchat) with a tiny vanilla JavaScript bridge under 4KB.
* **🛡️ E-Commerce Tracking**: Clean client-side WooCommerce event tracking for GA4 and Meta Pixel (upgrade to Pro for server-side Zero-Loss Conversion Recovery and closed-tab order rescue).
* **🪄 4-Step Setup Wizard**: Quickly configure Cloudflare Zaraz, select your marketing channels, customize consent, and get running in under 2 minutes.
* **☁️ Pre-Configured Zaraz Container Export**: Export ready-to-import JSON configurations for GA4 and Meta Pixel directly from your WordPress admin with zero API credentials required (or use Pro for automated 1-Click Cloudflare REST API Edge Deploy).
* **🍪 Built-in Cookie Scanner & Banner**: Scan your site in 1 click to discover and categorize cookies (Essential, Analytics, Marketing). Includes an accessible cookie banner under 2KB, reopen settings badge, and visual style customizer.
* **🔒 Google Consent Mode v2**: Full support for `ad_storage`, `analytics_storage`, `ad_user_data`, and `ad_personalization` with automated CMP detection (Complianz, Cookiebot, CookieYes, and WP Consent API).
* **🛒 Advanced WooCommerce Funnels**: Track AddToCart, ViewContent, Cart Removals, Coupons, Variation Selections, Unsubmitted Searches, and External Links.

### Included Zaraz Recipes Catalog

1. **Google Analytics 4 (GA4)**: Full e-commerce funnel mapping (`page_view`, `view_item`, `add_to_cart`, `purchase`, `refund`).
2. **Meta Pixel & Conversions API (CAPI)**: Client-side event tracking with SHA-256 PII hashing. Includes automated Parent ID mapping for variable products to prevent Facebook Catalog errors.
3. **Google Ads Enhanced Conversions** *(Pro)*: Cross-device conversion modeling with privacy-hashed customer data.
4. **TikTok Events API** *(Pro)*: Video ad attribution and complete purchase tracking.
5. **Snapchat Pixel & CAPI** *(Pro)*: Full e-commerce event pipeline for Snapchat ad campaigns.
6. **Pinterest Tag & CAPI** *(Pro)*: Rich visual discovery ad tracking.
7. **Microsoft Advertising (Bing UET)** *(Pro)*: Search network conversion attribution.

== Installation ==

1. Upload the `zbridge` folder to the `/wp-content/plugins/` directory, or install the ZIP file via **Plugins > Add New > Upload Plugin** in your WordPress dashboard.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. The **Setup Wizard** will launch automatically to guide you through connecting Cloudflare Zaraz.
4. Choose your marketing channels in the Setup Wizard and export your pre-configured Zaraz container JSON to import into Cloudflare (or connect your Cloudflare API token in Pro for automated 1-click sync).

== Frequently Asked Questions ==

= Do I need a paid Cloudflare account? =
No! Cloudflare Zaraz has a generous free tier that includes up to 100,000 events/month at zero cost. WP Zbridge works on both free and enterprise Cloudflare plans.

= How does Conversion Recovery work without duplicating orders? =
Both the browser and the WordPress server send the exact same WooCommerce `event_id` and `transaction_id`. Cloudflare Zaraz and ad platforms (Meta, Google, Snapchat) match these IDs and record the sale exactly once, ensuring 100% order capture even if the customer closes their browser early.

= Will this replace my existing tracking or pixel plugins? =
Yes. WP Zbridge allows you to deactivate heavy client-side tracking plugins because all tracking moves to Cloudflare's global edge network.

= How does the Cookie Scanner work? =
Navigate to **WP Zbridge > Consent & Privacy > Cookie Scanner** and click **Scan Site for Cookies & Trackers**. The plugin audits your homepage and scripts, categorizing cookies into Essential, Analytics, Marketing, and Functional without needing expensive external SaaS tools.

== External services ==

This plugin integrates with external services to deploy analytics configurations and process tracking events.

* **Cloudflare Zaraz & Cloudflare API (`api.cloudflare.com`)**:
    * **What it is:** Server-side tracking execution engine at the edge and REST API for container provisioning.
    * **What data is sent & when:** When an administrator enters credentials and clicks Deploy to Zaraz Edge or Sync with Cloudflare, container configuration is sent to the Cloudflare API. When site visitors browse with granted consent, anonymized tracking events are routed through Cloudflare Zaraz.
    * **Service Provider:** Cloudflare, Inc.
    * **Terms of Service:** https://www.cloudflare.com/terms/
    * **Privacy Policy:** https://www.cloudflare.com/privacypolicy/

* **Google Analytics & Google Tag Manager**:
    * **What it is:** Web analytics platform configured via pre-built Zaraz recipes and audited by the local Cookie & Tracker Scanner.
    * **What data is sent & when:** Client-side and edge-routed e-commerce events (such as page views, item views, and purchases) are sent only when site visitors grant analytics consent.
    * **Service Provider:** Google LLC
    * **Terms of Service:** https://marketingplatform.google.com/about/analytics/terms/us/
    * **Privacy Policy:** https://policies.google.com/privacy

* **Meta (Facebook Pixel & Conversions API)**:
    * **What it is:** Advertising attribution and conversion tracking configured via Zaraz recipes and audited by the local Cookie & Tracker Scanner.
    * **What data is sent & when:** Conversion and purchase events with hashed customer parameters are sent only when site visitors grant marketing consent.
    * **Service Provider:** Meta Platforms, Inc.
    * **Terms of Service:** https://www.facebook.com/legal/terms
    * **Privacy Policy:** https://www.facebook.com/privacy/policy/

== Screenshots ==

1. Setup Wizard: 4-step onboarding to connect Cloudflare Zaraz and configure recipes in minutes.
2. Tracking & Recovery Dashboard: Real-time telemetry showing rescued orders, saved revenue, and edge traffic statistics.
3. Zaraz Recipes Catalog: Pre-configured recipes for GA4 and Meta, with 5 additional channels in Pro.
4. Cookie Scanner & Consent Management: Built-in scanner, GDPR compliant banner, and Google Consent Mode v2.

== Changelog ==

= 1.2.9 =
* Fix: Full compliance with WordPress.org Plugin Directory guidelines (brand display name updated to Zbridge - Integration for Cloudflare Zaraz).
* Security: Whitelisted and JSON-serialized Google Consent Mode v2 default configuration to eliminate unescaped string interpolation.
* Security: Added unslashing and sanitization for Cloudflare country headers (HTTP_CF_IPCOUNTRY) and escaped privacy dropdown outputs.
* Improvement: Eliminated raw inline script and style tags across admin templates, migrating assets to registered stylesheets and scripts.
* Improvement: Excluded repository banners and icons from release archives.
* Documentation: Standardized external services disclosure covering Cloudflare Zaraz, Google Analytics, and Meta Pixel.

= 1.2.8 =
* Feature: Cloudflare Edge Geo-Targeting automatically detects 32 European jurisdictions (EU/EEA/UK/CH) to grant consent and eliminate banner fatigue outside Europe.
* Feature: Early Google Consent Mode v2 initialization injected synchronously in head with returning visitor cookie detection.
* Feature: Granular cookie preferences modal dialog with 4 accessible category controls (Strictly Necessary, Analytics, Marketing, Functional).
* Feature: Visual theming controls supporting Auto (OS dark/light preference), Light, and Dark modes with custom color overrides.
* Feature: Privacy policy page integration with dynamic permalink resolution and custom link text.
* Improvement: Full WordPress Coding Standards prefix compliance for slug zbridge across all globals and constants.

= 1.2.7 =
* Fix: Differentiate Pro and Lite plugin titles in WordPress admin plugins list.
* Fix: Prevent plugin collision with automatic mutual exclusion and auto-deactivation.
* Feature: Added visual PRO EDITION and LITE EDITION badges to plugin row meta in plugins list.
* Feature: Added public edge Lite release streaming via Cloudflare R2 storage.

= 1.2.6 =
* Improvement: Added visual tab icons across all administration settings tabs for improved navigation.
* Improvement: Hardened Cloudflare REST API synchronization routines and connection testing with robust credential validation.
* Improvement: Enhanced connection mode validation and automatic manual fallback handling.
* Improvement: Updated Wrangler configuration across all deployment targets with structured edge observability and logs persistence.

= 1.2.5 =
* Improvement: Expanded admin navigation to 7 focused tabs with enhanced visual spacing and breathing room.
* Feature: Dedicated tabs for Cloudflare connection settings, Zaraz recipes catalog, diagnostics, and settings.
* Improvement: Direct navigation linking from Dashboard telemetry to settings.
* Improvement: Clean package separation and distribution archive optimization.

= 1.2.4 =
* Feature: User engagement tracking suite including active time on page milestones, scroll depth, and email/tel links.
* Feature: Lead form submission tracking for Contact Form 7, WPForms, Gravity Forms, Fluent Forms, Elementor Forms, and generic HTML forms.
* Feature: User lifecycle tracking for logins, user registrations, and WordPress comments.
* Feature: High-contrast dark telemetry terminal dashboard with live server-side event dispatcher stream.
* Improvement: Modernized admin segmented tab navigation with single-line track and elevated active tab styling.
* Improvement: Standardized distribution archives to zbridge.zip and zbridge-pro.zip.

= 1.2.3 =
* Feature: Setup Wizard auto-hide upon completion to maintain a clean admin sidebar, with instant relaunch controls on Dashboard and Diagnostics.
* Feature: License deactivation mechanism allowing domain transfers by releasing site slots on the edge registry.
* Improvement: Added comprehensive visual walkthrough screenshots across developer documentation.
* Improvement: Enhanced Cloudflare build and preview configuration compatibility.

= 1.2.2 =
* Feature: Live Edge Handshake Verifier with real-time Anycast latency testing and Cloudflare PoP airport code detection.
* Feature: Manual and offline WooCommerce order attribution dispatch via WooCommerce Order Actions for phone and B2B orders.
* Improvement: Enhanced edge payload delivery and payload sanitization routines.
* Improvement: Optimized script asset enqueueing and diagnostic telemetry precision.

= 1.2.1 =
* Feature: Automated 1-click Cookie & Tracker Scanner.
* Feature: 4-Step Setup Wizard for initial onboarding.
* Feature: Reopen consent box floating badge for GDPR compliance.
* Feature: Live Cloudflare edge traffic stats on Dashboard.
* Feature: Added Snapchat Pixel & Conversions API Zaraz recipe.
* Feature: Added Parent ID option for WooCommerce variations (prevents Meta Catalog errors).
* Feature: Track variant selection events on single product pages.
* Feature: Track payment info entered during checkout.
* Feature: Track unsubmitted searches, search autocomplete selections, and external links.
* Feature: Exclude logged-in store staff and administrators from analytics.
* Fix: Resolved admin route aliases and added browser cache-busting for admin scripts.

= 1.2.0 =
* Initial release of WP Zbridge with hybrid zero-loss conversion recovery and Cloudflare Zaraz 1-click edge sync.
