Skip to main content

Mobile SDKs

The mobile SDKs do in a native app what the browser collector does on a web page: they read device facts, send them to POST /v1/fp/collect with a publishable key and return the fp_id the server resolved. Your backend then puts that fp_id into its events, so device rules (new device, accounts per device, fp.platform) work for mobile users too.

PlatformPackageMinimum
iOS (Swift)Defraudo (Swift Package)iOS 15
Android (Kotlin)com.defraudo:defraudo-androidAndroid 7 (API 24)
React Native@defraudo/react-native-sdkReact Native 0.74
Flutterdefraudo_sdkFlutter 3.50 (Dart 3.14)

React Native and Flutter are thin wrappers over the iOS and Android SDKs: the same signals, the same device id and the same error codes. Defraudo gives you access to the packages during onboarding.

How it works​

  1. The SDK keeps a stable device id: on iOS a random id in the Keychain of this device (it survives a reinstall and never moves to another phone); on Android an id derived from ANDROID_ID and your package name (the same after a reinstall, never sent raw).
  2. It sends hardware and OS facts: model, manufacturer, OS version, screen, CPU, memory, locale, time zone, app id and version. No IMEI, phone number, advertising id, contacts or location.
  3. The server identifies the device by its id and returns fp_id. The same device gets the same fp_id again.
  4. Your backend sends the event with context.fp_id and context.platform (ios or android) using your secret key, as in step 4 of Device fingerprint.

collect never blocks the main thread. On iOS and Android it returns a failure result instead of throwing; in React Native it rejects with a DefraudoError and in Flutter it throws a DefraudoException, each with the same code. Without network the code is NETWORK_ERROR; network errors, 5xx and 429 are retried twice with a short backoff, and any other API error comes back at once with its code. The wrappers add INVALID_CONFIG for a bad key or endpoint, and React Native adds NOT_LINKED when the native module is missing from the build.

Use a publishable key only: anyone who downloads the app can read it. Creating the configuration with a secret key, or with a malformed endpoint, fails at once (iOS DefraudoConfig throws, Android DefraudoConfig throws IllegalArgumentException), so build it from a constant you control.

iOS​

import Defraudo

let defraudo = DefraudoClient(config: try DefraudoConfig(publicKey: "pk_live_…"))

switch await defraudo.collect() {
case .success(let identity):
try await myBackend.rememberDevice(identity.fpId)
case .failure(let error):
print("Defraudo \(error.code): \(error.message)")
}

collect(completion:) is available for code without async/await. The package ships a privacy manifest; in your App Store privacy label declare Identifiers → Device ID, linked to the user, used for app functionality, not for tracking.

Android​

val defraudo = Defraudo(applicationContext, DefraudoConfig(publicKey = "pk_live_…"))

defraudo.collect { result ->
when (result) {
is DefraudoResult.Success -> myBackend.rememberDevice(result.fpId)
is DefraudoResult.Failure -> Log.w("Defraudo", "${result.error.code}: ${result.error.message}")
}
}

The callback runs on the main thread. In Google Play Data safety declare Device or other IDs: collected, not shared, for fraud prevention and security.

React Native​

import { collect, DefraudoError } from '@defraudo/react-native-sdk';

try {
const { fpId } = await collect({ publicKey: 'pk_live_…' });
await myBackend.rememberDevice(fpId);
} catch (error) {
if (error instanceof DefraudoError) console.warn(error.code, error.message);
}

Flutter​

import 'package:defraudo_sdk/defraudo_sdk.dart';

try {
final identity = await Defraudo.collect(publicKey: 'pk_live_…');
await myBackend.rememberDevice(identity.fpId);
} on DefraudoException catch (error) {
debugPrint('${error.code}: ${error.message}');
}

When to collect​

Create one SDK instance per app process and collect once per app start or right before a risky action: sign-up, login, deposit, withdrawal. Send the event after collect has returned, with that fp_id.

Rules for mobile devices​

fp.platform is ios, android or web. The server sets it from the kind of fingerprint it received, so the app cannot claim another platform in the event. A rule such as fp.platform = android matches only events whose fp_id came from the Android SDK. An event without a known fp_id has no fp.platform, so such a rule does not match it. The event's own context.platform stays what you send; R-HB-WEB-NO-FP keeps reading it and does not touch events marked ios or android.