Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@fingerprintjs/fingerprintjs-pro-react

fingerprintjs91.8kMIT2.6.3TypeScript support: included

FingerprintJS Pro React SDK

fraud, fraud detection, fraud prevention, browser, identification, fingerprint, fingerprinting, browser fingerprint, device fingerprint, privacy

readme

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://fingerprintjs.github.io/home/resources/logo_light.svg" /> <source media="(prefers-color-scheme: light)" srcset="https://fingerprintjs.github.io/home/resources/logo_dark.svg" /> Fingerprint logo </picture>

CI badge coverage Current NPM version Monthly downloads from NPM MIT license Discord server Discord server

Fingerprint Pro React

Fingerprint is a device intelligence platform offering 99.5% accurate visitor identification. Fingerprint Pro React SDK is an easy way to integrate Fingerprint Pro into your React application. It's also compatible with Next.js and Preact. See application demos in the examples folder.

Table of contents

Requirements

  • React 18 or higher
  • For Preact users: Preact 10.3 or higher
  • For Next.js users: Next.js 13.1 or higher
  • For Typescript users: Typescript 4.8 or higher

[!NOTE] This package assumes you have a Fingerprint Pro subscription or trial, it is not compatible with the source-available FingerprintJS. See our documentation to learn more about the differences between Fingerprint Pro and FingerprintJS.

Installation

Using npm:

npm install @fingerprintjs/fingerprintjs-pro-react

Using yarn:

yarn add @fingerprintjs/fingerprintjs-pro-react

Using pnpm:

pnpm add @fingerprintjs/fingerprintjs-pro-react

Getting started

In order to identify visitors, you'll need a Fingerprint Pro account (you can sign up for free). To get your API key and get started, see the Fingerprint Pro Quick Start Guide.

1. Wrap your application (or component) in <FpjsProvider>.

// src/index.js
import React from 'react'
import ReactDOM from 'react-dom/client'
import { FpjsProvider /*, FingerprintJSPro */ } from '@fingerprintjs/fingerprintjs-pro-react'
import App from './App'

const root = ReactDOM.createRoot(document.getElementById('app'))

root.render(
  <FpjsProvider
    loadOptions={{
      apiKey: 'your-public-api-key',
      // region: 'eu',
      // endpoint: ['metrics.yourwebsite.com', FingerprintJSPro.defaultEndpoint],
      // scriptUrlPattern: ['metrics.yourwebsite.com/agent-path', FingerprintJSPro.defaultScriptUrlPattern],
    }}
  >
    <App />
  </FpjsProvider>
)

2. Use the useVisitorData() hook in your components to identify visitors

// src/App.js
import React from 'react'
import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react'

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

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

  if (data) {
    // Perform some logic based on the visitor data
    return (
      <div>
        Welcome {data.visitorFound ? 'back' : ''}, {data.visitorId}!
      </div>
    )
  } else {
    return null
  }
}

export default App

The useVisitorData hook also returns a getData method you can use to make an API call on command.

// src/App.js
import React, { useState } from 'react'
import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react'

function App() {
  const { isLoading, error, getData } = useVisitorData({ tag: 'subscription-form' }, { immediate: false })
  const [email, setEmail] = useState('')

  if (isLoading) {
    return <div>Loading...</div>
  }
  if (error) {
    return <div>An error occurred: {error.message}</div>
  }

  return (
    <div>
      <form
        onSubmit={(e) => {
          e.preventDefault()
          getData()
            .then((data) => {
              // Do something with the visitor data, for example,
              // append visitor data to the form data to send to your server
              console.log(data)
            })
            .catch((error) => {
              // Handle error
            })
        }}
      >
        <label htmlFor='email'>Email:</label>
        <input type='email' value={email} onChange={(e) => setEmail(e.currentTarget.value)} />
        <button type='submit'>Subscribe</button>
      </form>
    </div>
  )
}

export default App
  • See the full code example in the examples folder.
  • See our Use cases page for open-source real-world examples of using Fingerprint to detect fraud and streamline user experiences.

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.

Associate the visitor ID with your data using the linkedId or tag parameter of the options object passed into the useVisitorData() hook or the getData function:

// ...

function App() {
  const {
    isLoading,
    error,
    getData
  } = useVisitorData({
    linkedId: "user_1234",
    tag: {
      userAction: "login",
      analyticsId: "UA-5555-1111-1"
    }
  });

// ...

Caching strategy

Fingerprint Pro usage is billed per API call. To avoid unnecessary API calls, it is a good practice to cache identification results. By default, the SDK uses sessionStorage to cache results.

  • Specify the cacheLocation prop on <FpjsProvider> to instead store results in memory or localStorage. Use none to disable caching completely.
  • Specify the cache prop on <FpjsProvider> to use your custom cache implementation instead. For more details, see Creating a custom cache in the Fingerprint Pro SPA repository (a lower-level Fingerprint library used by this SDK).
  • Pass {ignoreCache: true} to the getData() function to ignore cached results for that specific API call.

[!NOTE] If you use data from extendedResult, pay additional attention to your caching strategy. Some fields, for example, ip or lastSeenAt, might change over time for the same visitor. Use getData({ ignoreCache: true }) to fetch the latest identification results.

Error handling

The getData function throws errors directly from the JS Agent without changing them. See JS Agent error handling for more details.

API Reference

See the full generated API reference.

Support and feedback

To ask questions or provide feedback, use Issues. If you need private support, please email us at `oss-support@fingerprint.com`. If you'd like to have a similar React wrapper for the open-source FingerprintJS, consider creating an issue in the main FingerprintJS repository.

License

This project is licensed under the MIT license. See the LICENSE file for more info.

changelog

2.6.3 (2024-03-21)

Bug Fixes

  • review (951860c)
  • set initial isLoading according to config.immediate (3194f33)

Build System

2.6.2 (2023-11-17)

Documentation

  • README: fix badge underlines (0699feb)
  • README: improve caching explanation (9e109d4)
  • README: phrasing tweaks (2b954e6)
  • README: small grammar fixes (93ed29e)

2.6.1 (2023-10-18)

Documentation

  • README: add requirements section (fddd22f)

2.6.0 (2023-10-11)

Features

  • update @fingerprintjs/fingerprintjs-pro-spa to 1.2.0, add FingerprintJSPro export (8066afe)

2.5.1 (2023-09-14)

Bug Fixes

  • add CustomAgent support (01d5024)
  • bump spa package version to 1.1.2 (6fdf561)

Build System

  • deps: bump semver from 5.7.1 to 5.7.2 (5f086bb)
  • deps: bump semver from 5.7.1 to 5.7.2 in /examples/preact (909c868)
  • deps: bump semver from 6.3.0 to 6.3.1 in /examples/webpack-based (25c9369)
  • deps: bump semver in /examples/create-react-app (e10dc7f)
  • deps: bump tough-cookie from 4.1.2 to 4.1.3 (9a35428)
  • deps: bump tough-cookie in /examples/create-react-app (a3882fb)
  • deps: bump word-wrap from 1.2.3 to 1.2.4 (85e43fc)
  • deps: bump word-wrap from 1.2.3 to 1.2.5 in /examples/preact (ce8d845)
  • deps: bump word-wrap in /examples/create-react-app (c74d026)

2.5.0 (2023-07-06)

Features

  • add reexports of defaultEndpoint, defaultScriptUrlPattern, defaultTlsEndpoint (b701883)

Documentation

  • README: update a polish readme.md (3e04a52)

2.4.0 (2023-06-09)

Features

  • extend getData options with fingerprintjs-pro GetDataOptions. #108 (fe2961e)

Build System

  • deps: update typedoc version to get improved documentation page design (778bb4d)

2.3.3 (2023-04-17)

Bug Fixes

  • bump @fingerprintjs/fingerprintjs-pro-spa package to 1.0.2 (c59f303)
  • fix release pipeline to have a correct version in integrationInfo (5ed7ce6)

2.3.2 (2023-04-12)

Bug Fixes

  • update SPA package with fallback for localStorage and sessionStorage (2f61ba8)

Build System

  • deps: bump webpack in /examples/create-react-app (fa6095f)

2.3.1 (2023-03-14)

Bug Fixes

  • add webpack example (8274ef2)
  • failed webpack builds #97 (8111970)
  • make webpack demo similar to our code snipper (09e1021)

Build System

  • deps: bump dns-packet in /examples/create-react-app (f07fcef)

2.3.0 (2023-02-24)

Features

  • add use client directive to the bundled code (ae2bf8a)

Bug Fixes

  • add exports field to package.json (4b0fe82)

Build System

  • deps: bump decode-uri-component from 0.2.0 to 0.2.2 (140a9bc)
  • deps: bump decode-uri-component in /examples/preact (2dca013)
  • deps: bump decode-uri-component in /examples/spa (03e78fb)
  • deps: bump http-cache-semantics from 4.1.0 to 4.1.1 (43c0df1)
  • deps: bump http-cache-semantics in /examples/preact (124cc38)
  • deps: bump json5 from 1.0.1 to 1.0.2 (53fcf7e)
  • deps: bump json5 from 1.0.1 to 1.0.2 in /examples/spa (8deef15)

2.2.0 (2022-12-30)

Features

  • remove "undefined" and "void" from return type in getVisitorData (c7dd49e)

2.1.1 (2022-11-17)

Bug Fixes

  • update SPA library to 0.7.0 (2018592)

Build System

  • deps: bump loader-utils from 2.0.3 to 2.0.4 in /examples/spa (5019ec9)

2.1.0 (2022-11-10)

Features

  • bump SPA package to 0.6.0 (b3fd55e)

2.0.1 (2022-11-09)

Build System

  • deps: bump loader-utils from 2.0.2 to 2.0.3 in /examples/spa (32b6467)

2.0.0 (2022-11-02)

⚠ BREAKING CHANGES

  • Previously "getData" was returning "undefined" when error occurred

Features

  • throw on error when calling "getData" manually (3df14fc)

1.5.0 (2022-10-31)

Features

  • throw error if params passed to "useVisitorData" or "getData" are null (41e2068)

Bug Fixes

  • ensure that "products" parameter is correctly passed into the client (5c0dbd4)
  • use correct errors messages from pro agent (b2e1a7f)

1.4.1 (2022-10-25)

Bug Fixes

  • fix broken navigation when using <FpjsProvider /> (e518cbc)

1.4.0 (2022-10-04)

Features

  • introduce synchronous env detection (6ba1fd0)
  • support ignoring cache with "immediate" set to true (d55bc4c)

Build System

  • deps: bump terser from 4.8.0 to 4.8.1 in /examples/preact (6947ad5)
  • deps: bump terser from 5.13.1 to 5.14.2 in /examples/spa (e94c1ce)
  • deps: update FingerprintJS Pro SPA to 0.5.0 (e4f4039)

Documentation

  • README: add documentation badge (e4a8365)
  • README: remove manually written API reference from readme in favor of generated one (f534021)
  • README: update examples to use ReactDOM.createRoot (ed69e26)

1.3.1 (2022-07-15)

Bug Fixes

  • correctly provide contextual information when provider is mounted (5d8f195)

1.3.0 (2022-07-14)

Bug Fixes

  • use correct cwd in post-install script (7b8e96c)

Features

  • add contextual information for the JS agent about the library (d55e164)

1.3.0-test.2 (2022-07-13)

Bug Fixes

  • use correct cwd in post-install script (7b8e96c)

1.3.0-test.1 (2022-07-13)

Features

  • add contextual information for the JS agent about the library (d55e164)

1.2.0 (2022-07-11)

Features

  • use latest @fingerprintjs/fingerprintjs-pro-spa version (3576871)

1.1.0 (2022-06-20)

Chores
  • add eslint-config-preact as main package devDependency (4e8dc72e)
  • update packages (887d4d9f)
Documentation Changes
  • add preact example description to the contributing instruction (92f96c94)
  • fix typos (009a418a)
New Features
  • add preact example (f280bedf)
  • remove react from peerDeps for better preact compatibility (fd68db69)
Bug Fixes

1.0.1 (2022-05-16)

Chores
  • use production environment for npm publish (1c814d00)
  • deps: update deps for spa example (8f0c1ac6)
Documentation Changes
  • mention Next.js in the readme (f5df094f)

1.0.0 (2022-04-21)

Breaking Changes
  • change getData interface to more flexible (8c701414)
Chores
  • update actions to fix git issue with safe.directory (c3ff1c93)
  • fix mock for tests (cf804544)
  • apply prettier, fix linter issues (1397498f)
  • keep all linter settings in root (c6188443)
  • add codeowners file (a097794c)
  • don't create tag on version command (84b49fd6)
  • update node-forge (b697548e)
  • update minimist (02cc142f)
  • regenerate example package.lock for new fingerprintjs-pro-spa (d060112a)
  • add --isolatedModules for typecheck (547fbc99)
  • use 3-rd party GitHub action by sha (14ed2dbc)
  • update fingerprintjs-pro-spa integration with fingerprintjs-pro agent v3.6.0+ (8157dd18)
  • deps:
    • bump rollup-plugin-license (e4f9905c)
    • bump minimist from 1.2.5 to 1.2.6 (5c563329)
Continuous Integration
  • revert reference type from 'file' to 'link' (4c88b15f)
Documentation Changes
  • fix readme after review (5d0973af)
  • add info about NextJS example in contributing instruction (dc302f79)
  • review suggested fix (77ec7a7d)
  • update table of contents (72ecdce3)
  • add info about caching and describe useVisitorData hook (0f39f1a1)
  • add contributing.md (d09e68cb)
  • explain immediate property (bfcec74b)
  • add info about config parameter for the hook (59d40598)
  • fix Documentation section styling (af00b128)
  • format Documentation section (a9309abf)
  • remove separators (d84ef748)
  • add documentation (38e83a3c)
New Features
Bug Fixes
  • don't try to load FingerptintJS Pro Agent outside browser environment (eda093bb)

0.3.0 (2022-03-14)

Chores
New Features
  • pass config to the useVisitorData hook (750733a3)
Bug Fixes
  • race condition (getData called before init) (0c787786)

0.2.2 (2022-03-11)

Chores
  • add automatic changelog generation (9126a8e6)
  • bumped fingerprintjs-pro-spa version (4c5237b8)
Bug Fixes

0.2.1

Chores
  • Bumped fingerprintjs-spa-pro version

0.2.0

  • Initial release