---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/messaging/compliance/compliance-embed/overview#article
headline: Embed compliance registration in your app
description: To help your customers complete self-service registration and verification, embed our Compliance Embed into your web app.
url: https://www.twilio.com/docs/messaging/compliance/compliance-embed/overview
inLanguage: en
dateModified: 2026-12-01T17:31:10.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Embed compliance registration in your app

> \[!IMPORTANT]
>
> Compliance Embed is at a different release stage for each program. Toll-Free Verification and Secondary Customer Profiles are Public Beta. US A2P 10DLC and Regulatory Compliance Bundles are Private Beta. The information contained in this document is subject to change. Some features are not yet implemented and others may be changed before a program is declared as Generally Available. See each program's guide for its current release stage.

To use the Compliance Embeddable API, request [access][].

[access]: https://airtable.com/appBN6pqe3FSiF3n1/pagHTtSzxycNarq8Z/form

With global regulatory requirements frequently changing across jurisdictions, navigating compliance is an expensive, ongoing challenge. While maintaining internal compliance tooling consumes significant engineering resources, complex requirements lead to customer confusion and registration drop-offs. To address these challenges, Compliance Embed shifts development and regulatory management burden away from your team.

While Twilio manages the underlying registration workflow infrastructure, your end customers can manage their registration and verification requests.

To allow the end customers of an *Independent Software Vendor* (ISV) to comply with regulations, Twilio provides the Compliance Embed solution. The Compliance Embed provides an unbranded, self-service solution designed to integrate seamlessly into an ISV-hosted web app.

To create this self-service experience, ISVs complete the following activities:

1. From their servers, the ISV calls the Twilio ComplianceInquiry Initialize API resource. This returns a session token and session ID.
2. In their web app, the ISV creates a React component or JavaScript instance that renders a form in an `iframe` tag. This form connects to the compliance inquiry in Twilio through the ID and token.
3. The end customer completes and submits their compliance request through the ISV web app.
4. If it succeeds, the end customer can send messages. If it fails, the end customer can, in most cases, resubmit their request through the ISV's web app.

Compliance Embed can use your branding. Twilio manages the compliance logic and regulatory question flows, but you can match the end-user experience to match your brand design, typography, and color palette. Custom themes require [Twilio support][theme request form].

## How the Compliance Embed works

To deploy Compliance Embed, complete two activities:

1. [**Start a compliance session**](#server). To initialize a ComplianceInquiry, make a request to Twilio's API. The response includes a session ID and a session token. The endpoint and request parameters differ per program, so you need to refer to the guide for your program.
2. [**Add a compliance form to your app**](#client). Embed the form using the React or JavaScript SDK, passing the session ID and session token. This process works the same for every program.

## Prerequisites

Before you begin, complete the following tasks:

1. [Create a paid Twilio account][paid-account], if needed. You can't use a trial account.
2. Get an [approved Trust Hub Primary Customer Profile][primary-profile] in the [Twilio Console][1console-primary] with a **Business Identity** of **ISV or Reseller**.
3. Add [Persona][] to the allow list on your firewall. To manage compliance, Twilio uses this service.
4. Create a [*Content Security Policy* (CSP)][csp] for your web app as another layer of security.

[1console-primary]: https://1console.twilio.com/go?to=/account/__account__/us1/trusthub/compliance-profiles/primary

[paid-account]: https://www.twilio.com/try-twilio

[primary-profile]: /docs/messaging/compliance/toll-free/api-onboarding#create-a-trust-hub-primary-customer-profile

[Persona]: http://www.withpersona.com

[csp]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP

## Authenticate with Twilio API \[#api-auth]

You must authenticate all requests using Twilio's [REST API credentials][api-auth] with HTTP Basic Auth.

* Use your account SID as the username and your token as the password.
* The account SID can be either your primary Twilio Account SID or a subaccount SID.

[api-auth]: /docs/iam/credentials/api

The registration binds to the Account SID you provided in the credentials after completion of the ComplianceInquiry.

## Initiate a compliance session \[#server]

To initiate a compliance session, make an HTTPS `POST` request for the compliance program that needs approval:

* [Toll-Free Verification][]
* [US A2P 10DLC][]
* [Secondary Customer Profiles][]
* [Regulatory Compliance Bundles][]

To expedite compliance registration, you can pre-populate customer entity data during initialization.

The Initialize ComplianceInquiry resource for each program returns the session ID and token.

* The US A2P 10DLC resource returns these values in the `sessionId` and `sessionToken` properties.
* The Toll-Free Verification, Secondary Customer Profile, and Regulatory Compliance Bundle resources return these values in the `inquiry_id` and `inquiry_session_token` properties.

## Write integration code into your app \[#client]

After you initialize a session on the server, embed the form in your app using one of the Compliance Embed SDKs. To embed the form, use the React SDK for React apps or the JavaScript SDK for any other framework. The SDKs need the session ID and session token returned from the Initialize ComplianceInquiry resources.

* For the US A2P 10DLC resource, use the `sessionId` and `sessionToken` property values.
* For the Toll-Free Verification, Secondary Customer Profile, Regulatory Compliance Bundle resources, use the `inquiry_id` and `inquiry_session_token` property values.

> \[!WARNING]
>
> Don't make Initialize resource requests from the browser. That would expose your Twilio API credentials.

## React SDK

## Prerequisites

* Install React 19 or later.
* Install Node 22 or later.
* Install [`@twilio/twilio-compliance-embed-react`][] and its peer dependencies.
* Install [persona-react][]

  ```bash
  npm install @twilio/twilio-compliance-embed-react \
      react react-dom persona-react
  ```

## Create a TwilioComplianceEmbed React component

To render a `TwilioComplianceEmbed` component for your form, include the session values that you received from the Initialize API request:

```jsx
// !mark(6:7)
import { TwilioComplianceEmbed } from "@twilio/twilio-compliance-embed-react";

function VerificationPage() {
  return (
    <TwilioComplianceEmbed
      sessionId="{your-session-ID}"
      sessionToken="{your-session-token}"
      onReady={() => console.log("Ready")}
      onComplete={() => console.log("Complete")}
    />
  );
}
```

* When mounted, the component renders the form.
* When unmounted, the component cleans up.
* To control visibility, use standard React patterns.

When the `persona-react` module loads, it references the browser's global variable [`self`][self]. This `self` exists only in the browser. As modern web frameworks render web pages on the server before sending them to your browser, this could cause your server to crash. As a solution during server-side rendering, these frameworks, like [Next.js][], create placeholder values for variables, or [polyfill][], browser globals, like `self`.

If you run Node.js without a framework, it throws a `ReferenceError` when importing `persona-react`. To prevent this error, delay the import until the code runs in the end customer's browser. This requires using [`useEffect`][], which only executes in the browser and never the server. In addition, if using Next.js, disable server-side rendering on that component with `ssr: false`.

To learn about the React SDK parameters, see the [React SDK README][react-sdk-props].

## JavaScript SDK

## Prerequisites

* Install Node 22 or later with npm 7 or later.
* Install [`@twilio/twilio-compliance-embed-js`][].
  ```bash
  npm install @twilio/twilio-compliance-embed-js
  ```
* Install [persona][] 5.8.0.
  * npm includes this package.
  * If you use [Yarn][] or [pnpm][], you need to add the package yourself.

## Create a TwilioCompliance instance

To create an instance, instantiate `TwilioCompliance.create()`, then call `open()` from within `onReady`:

```js
import { TwilioCompliance } from "@twilio/twilio-compliance-embed-js";

let sdk;

sdk = TwilioCompliance.create({
  sessionId: "{your-session-ID}",
  sessionToken: "{your-session-token}",
  onReady: () => sdk.open(),
  onComplete: () => console.log("Complete"),
  onError: (error) => console.error(`Error ${error.code}: ${error.message}`),
});
```

To learn about the JavaScript SDK methods, see the [JavaScript SDK README][js-sdk-props].

You can import and instantiate the JavaScript SDK during server-side rendering safely.

* The `create()` method works on the server.
* The `open()` and `cancel()` methods do nothing.
* The `preload()` method resolves itself.
* The SDK loads the verification provider in the browser only.
* When using Next.js, mount the SDK in a `'use client'` component.

## Events \[#events]

The `onEvent` callback receives one JSON document with one required `name` field and one optional JSON `data` object. The `name` field returns one of the following values:

* `start`
* `page-change`
* `document-upload`
* `one-time-link-sent`
* `one-time-link-start`
* `one-time-link-exit`

```js title="Example call to get event data"
onEvent: (event) => {
  console.log(event.name, event.data);
}
```

### Page change event

The `page-change` event includes the height of the current page as `pageHeight` in its `data` object. The event expresses the `pageHeight` value as a positive integer representing the screen pixels. If you render inline with the JavaScript SDK, resize your container with this value as the user moves through the flow. The React SDK handles resizing for you.

## Submission result

The `onSubmit` callback receives a JSON document with an `outcome` field with values like `success`, `failed`, or `review-pending`. When the end customer reaches the final screen, this triggers the callback. This happens independent of `onComplete`. Each final screen fires `onSubmit` at most once per instance.

## Handle errors \[#errors]

The `onError` callback receives an object with a numeric `code` and a human-readable `message`. It also includes a `sessionId` for runtime errors, but not for configuration errors.

To handle these errors, log the `code` and `message` and provide your customer a way to retry.

> \[!IMPORTANT]
>
> Don't write logic that depends on a specific `code` value.

## Consider end customer browser issues

The SDKs render the compliance form inside an `iframe` tag that Persona serves.

Three conditions might impact your end customer experience:

1. If your app sets a [*Content Security Policy* (CSP)][csp], set following HTTP header[^1] for the page that contains the `iframe`:
   ```http
   Content-Security-Policy: frame-src 'self' https://*.withpersona.com;
   ```
2. Programs that collect identity documents require camera access. To allow camera use, include the following HTTP header[^1]:
   ```http
   Permissions-Policy: camera=(self "https://*.withpersona.com")
   ```
3. Some browsers block third-party cookies by default. Test your integration with strict privacy settings.

[^1]: Each web server differs in how they pass HTTP headers. To learn how your web server passes HTTP headers, see your web server documentation.

## Apply your branding to the compliance form

To style the embedded form consistent with your brand, target the `iframe` tag through a selector your web app controls. An example would be `.your-classname > iframe`. Don't rely on internal class names. These change without notice.

## Migrate from the legacy SDK

The legacy `@twilio/twilio-compliance-embed` package (version 2.1.3) remains in maintenance mode. It doesn't get new features. When building new integrations, use the [React SDK or the JavaScript SDK](#client).

If you integrated with the legacy package, replace the package with the React or JavaScript package then update your properties and callbacks:

| Legacy                         | Replacement                                                 | See also              |
| ------------------------------ | ----------------------------------------------------------- | --------------------- |
| `inquiryId`                    | `sessionId`                                                 |                       |
| `inquirySessionToken`          | `sessionToken`                                              |                       |
| `onInquirySubmitted()`         | `onSubmit({ outcome })`                                     | [Submission result][] |
| `onError()`                    | `onError({ code, message, sessionId })`                     | [Error handling][]    |
| `onEvent(eventName, metaData)` | `onEvent({ name, data })`.                                  | [Events][]            |
| `className`                    | `frameHeight`, `frameWidth`, `language`, and `iframeTitle`. |                       |

## Security

Twilio secures the exchange of all sensitive information through your app, your server, and the Twilio API. Sensitive information includes credentials, permanent resource identifiers, and [*personally identifiable information* (PII)][pii].

1. Your customer initiates the ComplianceInquiry interface in your site.
2. Your server requests the session ID and the ephemeral session token from the [Twilio API][api-auth].
3. Your server returns those values to your web app, which then passes them to the SDK.
4. Your web app, through the SDK, launches and loads the ComplianceInquiry form.

[`@twilio/twilio-compliance-embed-js`]: https://www.npmjs.com/package/@twilio/twilio-compliance-embed-js

[`@twilio/twilio-compliance-embed-react`]: https://www.npmjs.com/package/@twilio/twilio-compliance-embed-react

[`useEffect`]: https://react.dev/reference/react/useEffect

[api-auth]: #api-auth

[csp]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP

[Error handling]: #errors

[Events]: #events

[js-sdk-props]: https://github.com/twilio/twilio-compliance-embed-js#twiliocompliancecreateconfig

[next.js]: https://nextjs.org

[persona-react]: https://www.npmjs.com/package/persona-react?activeTab=readme

[persona]: https://www.npmjs.com/package/persona

[pii]: /docs/glossary/what-is-personally-identifiable-information-pii

[pnpm]: https://pnpm.io/cli/add

[polyfill]: https://developer.mozilla.org/en-US/docs/Glossary/Polyfill

[react-sdk-props]: https://github.com/twilio/twilio-compliance-embed-react#twiliocomplianceembed-

[Regulatory Compliance Bundles]: /docs/messaging/compliance/compliance-embed/regulatory-compliance

[Secondary Customer Profiles]: /docs/messaging/compliance/compliance-embed/secondary-customer-profiles

[self]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#global_context

[Submission result]: #submission-result

[theme request form]: https://airtable.com/appBN6pqe3FSiF3n1/pag4YSVvOteaAVaLd/form

[Toll-Free Verification]: /docs/messaging/compliance/compliance-embed/toll-free-verification

[US A2P 10DLC]: /docs/messaging/compliance/compliance-embed/a2p-10dlc

[yarn]: https://yarnpkg.com/cli/add
