> ## Documentation Index
> Fetch the complete documentation index at: https://docs.festtide.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Runtime JS API

> window.Festtide, its events and error codes.

The script tag installs `window.Festtide`. Use it to react to campaigns (for example in your own
analytics), to pass consent, or to remove everything from a page.

```ts theme={null}
interface FesttideRuntime {
  /** The runtime's version, e.g. "1.0.3". */
  readonly version: string
  /** Resolves after the first render decision, or after the 1.5 s give-up. Never rejects. */
  readonly ready: Promise<void>
  /** Listens to an event; returns a function that stops listening. */
  on(event: RuntimeEventName, handler: (detail: RuntimeEventDetail) => void): () => void
  /** Consent for counting (views, clicks). Rendering never needs consent. */
  consent(granted: boolean): void
  /** Campaign ids live on this page right now. */
  active(): string[]
  /** Removes everything the runtime added to the page, until the next page load. */
  pause(): void
}

type RuntimeEventName =
  | "ready"
  | "campaign:start"
  | "campaign:end"
  | "banner:view"
  | "banner:click"
  | "banner:dismiss"
  | "offer:copy"
  | "error"

interface RuntimeEventDetail {
  campaignId?: string
  /** For "error": a short code. */
  code?: string
}
```

The script loads asynchronously, so `window.Festtide` may not exist yet when your own code runs.
Check for it first, as in the examples below.

## Properties and methods

### `version`

The runtime's version string. Useful in bug reports.

### `ready`

A promise that resolves once the runtime has decided what to render on this page, or after it gives
up at 1.5 seconds. It never rejects, so you can always `await` it.

```js theme={null}
await window.Festtide?.ready
console.log(window.Festtide?.active())
```

### `on(event, handler)`

Calls `handler` with a detail object every time `event` happens. Returns a function that removes
the handler.

```js theme={null}
const off = window.Festtide?.on("banner:click", ({ campaignId }) => {
  myAnalytics.track("campaign_banner_click", { campaignId })
})

// Later, to stop listening:
off?.()
```

### `consent(granted)`

Tells the runtime whether it may count views and clicks. Rendering never needs consent. See
[Consent](https://docs.festtide.com/consent.md).

### `active()`

The ids of the campaigns live on this page right now. Empty when nothing is live, when the page is
excluded, or after `pause()`.

### `pause()`

Removes everything the runtime added to the page (banner, effect, theme colours) until the next
page load. To stop campaigns on every page for every visitor, use **Pause everywhere** in the
dashboard instead.

## Events

| Event | When | Detail |
| - | - | - |
| `ready` | The first render decision is made, or the runtime gave up. | – |
| `campaign:start` | A campaign starts rendering on the page. | `campaignId` |
| `campaign:end` | A campaign stops rendering (its window ended, or `pause()`). | `campaignId` |
| `banner:view` | A banner is shown. | `campaignId` |
| `banner:click` | The banner's button is clicked. | `campaignId` |
| `banner:dismiss` | The visitor closes the banner. | `campaignId` |
| `offer:copy` | The visitor copies the offer code. | `campaignId` |
| `error` | Something stopped the runtime; your page is shown as is. | `code` |

## Error codes

Every error fails open: the visitor sees your normal page, and the last good timeline is kept for
the next page load.

| Code | Meaning |
| - | - |
| `fetch-timeout` | The timeline did not arrive within 1.5 seconds. |
| `bad-signature` | The timeline's signature did not verify, so it was ignored. |
| `unknown-key` | The timeline was signed with a key this runtime does not know. Update the plugin, or copy the current script tag from the dashboard. |
| `expired` | The timeline is past its expiry date. It is republished automatically; contact support if this persists. |
| `bad-json` | The response could not be read. |
| `blocked` | The request was blocked, for example by a Content Security Policy or a content blocker. |

```js theme={null}
window.Festtide?.on("error", ({ code }) => {
  console.warn("Campaigns not shown:", code)
})
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.