Skip to content

User Consent

Part of the Human Scoring use case.

The SDK records how the user interacts with your app, so by default it records nothing until the user agrees. On React Native you ask with your own UI and hand the answer to the SDK, which stores it on the device.

Not available on React Native. The SDK has no built-in consent dialog like the Flutter SDK's showDeaConsentDialog, no way to clear a stored answer (forget()), and no way to keep an answer for one launch only (remember: false).

When to use it

  • Always, unless your app already obtains consent before calling init — in that case pass the answer as consent, or set requireConsent: false
  • To let the user withdraw consent from a settings screen

Prerequisites

  • The SDK is installed and initialized. See the Quick Start.

Usage

Record the answer

import * as Dea from '@dea/react-native';

await Dea.setConsent(true);  // the user agreed
await Dea.setConsent(false); // the user declined

Recording starts or stops as soon as the answer is recorded. The answer is stored on the device and survives app restarts. What the SDK records once the user agrees is on Privacy and network.

Read the current answer

const consent = await Dea.getConsent(); // 'unknown' | 'granted' | 'denied'

'unknown' means the user has not answered yet — the cue to ask.

Pass an answer you already have to init

If your onboarding asks before the SDK starts, hand the answer to init. It is applied before the first event is captured:

await Dea.init({appId: 'YOUR_APP_ID', consent: userAgreed});
await Dea.setConsent(false);

Recording stops immediately. The session is kept, so if the user agrees again, recording continues in the same session.

Examples

Ask on the first screen

import {useEffect} from 'react';
import {Alert, Text, View} from 'react-native';
import * as Dea from '@dea/react-native';

export function HomeScreen() {
  useEffect(() => {
    (async () => {
      if ((await Dea.getConsent()) !== 'unknown') return;

      Alert.alert(
        'Help us keep bots out',
        'We measure how you touch and hold your phone to tell people apart from bots. ' +
          'We never record what you type or what is on your screen.',
        [
          {text: 'Not now', style: 'cancel', onPress: () => Dea.setConsent(false)},
          {text: 'Allow', onPress: () => Dea.setConsent(true)},
        ],
        {cancelable: false},
      );
    })().catch(() => {
      // init has not run yet
    });
  }, []);

  return (
    <View>
      <Text>Home</Text>
    </View>
  );
}

Make sure your wording stays true for your app.

A settings switch

import {useEffect, useState} from 'react';
import {Switch, Text, View} from 'react-native';
import * as Dea from '@dea/react-native';

export function DeaConsentSetting() {
  const [granted, setGranted] = useState(false);

  useEffect(() => {
    Dea.getConsent().then(answer => setGranted(answer === 'granted'));
  }, []);

  const onChange = async (value: boolean) => {
    await Dea.setConsent(value);
    setGranted(value);
  };

  return (
    <View style={{flexDirection: 'row', alignItems: 'center'}}>
      <Text style={{flex: 1}}>Bot protection — measure how I interact with the app</Text>
      <Switch value={granted} onValueChange={onChange} />
    </View>
  );
}

API

Member Returns Description
setConsent(granted) Promise<void> Records and stores the answer
getConsent() Promise<ConsentState> 'unknown', 'granted' or 'denied'
init({consent}) — Applies an answer your app already has before the first event