Package Exports
- @fingerprintjs/fingerprintjs-pro-react-native
- @fingerprintjs/fingerprintjs-pro-react-native/build/fpjs-pro-react-native.cjs.js
- @fingerprintjs/fingerprintjs-pro-react-native/build/fpjs-pro-react-native.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fingerprintjs/fingerprintjs-pro-react-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Fingerprint Pro React Native
Official React Native module for 100% accurate device identification, created for Fingerprint Pro.
This module can be used in a React Native application to call the native Fingerprint Pro libraries and identify devices.
Fingerprint Pro is a professional visitor identification service that processes all information server-side and transmits it securely to your servers using server-to-server APIs.
Retrieve an accurate, sticky and stable Fingerprint Pro visitor identifier in an Android or an iOS app. This library communicates with the Fingerprint Pro API and requires an api key.
Native libraries used under the hood:
Quick start
1. Add @fingerprintjs/fingerprintjs-pro-react-native to your application via npm or yarn:
npm install @fingerprintjs/fingerprintjs-pro-react-native --save
or
yarn 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
Fingerprint Pro public API key
To identify visitors, you need a Fingerprint Pro account (you can sign up for free).
- Go to the Fingerprint Pro dashboard
- Open the API keys page from the sidebar
- Find your Public API key
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'
// =================================================================================================^^^^^^^^^^^^^^^^^^^^^^^^^^^^LinkedId and tags
linkedId is a way of linking current analysis event with a custom identifier. This will allow you to filter visit information when using the Server API
More information about approaches you can find in the js agent documentation.
tag is a customer-provided value or an object that will be saved together with the analysis event and will be returned back to you in a webhook message or when you search for the visit in the server API.
More information about approaches you can find in the js agent documentation.
Providing linkedId and tags with hooks approach
const { getData } = useVisitorData();
const tags = {
tag1: 'string tag',
tag2: 42,
tag3: true,
tag4: [0, 1, 1, 2, 5],
tag5: { foo: 'bar' }
};
const linkedId = 'custom id';
const visitorData = await getData(tags, linkedId);Providing linkedId and tags with API Client approach
const { getData } = useVisitorData();
const tags = {
tag1: 'string tag',
tag2: 42,
tag3: true,
tag4: [0, 1, 1, 2, 5],
tag5: { foo: 'bar' }
};
const linkedId = 'custom id';
const visitorId = await FingerprintClient.getVisitorId(tags, linkedId); // Use this method if you need only visitorId
const visitorData = await FingerprintClient.getVisitorData(tags, linkedId); // Use this method if you need additional information about visitorAPI Reference
You can find API reference here.
Additional Resources
Limitations
- Fingerprint Pro request filtering is not supported right now. Allowed and forbidden origins cannot be used.
- Using inside Expo environment is not supported right now.
License
This library is MIT licensed.