Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/formbricks/formbricks/llms.txt

Use this file to discover all available pages before exploring further.

App surveys enable you to collect feedback directly within your mobile or desktop applications. Formbricks provides native SDKs for iOS, Android, React Native, and Flutter.

Overview

App surveys work similarly to website surveys but are optimized for native mobile and desktop environments. They support:
  • Native UI components for better performance
  • Offline response queueing
  • Platform-specific gestures and interactions
  • Deep integration with app lifecycle events
// App surveys use the same type as website surveys
interface TSurvey {
  type: "app" | "link";
  displayOption: TSurveyDisplayOption;
  triggers: Array<{ actionClass: TActionClass }>;
}

Platform Support

iOS

Native Swift SDK for iOS apps

Android

Kotlin SDK for Android apps

React Native

Cross-platform React Native support

Flutter

Dart SDK for Flutter apps

iOS (Swift)

Installation

1

Add Swift Package

Add the Formbricks iOS SDK to your Xcode project:
https://github.com/formbricks/formbricks-ios
Or using Swift Package Manager:
dependencies: [
  .package(url: "https://github.com/formbricks/formbricks-ios", from: "1.0.0")
]
2

Import SDK

import Formbricks
3

Initialize in AppDelegate

func application(_ application: UIApplication, 
                didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    Formbricks.configure(
        environmentId: "your-environment-id",
        apiHost: "https://your-formbricks-instance.com"
    )
    
    return true
}

Tracking Events

// Track custom events
Formbricks.track(name: "product_viewed")

// Track with attributes
Formbricks.track(
    name: "purchase_completed",
    properties: [
        "order_value": "99.99",
        "product_category": "electronics"
    ]
)

User Identification

// Set user ID
Formbricks.setUserId("user_12345")

// Set user attributes
Formbricks.setAttributes([
    "email": "user@example.com",
    "plan": "premium",
    "signup_date": "2024-01-15"
])

// Logout
Formbricks.logout()

Screen Tracking

// Track screen views automatically in UIViewController
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    Formbricks.trackScreen(name: "ProductDetailScreen")
}

// Or track manually
Formbricks.trackScreen(name: "HomeScreen")

Android (Kotlin)

Installation

1

Add dependency

Add to your build.gradle:
dependencies {
    implementation 'com.formbricks:formbricks-android:1.0.0'
}
2

Initialize in Application class

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        
        Formbricks.initialize(
            context = this,
            environmentId = "your-environment-id",
            apiHost = "https://your-formbricks-instance.com"
        )
    }
}
3

Update AndroidManifest.xml

<application
    android:name=".MyApplication"
    ...>
</application>

Tracking Events

// Track custom events
Formbricks.track("product_viewed")

// Track with properties
Formbricks.track(
    event = "purchase_completed",
    properties = mapOf(
        "order_value" to "99.99",
        "product_category" to "electronics"
    )
)

User Identification

// Set user ID
Formbricks.setUserId("user_12345")

// Set user attributes
Formbricks.setAttributes(
    mapOf(
        "email" to "user@example.com",
        "plan" to "premium",
        "signup_date" to "2024-01-15"
    )
)

// Logout
Formbricks.logout()

Activity Tracking

class ProductDetailActivity : AppCompatActivity() {
    override fun onResume() {
        super.onResume()
        Formbricks.trackScreen("ProductDetailScreen")
    }
}

React Native

Installation

1

Install package

npm install @formbricks/react-native
2

Install pods (iOS only)

cd ios && pod install
3

Initialize in App.tsx

import { useEffect } from 'react';
import Formbricks from '@formbricks/react-native';

export default function App() {
  useEffect(() => {
    Formbricks.initialize({
      environmentId: 'your-environment-id',
      apiHost: 'https://your-formbricks-instance.com'
    });
  }, []);
  
  return (
    <YourApp />
  );
}

Tracking Events

import Formbricks from '@formbricks/react-native';

// Track events
await Formbricks.track('button_clicked');

// Track with properties
await Formbricks.track('purchase_completed', {
  orderValue: '99.99',
  productCategory: 'electronics'
});

User Identification

// Set user ID
await Formbricks.setUserId('user_12345');

// Set attributes
await Formbricks.setAttributes({
  email: 'user@example.com',
  plan: 'premium'
});

// Logout
await Formbricks.logout();

Screen Tracking with React Navigation

import { useNavigationContainerRef } from '@react-navigation/native';
import Formbricks from '@formbricks/react-native';

function App() {
  const navigationRef = useNavigationContainerRef();
  const routeNameRef = useRef();
  
  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={() => {
        routeNameRef.current = navigationRef.getCurrentRoute()?.name;
      }}
      onStateChange={async () => {
        const previousRouteName = routeNameRef.current;
        const currentRouteName = navigationRef.getCurrentRoute()?.name;
        
        if (previousRouteName !== currentRouteName) {
          await Formbricks.trackScreen(currentRouteName);
        }
        
        routeNameRef.current = currentRouteName;
      }}
    >
      {/* Your app screens */}
    </NavigationContainer>
  );
}

Flutter

Installation

1

Add dependency

Add to pubspec.yaml:
dependencies:
  formbricks_flutter: ^1.0.0
2

Install packages

flutter pub get
3

Initialize in main.dart

import 'package:formbricks_flutter/formbricks_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await Formbricks.initialize(
    environmentId: 'your-environment-id',
    apiHost: 'https://your-formbricks-instance.com',
  );
  
  runApp(MyApp());
}

Tracking Events

// Track events
await Formbricks.track('button_clicked');

// Track with properties
await Formbricks.track(
  'purchase_completed',
  properties: {
    'order_value': '99.99',
    'product_category': 'electronics',
  },
);

User Identification

// Set user ID
await Formbricks.setUserId('user_12345');

// Set attributes
await Formbricks.setAttributes({
  'email': 'user@example.com',
  'plan': 'premium',
});

// Logout
await Formbricks.logout();

Common Features

The following features work across all platforms:

Display Configuration

Control when and how surveys appear:
{
  "displayOption": "displayOnce",
  "recontactDays": 7,
  "displayLimit": 3,
  "displayPercentage": 50
}

Trigger Actions

Define triggers in the Formbricks dashboard:
  • Code Triggers: Match tracked events by identifier
  • Screen View: Trigger on specific screen names
  • Custom Logic: Combine multiple conditions

Audience Targeting

Target users based on attributes:
{
  "segment": {
    "filters": [
      {
        "attribute": "plan",
        "operator": "equals",
        "value": "premium"
      },
      {
        "attribute": "app_version",
        "operator": "greaterThan",
        "value": "2.0.0"
      }
    ]
  }
}

Offline Support

All SDKs support offline response queueing:
  1. Responses are stored locally when offline
  2. Automatically sync when connection restores
  3. Configurable retry logic
  4. Storage limits to prevent data buildup

Best Practices

Initialize Formbricks as early as possible in your app lifecycle to ensure surveys can trigger on app launch.
Focus on key user actions that indicate engagement or friction points:
  • Onboarding completed
  • Feature discovered
  • Purchase completed
  • Error encountered
Request appropriate permissions before collecting data. Be transparent about data usage.
Always test surveys on physical devices across different screen sizes and OS versions.
Track SDK impact on app performance:
  • Bundle size increase
  • Memory usage
  • Battery consumption
  • Network requests
Wrap SDK calls in try-catch blocks to prevent crashes:
do {
    try Formbricks.track("event_name")
} catch {
    print("Formbricks error: \(error)")
}

Platform-Specific Considerations

iOS

  • App Tracking Transparency: Request tracking permission on iOS 14.5+
  • Background Mode: Survey data syncs when app returns to foreground
  • Universal Links: Support deep linking from survey notifications

Android

  • ProGuard: Add ProGuard rules if using code obfuscation
  • Background Restrictions: Handle Android’s battery optimization
  • Multi-Window: Test surveys in split-screen mode

React Native

  • Hermes: Compatible with Hermes JavaScript engine
  • Expo: Works with both bare and managed workflows
  • Navigation: Supports React Navigation and React Native Navigation

Flutter

  • Web Support: Limited web platform support
  • Desktop: Experimental support for macOS and Windows
  • Hot Reload: Initialization persists across hot reloads

Troubleshooting

  • Verify environmentId and apiHost are correct
  • Check network connectivity
  • Review app logs for initialization errors
  • Ensure SDK is initialized before tracking events
  • Confirm survey type is set to App
  • Verify trigger conditions match tracked events
  • Check if user meets audience targeting criteria
  • Review recontact days and display limits
  • Test in development/staging environment first
  • Verify event names match exactly (case-sensitive)
  • Check network tab for failed API requests
  • Ensure user is identified if required by segment
  • Confirm app has internet connectivity
  • Update to latest SDK version
  • Clear build cache and rebuild
  • Check platform-specific requirements
  • Review SDK changelog for breaking changes

Example: Complete Integration

Here’s a complete example for iOS:
import UIKit
import Formbricks

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication,
                    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Initialize Formbricks
        Formbricks.configure(
            environmentId: "clxxx123456789",
            apiHost: "https://app.formbricks.com"
        )
        
        return true
    }
}

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Identify user
        Formbricks.setUserId("user_12345")
        Formbricks.setAttributes([
            "email": "user@example.com",
            "plan": "premium"
        ])
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // Track screen view
        Formbricks.trackScreen(name: "HomeScreen")
    }
    
    @IBAction func checkoutButtonTapped(_ sender: UIButton) {
        // Track event
        Formbricks.track(
            name: "checkout_started",
            properties: [
                "cart_value": "299.99",
                "item_count": "3"
            ]
        )
    }
}

Website Surveys

Implement surveys on websites

iOS SDK Reference

Complete iOS SDK documentation

Android SDK Reference

Complete Android SDK documentation

Conditional Logic

Create dynamic survey flows