The Greenstead Marketing Infrastructure
I engineered a privacy-first server-side attribution and conversion pipeline for a direct-booking hospitality operation, running on a custom Cloudflare Worker backed by a Cloudflare D1 SQL state machine. It links consented campaign parameters to finalized reservations and dispatches verified Purchase events to Meta Conversions API and GA4 without storing personal contact or payment data.

The Challenge
Measurement broke in the handoff between the WordPress content sites and the Hospitable direct booking engine. Safari ITP, ad blockers, and cross-domain storage boundaries severed campaign attribution before a reservation was ever recorded, and duplicate checkout fires inflated the conversions that did survive. The client-side tag layer could not be trusted to report what it had actually sold.
The Solution
I moved conversion ownership off the browser and onto the edge. A custom Cloudflare Worker writes consented GTM UTM parameters against Hospitable quote UUIDs in a Cloudflare D1 SQL state machine, then resolves them to finalized reservation IDs with no personal contact or payment PII in storage. I ingest asynchronous Hospitable webhooks with HMAC signature verification and a 48-hour out-of-order retry window, then dispatch server-to-server Purchase events to Meta Conversions API and GA4 using deterministic Event IDs so browser and server signals deduplicate against each other.
The Results
Conversion reporting now originates from verified server-side reservation data rather than browser tags, with a custom Google Consent Mode v2 template sending anonymous cookieless pings when marketing consent is withheld and a WordPress MU-plugin suppressing logged-in admin traffic. The pipeline ships behind Vitest unit and migration suites plus Playwright live-tag audits, so every deployment is validated against real runtime tag behavior.
An Edge State Machine on Cloudflare Workers and D1
I built this direct-booking hospitality operation a measurement layer that runs at the edge rather than in the browser. A custom Cloudflare Worker receives consented UTM parameters from Google Tag Manager at the start of checkout and writes them to a Cloudflare D1 SQL database, keyed to the Hospitable quote UUID issued for that session. When the booking completes, the Worker links that quote UUID to the finalized reservation ID, closing the loop between a campaign click and a confirmed stay.
The D1 schema is deliberately narrow: it holds attribution context and booking identifiers, and no personal contact or payment data ever enters the store. Hospitable posts reservation webhooks asynchronously, so the Worker verifies each payload's HMAC signature before acting on it, then holds unmatched records inside a 48-hour retry window. That window exists because webhooks and client-side confirmations routinely arrive out of order, and I wanted the state machine to resolve the match rather than discard the event.
Consent Governance Built Into the Tag Layer
Privacy decisions are enforced before any tag fires. I wrote a custom Google Tag Manager template implementing Google Consent Mode v2, so the visitor's choice across essential, analytics, and marketing categories governs what the Worker is allowed to receive. Where marketing consent is withheld, the site sends anonymous cookieless pings instead, which preserves aggregate traffic measurement while keeping identifiers out of the pipeline entirely.
Internal activity distorts small-volume booking data quickly, so a WordPress MU-plugin suppresses measurement for logged-in administrators across the content sites. Combined with the consent template, that gives the operator a defensible record of what was collected, under which permission, and from whom.
Deterministic Event IDs and Automated Tag Verification
Verified reservations dispatch Purchase events server-to-server to the Meta Conversions API and GA4. Each event carries a deterministic Event ID derived from the reservation, so any browser-side signal that does reach the platforms collapses into the same conversion instead of inflating revenue. This matters in a setup where visitors cross from WordPress content sites into the Hospitable booking engine, and where Safari ITP, ad blockers, cross-domain drops, and repeated checkout fires all distort client-side counts.
The infrastructure ships with its own test discipline. Vitest suites cover the Worker's unit logic and the D1 migrations, and Playwright audits run against live endpoints to confirm which tags fire under each consent state. Measurement code fails quietly when left unchecked, so I treat these runs as a release gate rather than an optional step.
Project Gallery
Need similar work?
Send the project details in writing and I will reply with the next steps.
Send Project Brief