Important for Self-Hosted Setups:Multi-Domain Setup: If you are using the multi-domain setup, the
appUrl parameter in all SDK configurations should point to your public domain (PUBLIC_URL environment variable). This is the domain where surveys and public-facing content are served, which may be different from your admin interface domain (WEBAPP_URL).Single Domain Setup: If you are using the single domain setup, the appUrl parameter in all SDK configurations should point to your admin domain (WEBAPP_URL environment variable).HTML
All you need to do is add three lines of code to your HTML script, and that’s it!
React.js
Load our JavaScript library with your environment ID, and you’re ready to
go!
Next.js
Natively add us to your Next.js project, with support for both App and Pages project
structure.
Vue.js
Learn how to use Formbricks’ Vue.js SDK to integrate your surveys into Vue.js applications.
React Native
Easily integrate our SDK with your React Native app for seamless survey
support.
Swift
Use our iOS SDK to quickly integrate surveys into your iOS
applications.
Android
Integrate surveys into your Android applications using our native Kotlin
SDK.
Prerequisites
Before getting started, make sure you have:- A running web application with user authentication in your chosen framework.
- A Formbricks account with your environment ID and API host, available in the Setup Checklist under Settings.
HTML
All you need to do is copy a<script> tag to your HTML head:
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
React.js
Install the Formbricks SDK using one of the following package managers:npm, pnpm, or yarn.
Note that zod is required as a peer dependency and must also be installed in your project.
npm
pnpm
yarn
App.js/ts file to initialize Formbricks.
src/App.js
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
Next.js
Next.js projects use either the App Directory or the Pages Directory. Since the Formbricks SDK runs on the client side, follow these steps based on your setup:-
App Directory: Create a new component in
app/formbricks.tsxand call it inapp/layout.tsx. -
Pages Directory: Initialize Formbricks directly in
_app.tsx.
npm
pnpm
yarn
App directory
app/formbricks.tsx
app/layout.tsx
Pages directory
src/pages/_app.tsx
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
Vue.js
Integrating the Formbricks SDK with Vue.js is easy. We’ll ensure the SDK is only loaded and used on the client side, as it’s not meant for server-side use.npm
pnpm
yarn
src/formbricks.js
src/main.js
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
React Native
Install the Formbricks React Native SDK using one of the package managers, i.e., npm, pnpm, or yarn.npm
pnpm
yarn
App.js/App.tsx file to initialize Formbricks:
src/App.js
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
Swift
Minimum iOS Version: The Formbricks iOS SDK requires iOS 16.4 or higher.
- In Xcode choose File → Add Packages…
-
Enter your repo URL (e.g.
https://github.com/formbricks/ios.git) -
Choose version rule (e.g. “Up to Next Major” starting at
1.0.0). -
Import in your code:
-
Add the following to your
Podfile: -
Run
pod installin your project directory -
Import in your code:
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
Android
Minimum Android Version: The Formbricks Android SDK requires Android 10 (API level 29) or higher.
Installation
Add the Maven Central repository and the Formbricks SDK dependency to your application’sbuild.gradle.kts:
Usage
Required Customizations
| Name | Type | Description |
|---|---|---|
| environment-id | string | Formbricks Environment ID. |
| app-url | string | URL of the hosted Formbricks instance. |
Validate your setup
Once you’ve completed the steps above, validate your setup by checking the Setup Checklist in the Settings. The widget status indicator should change from this:
To this:
Debugging Formbricks Integration
The debug mode is only available in the JavaScript SDK and works exclusively in the browser. It is not
supported in mobile SDKs such as React Native, iOS, or Android.
Activate Debug Mode
To enable debug mode, add?formbricksDebug=true to your app’s URL (e.g., https://example.com?formbricksDebug=true).
View Debug Logs
- Open your browser’s developer tools:
-
Google Chrome/Edge: Press
F12or right-click and select “Inspect” > “Console”. -
Firefox: Press
F12or right-click and select “Inspect Element” > “Console”. -
Safari: Press
Option + Command + Cto open developer tools and go to the “Console” tab.
Common Use Cases
Debug mode is helpful for:- Verifying Formbricks initialization.
- Identifying issues with survey triggers.
- Troubleshooting unexpected behavior.
Debug Log Messages
Logs provide insights into:- API calls and responses.
- Survey triggers and form interactions.
- Initialization errors.