Managed Components docs are published at https://managedcomponents.dev .
Find out more about Managed Components here for inspiration and motivation details.
- Make sure you're running node version >=18.
- Install dependencies with
pnpm i - Run unit test watcher with
pnpm run test:dev
Use the bundled Web Components Manager to exercise the component against either a local fixture or a live site.
pnpm run dev:webcmBy default, WebCM reads webcm.config.ts for permissions, settings, and proxy target. Tweak the settings block to match the properties you expect inside Zaraz (for example, set the hostname, autoCollect, or collectDnt flags). To proxy a live site or pass ad-hoc settings from the command line:
# Proxy https://example.com while injecting the local component
pnpm run dev:webcm:proxy
# Override the target/settings on the fly
pnpm run dev:webcm -- https://your-site.com --settings_hostname=your-site.com --settings_collectDnt=trueWebCM will expose the proxied site on the host/port defined in the config (defaults to http://localhost:1337).
Settings are used to configure the tool in a Component Manager config file
exampleSetting can be the pixelID or any other essential/optional setting like the option to anonymize IPs, send ecommerce events etc.
Fields are properties that can/must be sent with certain events
field_id give it a short description and send to a more detailed reference Find more about how to create your own Managed Component.
-
Authenticate with your Cloudflare account (interactive browser login):
pnpm run cf:login
-
Build and deploy the managed component as a Worker:
pnpm run cf:deploy
This script runs the local bundle and then invokes
managed-component-to-cloudflare-workerwith the compiled file indist/index.js. Before the first deploy, editwrangler.tomland replaceYOUR_ACCOUNT_IDwith the Cloudflare account that should own the Worker. The script publishes the Worker ascustom-mc-simple-analytics. -
(Optional) Publish directly with Wrangler if you prefer:
pnpm run cf:publish
Wrangler will execute the
pnpm run bundlecommand declared inwrangler.tomlbefore pushing the Worker.
In the Cloudflare dashboard navigate to Zaraz → Tools configuration → Add new tool → Custom Managed Component, pick custom-mc-simple-analytics, assign the same permissions you configured locally, and populate the settings. Afterwards wire the component up to your triggers and actions (pageview, event, custom events, etc.).
Enable Zaraz Preview & Publish. Then, inside the site’s DevTools console, run:
zaraz.preview('<YOUR_DEBUG_KEY>');Preview mode limits the rollout to sessions with the debug key and exposes detailed telemetry in the browser console. Combine it with Zaraz’ Debug mode or the network panel to inspect emitted events before publishing changes to production traffic.
For automated deployments you can connect the Worker in the Cloudflare dashboard to your Git repo (Workers Builds) or add a GitHub Action that runs pnpm run bundle followed by wrangler publish. See Cloudflare Workers CI/CD docs and the Wrangler Action marketplace listing for ready-to-use templates.
Licensed under the Apache License.