Skip to main content
Zero dependencies; runs in any JS runtime with fetch (browser, Node, edge, workers).

Install

Usage

getAd resolves to RevinelAd | null; getAds to RevinelAd[] (empty when nothing is eligible; the SDK never throws on “no ads”).

Typed creative (meta)

ad.meta is keyed by each custom field’s stable machine slug (set when the publisher creates the field, e.g. bannerImage for a “Banner image” field). Pass your own interface for typesafe access:
Renaming a field’s display label never changes its slug, so your code keeps working.

Next.js / caching

Ad fetches default to next: { revalidate: 60 }, so App Router pages that call getAd/getAds stay statically renderable while the ad still refreshes every minute. (Revinel’s API edge-caches responses for ~5s anyway, so per-request rotation was always approximate.) Non-Next runtimes ignore the next key: server fetches (Node/edge) stay uncached, while browsers honor the response Cache-Control (max-age=5) and may reuse an identical request for up to ~5s, the same window the API’s edge cache already imposes. Opt out for true per-request rotation (on an already-dynamic Next page, or anywhere else):
Any explicit cache or next.revalidate you pass replaces the default entirely.
In Next.js server components, don’t wrap getAd in a try/catch that swallows every error. Errors carrying a digest property (e.g. DYNAMIC_SERVER_USAGE) are Next.js control flow, so rethrow them:

Checkout

Start a Stripe Checkout session for a tier price and send the visitor to its url:
metadata is written to both the Stripe Checkout session and the subscription on your connected Stripe account. The subscription keeps it, so every renewal invoice carries it too. Values must be strings. You can send up to 47 keys (Stripe allows 50 and Revinel uses 3), each key up to 40 characters and each value up to 500 characters. Keys cannot contain square brackets. The keys workspaceId, tierId and tierPriceId are reserved for Revinel. A request that uses one of them or breaks a limit answers 422 and creates no session. Revinel does not store your metadata.

Local development

On a page served from a local or private host, recordImpression and recordClick send no request and resolve to { success: false }. The Revinel API ignores those events, so your own testing stays out of the stats advertisers see. A client pointed at a local Revinel API still sends them. isLocalHostname(hostname) is the check the SDK and the API both use. It is exported if you want to apply the same rule elsewhere:

Errors

Non-2xx responses throw RevinelApiError ({ status, body }). The body is the Revinel API error envelope:
Input-validation failures use HTTP 422 with code: "INPUT_VALIDATION_FAILED" and a data.fieldErrors / data.formErrors map. For React bindings see revinel/react.