Giter VIP home page Giter VIP logo

fingerprintjs / fingerprintjs-pro-react-native Goto Github PK

View Code? Open in Web Editor NEW
51.0 10.0 4.0 2.68 MB

Official React Native client for Fingerprint PRO. 100% accurate device identification for fraud detection.

Home Page: https://fingerprint.com

License: MIT License

Objective-C 3.43% Ruby 3.05% Kotlin 5.89% TypeScript 34.98% Swift 7.78% JavaScript 8.88% Starlark 2.29% Java 17.95% Shell 1.44% CMake 0.32% C++ 8.69% Objective-C++ 5.31%
react react-native integration fingerprintjs fingerprintjs-pro fraud-detection fingerprint

fingerprintjs-pro-react-native's Introduction

Fingerprint logo

coverage Current NPM version Monthly downloads from NPM Discord server Discord server

Fingerprint Pro React Native

Fingerprint is a device intelligence platform offering 99.5% accurate visitor identification. Fingerprint Pro React Native SDK is an easy way to integrate Fingerprint Pro into your React Native application to call the native Fingerprint Pro libraries (Android and iOS) and identify devices.

Table of contents

Requirements and limitations

  • React Native 0.73 or higher

  • Android 5.0 (API level 21+) or higher

  • iOS 13+/tvOS 15+, Swift 5.7 or higher (stable releases)

  • Fingerprint Pro request filtering is not supported right now. Allowed and forbidden origins cannot be used.

  • Usage inside the Expo environment is not supported right now.

Dependencies

How to install

1. Install the package using your favorite package manager:

  • NPM:

    npm install @fingerprintjs/fingerprintjs-pro-react-native --save
  • Yarn:

    yarn add @fingerprintjs/fingerprintjs-pro-react-native
  • PNPM:

    pnpm add @fingerprintjs/fingerprintjs-pro-react-native

2. Configure native dependencies

  • iOS

    cd ios && pod install
  • Android

    Add a declaration of the Fingerprint Android repository to your app main build.gradle file to the allprojects section:

    maven {
      url("https://maven.fpregistry.io/releases")
    }
    maven {
      url("https://www.jitpack.io")
    }

    The file location is {rootDir}/android/build.gradle. After the changes the build.gradle file should look as following:

    allprojects {
     repositories {
       mavenCentral()
       mavenLocal()
       maven {
         // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
         url("$rootDir/../node_modules/react-native/android")
       }
       maven {
         // Android JSC is installed from npm
         url("$rootDir/../node_modules/jsc-android/dist")
       }
       maven {
         url("https://maven.fpregistry.io/releases")
       }
       maven {
         url("https://www.jitpack.io")
       }
       google()
     }
    }

Usage

To identify visitors, you need a Fingerprint Pro account (you can sign up for free).

Hooks approach

Configure the SDK by wrapping your application in FingerprintJsProProvider.

// src/index.js
import React from 'react';
import { AppRegistry } from 'react-native';
import { FingerprintJsProProvider } from '@fingerprintjs/fingerprintjs-pro-react-native';
import App from './App';

const WrappedApp = () => (
    <FingerprintJsProProvider
        apiKey={'your-fpjs-public-api-key'}
        region={'eu'}
    >
        <App />
    </FingerprintJsProProvider>
);

AppRegistry.registerComponent('AppName', () => WrappedApp);

Use the useVisitorData hook in your components to perform visitor identification and get the data.

// src/App.js
import React, { useEffect } from 'react';
import { Text } from 'react-native';
import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react-native';

function App() {
  const {
    isLoading,
    error,
    data,
    getData,
  } = useVisitorData();

  useEffect(() => {
    getData();
  }, []);

  if (isLoading) {
    return <Text>Loading...</Text>;
  }
  if (error) {
    return <Text>An error occured: {error.message}</Text>;
  }

  if (data) {
    // perform some logic based on the visitor data
    return (
      <Text>
        Visitor id is {data.visitorId}
      </Text>
    );
  } else {
    return null;
  }
}

export default App;

API Client approach

import React, { useEffect } from 'react';
import { FingerprintJsProAgent } from '@fingerprintjs/fingerprintjs-pro-react-native';

// ... 

useEffect(() => {
  async function getVisitorInfo() {
    try {
      const FingerprintClient = new FingerprintJsProAgent({ apiKey: 'PUBLIC_API_KEY', region: 'eu' }); // Region may be 'us', 'eu', or 'ap'
      const visitorId = await FingerprintClient.getVisitorId(); // Use this method if you need only visitorId
      const visitorData = await FingerprintClient.getVisitorData(); // Use this method if you need additional information about visitor
      // use visitor data in your code
    } catch (e) {
      console.error('Error: ', e);
    }
  }
  getVisitorInfo();
}, []);

extendedResponseFormat

Two types of responses are supported: "default" and "extended". You don't need to pass any parameters to get the "default" response. "Extended" is an extended result format that includes geolocation, incognito mode and other information. It can be requested using the extendedResponseFormat: true parameter. See more details about the responses in the documentation.

Providing extendedResponseFormat with hooks approach

  return (
    <FingerprintJsProProvider apiKey={PUBLIC_API_KEY} extendedResponseFormat={true}>
      <App />
    </FingerprintJsProProvider>
  )

Providing extendedResponseFormat with API Client approach

const FingerprintClient = new FingerprintJsProAgent({ apiKey: 'PUBLIC_API_KEY', region: 'eu', extendedResponseFormat: true }); // Region may be 'us', 'eu', or 'ap'
// =================================================================================================^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Linking and tagging information

The visitorId provided by Fingerprint Identification is especially useful when combined with information you already know about your users, for example, account IDs, order IDs, etc. To learn more about various applications of the linkedId and tag, see Linking and tagging information.

const tag = {
  userAction: 'login',
  analyticsId: 'UA-5555-1111-1'
};
const linkedId = 'user_1234';

// Using hooks
const { getData } = useVisitorData();
const visitorData = await getData(tag, linkedId);

// Using the client
const FingerprintClient = new FingerprintJsProAgent({ apiKey: 'PUBLIC_API_KEY'});
const visitorId = await FingerprintClient.getVisitorId(tag, linkedId);
const visitor = await FingerprintClient.getVisitorData(tag, linkedId); 

API Reference

See the full generated API Reference.

Additional Resources

Support and feedback

To report problems, ask questions or provide feedback, please use Issues. If you need private support, please email us at [email protected].

License

This project is licensed under the MIT license.

fingerprintjs-pro-react-native's People

Contributors

alexey-verkhovsky avatar dependabot[bot] avatar finesse avatar ilfa avatar jurouhlar avatar makma avatar necipallef avatar petrpalata avatar semantic-release-bot avatar stereodenis avatar theunderscorer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fingerprintjs-pro-react-native's Issues

Apple Privacy Manifests

Apple's requirement to document usages of certain Api's is coming into effect May 1.
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api

using scanner tool (here) to scan for usages of these API's/symbols

and there are a couple of results found for FingerprintPro:

NSFileSystemFreeSize
NSFileSystemSize

Is this something the team is aware of? or have an ETA for?

more info here
react-native-community/discussions-and-proposals#776

Edit
looks like ios sdk got the update https://github.com/fingerprintjs/fingerprintjs-pro-ios/releases/tag/2.3.2

Introduce E2E tests

It might be a little bit far stretched, but I'm wondering if we should introduce some E2E tests for our library?
As far as I see, we don't have any tests yet.

Since we are using native modules under the hood, unit tests won't make much sense here. We could use https://github.com/wix/detox/ for it, and add tests to the TestProject - even simple checking like if the visitorId is being rendered.

WDYT?

What is the benefit of using this over the unique device ID?

What is the benefit of using this over the unique device ID?

react-nativ-device-info returns a unique device ID for both iOS and Android:

iOS: This is IDFV or a random string if IDFV is unavaliable. Once UID is generated it is stored in iOS Keychain and NSUserDefaults. So it would stay the same even if you delete the app or reset IDFV. You can carefully consider it a persistent, cross-install unique ID. It can be changed only in case someone manually override values in Keychain/NSUserDefaults or if Apple would change Keychain and NSUserDefaults implementations. Beware: The IDFV is calculated using your bundle identifier and thus will be different in app extensions.
android: Prior to Oreo, this id (ANDROID_ID) will always be the same once you set up your phone.

https://github.com/react-native-device-info/react-native-device-info#getuniqueid

✅ = ID does not change
❌ = ID does change

image

NetworkError: Could not connect to the server.

FingerprintJS is throwing network connection issues reported by our monitoring tool for both iOS & Android apps. There are multiple instances of this error, and it's throwing different error messages:

NetworkError: A server with the specified hostname could not be found.

NetworkError: Could not connect to the server.

NetworkError: The Internet connection appears to be offline.

Note: my fingerprintjs-pro-react-native is 2.5.3

Did anyone experienced something similar?

`browserName` for Android and IOS apps is different

I'm using browserName field to determine the platform that is used by users. When IOS app triggers fingerprint update I see browserName is coming with the value, e.g. 'TestValue', but when Android app does, browserName is coming as Other.
Are you aware how to make it consistent and get TestValue for browserName from both platforms?

does this work with expo?

basically title. i was trying to implement it, following the example too and this error is all i am getting

RNFingerprintjsPro init error:  [TypeError: null is not an object (evaluating 'reactNative.NativeModules.RNFingerprintjsPro.init')] 

Version being set in dist file is 2.7.0

I've spun up a completely bare-bones repo with just node v20 and installed the latest fingerprintjs-pro-react-native package - https://github.com/fluz-jeff/fingerprintjs/blob/633e3cb98469c86cdf3fda4a1734a4e8179f5130/package.json#L12.

You can see the version defined in the dist directory is set as 2.7.0 - https://github.com/fluz-jeff/fingerprintjs/blob/633e3cb98469c86cdf3fda4a1734a4e8179f5130/node_modules/%40fingerprintjs/fingerprintjs-pro-react-native/dist/fpjs-pro-react-native.cjs.js#L341

Introduce "useVisitorData" hook

I'm wondering if we could introduce a similar hook as we have in https://github.com/fingerprintjs/fingerprintjs-pro-react for this package as well?

Something like this:

import {useVisitorData} from '@fingerprintjs/fingerprintjs-pro-react-native';

  const {
    isLoading,
    error,
    data,
  } = useVisitorData('PUBLIC_API_KEY', 'REGION');

I believe that it would provide a better developer experience, and make it more consistent with our react library.
To keep the consistency we can also omit the parameters here, and add a provider as well.

Things to consider:

  • would we also want to use the @fingerprintjs/fingerprintjs-pro-spa for caching?
  • maybe in order to avoid duplicating the code, we can use the logic from https://github.com/fingerprintjs/fingerprintjs-pro-react, while providing custom agent implementation, in order to use the native libraries under the hood?

WDYT?

Module RNFingerprintjsPro requires main queue setup since it overrides

There is a console warning from rn which I think we should pay attention to

Module RNFingerprintjsPro requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.

iOS: Error when adding endpoint in init

Getting this error when using the endpoint parameter in FingerprintJS.init:

index.bundle?platfor…&minify=false:27518 Exception '-[__NSCFString isFileReferenceURL]: unrecognized selector sent to instance 0x60000387a130' was thrown while invoking init on target RNFingerprintjsPro with params (
    ------, (hiding the real key here)
    us,
    "\"https://google.com\""(hiding the real domain)
)

Tried using different domains as well, no luck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.