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

# Consent and scripts

> Inject tracking scripts and gate them on the visitor's consent.

`ReploScripts` injects managed scripts and gates each one on consent. You edit the script array, and never hand-write `<script>` tags for managed scripts.

## `consent/replo-scripts`

`@replohq/sdk/consent/replo-scripts`

#### `ReploScripts`

The single registry component for all managed tracking scripts on the site. Authored once in `app/layout.tsx`; the agent/miniapp only edit the `scripts` array. Each entry registers itself and is gated + injected per consent.

A consent-platform entry (`Cookiebot`, or a generic `consentPlatform`) takes over consent site-wide: scripts carry the platform's blocking attributes, its loader injects after them so its startup scan sees the full set, and Replo's own gates follow the platform instead of the native banner.

```ts theme={null}
import { ReploScripts } from "@replohq/sdk/consent/replo-scripts";
```

```ts theme={null}
ReploScripts: ({ scripts }: { scripts: ReploScriptEntry[]; }) => JSX.Element
```

**Also exported**

| Export           | Kind      | Type                    |
| ---------------- | --------- | ----------------------- |
| `InjectedScript` | component | `typeof InjectedScript` |

## `consent/consent-store`

`@replohq/sdk/consent/consent-store`

#### `ConsentState`

Framework-agnostic, cookie-backed consent store. Lives as a single module singleton so `ReploScripts`, the site's consent banner, and `AnalyticsProvider` all share the same state regardless of where they sit in the React tree — no provider-ancestor relationship is required.

Consent-dependent work (script injection, banner visibility) happens on the client (effects / post-mount), so there is no SSR/hydration mismatch. The client reads the (non-httpOnly) consent cookie directly, so no server seed is needed. The whole-site `mode` comes from the `data-replo-consent-mode` attribute on `<html>`.

```ts theme={null}
import type { ConsentState } from "@replohq/sdk/consent/consent-store";
```

| Field        | Type                                   | Required | Description                                                                                                                                                                                   |
| ------------ | -------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `categories` | `ConsentCategories`                    | Yes      |                                                                                                                                                                                               |
| `cmp`        | `"replo" \| "cookiebot" \| "external"` | No       | Which platform owns consent. Absent means Replo's native banner; "external" is a generic `consentPlatform` entry.                                                                             |
| `consentId`  | `string`                               | No       | Persistent pseudonymous per-browser id linking a visitor's consent history. Absent until the first `commit()` (and on legacy pre-id cookies, until the next interaction lazily backfills it). |
| `decidedAt`  | `number`                               | Yes      | Epoch ms when the visitor last made a choice, or null if undecided.                                                                                                                           |
| `mode`       | `ConsentMode`                          | Yes      |                                                                                                                                                                                               |

#### `isConsentAllowed`

Whether a script requiring `requiredConsent` may load now. `mode === "off"` allows everything only under Replo's banner; a delegated CMP answers instead.

```ts theme={null}
import { isConsentAllowed } from "@replohq/sdk/consent/consent-store";
```

```ts theme={null}
isConsentAllowed: ({ state, requiredConsent, }: { state: ConsentState; requiredConsent: ConsentCategory[]; }) => boolean
```

**Also exported**

| Export              | Kind     | Type                                                                                                                                                                                                                                                                                                                                                         |
| ------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `consentStore`      | function | `{ getSnapshot(): ConsentState; getServerSnapshot(): ConsentState; subscribe(listener: () => void): () => void; accept(options?: { policyVersion?: number; }): void; reject(options?: { policyVersion?: number; }): void; updateCategories({ next, policyVersion, }: { next: Partial<ConsentCategories>; policyVersion?: number; }): void; reset(): void; }` |
| `useConsent`        | hook     | `(options?: UseConsentOptions) => UseConsentResult`                                                                                                                                                                                                                                                                                                          |
| `UseConsentOptions` | type     | `{ version?: number }`                                                                                                                                                                                                                                                                                                                                       |
| `UseConsentResult`  | type     | `{ accept: () => void; categories: ConsentCategories; cmp?: "replo" \| "cookiebot" \| "external"; consentId?: string; decidedAt: number; mode: ConsentMode; reject: () => void; updateCategories: (next: Partial<ConsentCategories>) => void }`                                                                                                              |

## `consent/types`

`@replohq/sdk/consent/types`

**Exports**

| Export                | Kind | Type                                                                                                                                                                                                                                                                  |
| --------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ConsentCategory`     | type | `"necessary" \| "analytics" \| "marketing" \| "preferences" \| "sale_of_data"`                                                                                                                                                                                        |
| `ConsentMode`         | type | `"off" \| "simple" \| "per-category"`                                                                                                                                                                                                                                 |
| `ReploScriptEntry`    | type | —                                                                                                                                                                                                                                                                     |
| `ReploScriptType`     | type | `"GA4" \| "GoogleTagManager" \| "Meta" \| "TikTok" \| "Pinterest" \| "Reddit" \| "Snapchat" \| "Hotjar" \| "MicrosoftClarity" \| "Contentsquare" \| "Segment" \| "Northbeam" \| "Gorgias" \| "Converge" \| "Cookiebot" \| "snippet" \| "custom" \| "consentPlatform"` |
| `ScriptTagDescriptor` | type | `{ kind: "external"; src: string; attributes?: { [x: string]: string; }; } \| { kind: "inline"; body: string; }`                                                                                                                                                      |
