MonetizationOS powers monetization for human and bot users alike. Use this Cloudflare Worker to proxy your website and integrate MonetizationOS Surfaces, enabling seamless monetization experiences for sites served with static HTML.
This worker includes handling for both HTTP response modification and CSS-targeted Components for content modifications including: removal/truncation, displaying offerings, and custom messaging.
Read more about using MonetizationOS at docs.monetizationos.com.
Click deploy to Cloudflare to get started or fork this repo to customize it for your needs.
This worker requires the following environment variables to be set in your Cloudflare configuration:
MONETIZATION_OS_SECRET_KEY: Your MonetizationOS secret key. Get your secret key.ORIGIN_URL: The origin URL for your proxied website.SURFACE_SLUG: The slug for the MonetizationOS surface you want to target.AUTHENTICATED_USER_JWT_COOKIE_NAME: Cookie name for authenticated user JWT sessions.ANONYMOUS_SESSION_COOKIE_NAME: Cookie name for anonymous sessions.
Bindings should be set in your wrangler.jsonc, or a .dev.vars.local file when working locally.
ORIGIN_REQUEST_HEADERS adds or overrides outgoing headers on every upstream fetch to ORIGIN_URL. Set it to a JSON object mapping header names to values. Leave it as {} when no extra headers are needed.
In wrangler.jsonc vars:
In the Cloudflare dashboard, the variable supports JSON input directly.
npm run dev— Start local development using Wrangler.npm run deploy— Deploy the worker to Cloudflare.npm test— Run tests with Vitest.npm run cf-typegen— Generate Cloudflare type definitions.npm run lint— Run lint checks with Biome.
- Install dependencies:
npm install
- Start the development server:
npm run dev
Deploy to Cloudflare with:
npm run deploy