@fingerprint/react

中文文档
3.3.0发布于 2026/10/26MITTypeScriptESM + CJS构建来源已验证近 30 天下载 42.2万

Fingerprint React SDK

原始使用文档
文档目录12 节
  1. Table of contents
  2. Requirements
  3. Installation
  4. Getting started
  5. 1. Wrap your application (or component) in <FingerprintProv…
  6. 2. Use the useVisitorData() hook in your components to iden…
  7. Linking and tagging information
  8. Error handling
  9. API Reference
  10. Version support
  11. Support and feedback
  12. License

Fingerprint logo

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

Fingerprint React

Fingerprint is a device intelligence platform offering industry-leading accuracy. Fingerprint React SDK is an easy way to integrate Fingerprint 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 19
  • 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 subscription or trial, it is not compatible with the open-source FingerprintJS. See our documentation to learn more about the differences between Fingerprint and the open-source FingerprintJS.

Installation

Using npm:

npm install @fingerprint/react

Using yarn:

yarn add @fingerprint/react

Using pnpm:

pnpm add @fingerprint/react

Getting started

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

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

// src/index.js
import React from 'react'
import ReactDOM from 'react-dom/client'
import { FingerprintProvider } from '@fingerprint/react'
import App from './App'

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

// <FingerprintProvider /> supports the same options as `start()` function.
root.render(
  <FingerprintProvider
    apiKey='PUBLIC_API_KEY'
    cache={{ storage: 'sessionStorage', duration: 3600 }}
  >
    <App />
  </FingerprintProvider>
)

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

// src/App.js
import React from 'react'
import { useVisitorData } from '@fingerprint/react'

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

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

  if (isFetched) {
    return <div>Welcome {data.visitor_id}!</div>
  }
  
  return null
}

export default App

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

Both useVisitorData and getData accept all the get options available in the JavaScript agent get function.

The returned v4 visitor data uses raw response field names in snake_case, for example visitor_id and event_id.

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

function App() {
  const { isLoading, error, getData } = useVisitorData(
    { 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.visitor_id)
            })
            .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
  • You can pass { immediate: false } to disable automatic identification and call getData manually instead.
  • By default ({ immediate: true }), the hook automatically identifies the visitor after mounting and whenever its request options change. Changing immediate from false to true also starts an identification request with the latest options.
  • 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 visitor ID 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 tags, see Linking and tagging information.

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

// ...
function App() {
  const { isLoading, error, getData } = useVisitorData({
    linkedId: 'user_1234',
    tags: {
      userAction: 'login',
      analyticsId: 'UA-5555-1111-1',
    },
  })
}
// ...

[!NOTE] The tag option is deprecated in favor of tags. tag still works, but if both are provided, tags takes precedence.

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.

Version support

SDK major versionJS Agent versionStatusEnd of support
v3.x (current)v4Supported-
v1.x-v2.xv3Deprecated (security fixes only). See the migration guide.To be decided

Support and feedback

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

License

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

版本与发布记录

@fingerprint/react 共发布 6 个版本,首次发布于 2026/01/28;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.3.0latest2026/10/2619 天前
3.2.02026/09/142 个月前
3.1.02026/07/273 个月前
3.0.1-test.0test2026/05/275 个月前
3.0.02026/01/299 个月前
3.0.0-test.32026/01/289 个月前

关于 @fingerprint/react 的常见问题

@fingerprint/react 是什么?

Fingerprint React SDK

如何安装 @fingerprint/react?

在项目目录运行 npm install @fingerprint/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18 <20)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fingerprint/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fingerprint/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fingerprint/react 可以商用吗?

@fingerprint/react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fingerprint/react 的下载量有多少?

根据 npm 官方下载统计,@fingerprint/react 在 2026/10/15 – 2026/11/13 这 30 天内被下载 422,152 次,日均约 14,072 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fingerprint/react 还在维护吗?

最新版本 3.3.0 发布于 2026/10/26(19 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/01/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。