コンテンツにスキップ

ユーザー同意

ヒューマンスコアリングユースケースの一部です。

SDK はユーザーがアプリをどのように操作するかを記録するため、デフォルトではユーザーが同意するまで何も記録 しません。React Native では、独自の UI で尋ねたうえで回答を SDK に渡し、SDK がそれを端末に保存します。

React Native では利用できません。 SDK には Flutter SDK の showDeaConsentDialog のような組み込みの 同意ダイアログはなく、保存された回答を消去する手段(forget())も、回答を 1 回の起動だけ保持する手段 (remember: false)もありません。

使いどころ

  • 常に。ただし、アプリが init を呼び出す前にすでに同意を得ている場合は、回答を consent として渡すか、 requireConsent: false を設定します
  • 設定画面からユーザーが同意を撤回できるようにするとき

前提条件

使い方

回答を記録する

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

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

回答が記録されるとすぐに、記録が開始または停止します。回答は端末に保存され、アプリの再起動後も保持されます。 ユーザーが同意した後に SDK が記録するものは、 プライバシーとネットワークにあります。

現在の回答を読み取る

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

'unknown' はユーザーがまだ回答していないことを意味し、尋ねるべき合図です。

すでに持っている回答を init に渡す

オンボーディングで SDK の起動前に尋ねている場合は、回答を init に渡します。最初のイベントが取得される前に 適用されます。

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

記録は直ちに停止します。セッションは保持されるため、ユーザーが再び同意すれば、同じセッションで記録が続きます。

例

最初の画面で尋ねる

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>
  );
}

文言がアプリの実態に合っていることを確認してください。

設定画面のスイッチ

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

メンバー 戻り値 説明
setConsent(granted) Promise<void> 回答を記録して保存する
getConsent() Promise<ConsentState> 'unknown'、'granted'、'denied' のいずれか
init({consent}) — アプリがすでに持っている回答を、最初のイベントの前に適用する