Add in-app support to a React Native app

Give your React Native app a "Get help" button that shares your app's screen with your support team on iOS and Android, with consent, under your company's name.

Embed
Preview of the card
<a href="https://gaiadesk.net/docs/react-native-in-app-support"><img src="https://gaiadesk.net/docs/_api/public/orgs/89a5df38-be2c-4963-8823-21d4bd40a2ab/spaces/57b99ea0-d45a-4986-8aa6-6b0683c9fe1d/pages/918c8fca-c930-403e-8da3-19d1c7fec3a0/social-card.svg?v=3e7ae33eec8b" alt="Add in-app support to a React Native app" width="600" height="315"></a>

Give your React Native app a "Get help" button: your customer taps it and agrees, and your support team sees your app's screen in the GaiaDesk console — and, if you allow it, guides it — without the customer installing anything.

@gaiadesk/embed-react-native 0.1.0 works on iOS and Android with React Native 0.74 or later, on the new or the old architecture. It is a typed TypeScript API over GaiaDesk's native SDKs: the iOS SDK (the GaiaDeskEmbed pod) and the Android SDK (net.gaiadesk:embed-android). It is open source (MIT), at github.com/Gaia-Desk/gaiadesk-embed-react-native. The native SDKs carry the same signed native library as GaiaDesk's other embed SDKs; the library is a prebuilt binary that ships, unmodified, inside your app.

What your customer sees

  • One button. Your app shows "Get help" wherever you put it.

  • A consent dialog. It names your company, says what will be shared (this app's screen, or on Android the whole screen if you chose it) and whether your team will be able to guide it. Nothing is shared until the customer agrees.

  • An indicator for as long as anything is shared. "Sharing with Acme · Stop", drawn by the SDK on top of your app. In a guided session it also has Pause control.

  • A support code. Nine digits your customer can read to an agent over the phone.

When the session ends — the customer presses Stop, your app stops it, the session expires, or the app quits — sharing stops at once and nothing is left behind: the SDK installs nothing and writes nothing to disk. Reloading the JS bundle stops a running session too.

What your support team sees

Agents open Support in the GaiaDesk console, see the waiting customer (with the details your backend passed) and join, or type the support code. Only your own account and team can join, and only team members with a support seat.

1. Add the package

@gaiadesk/embed-react-native is not on npm yet: it waits for the native SDKs to reach CocoaPods trunk and Maven Central. Until then, pack it from the release tag (lib/ is built when the package is packed, so installing straight from GitHub does not work):

git clone --branch v0.1.0 https://github.com/Gaia-Desk/gaiadesk-embed-react-native.git
cd gaiadesk-embed-react-native && npm ci && npm pack
cd <your app> && npm install <path>/gaiadesk-embed-react-native-0.1.0.tgz

Once it is published, this becomes npm install @gaiadesk/embed-react-native.

It is native code, so it does not run in Expo Go; in an Expo app, use a development build.

2. The native SDKs

iOS (15.1 or later). In ios/Podfile, inside your app target and above use_native_modules!, take the GaiaDeskEmbed pod from its GitHub release, then run pod install:

pod 'GaiaDeskEmbed', :podspec => 'https://raw.githubusercontent.com/Gaia-Desk/gaiadesk-embed-ios/v0.1.0/GaiaDeskEmbed.podspec'

The pod carries the Swift SDK and the prebuilt GaiaDeskEmbedFFI.xcframework.

Android (minSdkVersion 26, set in android/build.gradle). Autolinking adds the module. Download embed-android-0.1.0.aar from the Android SDK's v0.1.0 release and point the module at it in android/gradle.properties:

GaiaDeskEmbed_embedAndroidAar=/path/to/embed-android-0.1.0.aar

(or set GAIADESK_EMBED_ANDROID_AAR). Once net.gaiadesk:embed-android is on Maven Central, drop the override: the module takes it from there. Nothing goes in your manifest unless you opt into sharing the whole screen (see what each platform supports).

3. Create the session on your backend

The SDK takes an embed token: your backend creates the session with a secret API key (scope support), decides who may get help, passes verified customer details, and hands the app only the token:

curl -s -X POST https://api.gaiadesk.net/v1/support/sessions \
  -H "Authorization: Bearer $GAIADESK_API_KEY" -H "Content-Type: application/json" \
  -d '{"mode": "view", "customer": {"name": "Ada", "plan": "pro"}}'

The response carries embed_token (gdemb_…), which your app passes as embedToken. Never ship the secret key in your app: the embed token is all it needs. Version 0.1.0 has no publishable-key option. The full request is in the support API reference.

4. Add the button

import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
import { EmbedError, EmbedSession, GaiaDeskEmbed, GaiaDeskMasked } from '@gaiadesk/embed-react-native';

export function HelpButton({ getEmbedToken }: { getEmbedToken: () => Promise<string> }) {
  const [session, setSession] = useState<EmbedSession | null>(null);
  const [code, setCode] = useState<string | null>(null);

  async function getHelp() {
    const consent = await GaiaDeskEmbed.requestConsent('Acme');
    if (!consent) return; // the customer said no
    try {
      const help = await GaiaDeskEmbed.start({ embedToken: await getEmbedToken(), company: 'Acme' }, consent, (e) => {
        if (e.type === 'code') setCode(e.code); // read it to the agent
        if (e.type === 'ended') {
          setSession(null);
          setCode(null);
        }
      });
      if (!help.isEnded) setSession(help);
    } catch (e) {
      if (e instanceof EmbedError) console.warn(e.code, e.message); // bad_token, consent_required, busy, …
      else throw e;
    }
  }

  return (
    <View>
      {session ? <Button title="Stop sharing" onPress={() => session.stop()} /> : <Button title="Get help" onPress={getHelp} />}
      {code && <Text>Your support code is {code}</Text>}
      <GaiaDeskMasked>
        <Text>Card 4242 4242 4242 4242</Text>
      </GaiaDeskMasked>
    </View>
  );
}

requestConsent shows the native SDK's dialog (a UIAlertController on iOS, an AlertDialog on Android) and resolves with a Consent, or null when the customer declines. start takes only that consent: it is single-use, valid for 10 minutes, and bound to what the customer was asked — start refuses (consent_required) another company, or a guided session they were not told about. With your own dialog, call GaiaDeskEmbed.recordConsent(company, { guided, capture }) when the customer agrees, and say exactly that in it.

Events arrive on the JS thread, in order: state, code ({ code, sessionId, mode }), joined ({ agent }), left, control ({ allowed }), action ({ action, applied, reason }), error ({ code, message }) and ended ({ reason }: stopped, app_stopped, disconnected, expired or error) — always last, exactly once. You can also await session.ended. One session runs at a time (busy).

Option

embedToken

gdemb_…, from your backend

company

Shown on the consent dialog and the indicator

server

Default https://gaiadesk.net

guided

Allow guided input (default false)

fps

1 to 30 (default 15)

masks

{ x, y, w, h }[] in layout units, masked from the first frame

capture

"app" (default) or "screen" (Android only)

captureMethod

"replayKit" (default) or "snapshot" (iOS only)

The consent dialog and the indicator show the company you pass. Version 0.1.0 has no colour or logo options.

Guided sessions

By default your team can only look. To let them tap, scroll and type, create the session as cobrowse ("mode": "cobrowse") and ask for and pass guided: true — both ends must want it:

const consent = await GaiaDeskEmbed.requestConsent('Acme', { guided: true });
// …
await GaiaDeskEmbed.start({ embedToken, company: 'Acme', guided: true }, consent, onEvent);

Even then a request is applied only inside your app, while it is in front, never under a mask, and at most 20 a second. Your customer can pause it at any time from the indicator, and only they can lift that pause; your app can pause too (session.setPaused(true)). Every request is reported as an action event.

  • Android: full. Input is delivered inside your app to your views, React Native's included.

  • iOS: partial. iOS has no public way to synthesise a touch. UIKit controls, text fields, table and collection cells, and scroll views get real delivery, and typing goes into the first responder. Anything else — which includes most React Native touchables (Pressable, TouchableOpacity) — shows your customer a "Tap here" ring instead, reported as applied: false, reason: "hint_shown".

Keeping things private

  • Your app only. On iOS, always; on Android, unless you choose capture: "screen".

  • Masks. Wrap anything sensitive — card numbers, balances — in <GaiaDeskMasked> (a View that takes every View prop), or use useGaiaDeskMask() on your own view. It is painted black before a frame is encoded, from the very first frame, and re-measured on every animation frame while a session runs, so it follows scrolls and animations. A marked view that has not been measured yet masks the whole picture until it is. You can also pass rects (masks, or session.setMaskedRects()).

  • Secret fields. Password fields (secureTextEntry) are masked and guided typing into them is refused. For other secrets, such as a PIN or one-time code shown in clear, use <GaiaDeskSecretInput> or spread useGaiaDeskSecretFocus()'s onFocus / onBlur on your own input.

  • Consent every time. The native library refuses to start without it; there is no setting that skips the consent or hides the indicator.

What each platform supports

Capture

Guided input

Consent dialog

iOS 15.1 or later

this app only

partial (UIKit controls; "Tap here" hints otherwise)

UIAlertController, or your own

Android 8.0 or later (API 26)

your app's window; the whole screen opt-in

yes, inside your app

AlertDialog, or your own

  • iOS: the default, captureMethod: "replayKit", captures exactly what the app shows; iOS asks your customer once to allow recording the app. ReplayKit is not available in the iOS Simulator: use captureMethod: "snapshot" there (a snapshot of the app's windows, no system prompt, which can miss some video or Metal content). capture: "screen" is refused on iOS (bad_config).

  • Android: the default copies your activity's window (PixelCopy): no permission, no system dialog. capture: "screen" shares the whole screen through MediaProjection: Android asks the customer too, and your app must declare in its AndroidManifest.xml:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

    Without them the session fails with capture_failed. Pass capture: "screen" to requestConsent as well, so the dialog says the whole screen is shared. captureMethod is refused on Android (bad_config).

What is and is not permitted

You may: ship the prebuilt library unmodified inside your app, with its licence in your app's notices; offer support sessions to your own customers; show your company's name on the dialog and indicator.

You may not: modify, decompile or re-sign the library separately from your app; hide or imitate the indicator; start a session without your customer's agreement.

See the package's README for every option, event and error code, and in-app support for the other platforms.

Updated