Generic JS Agent Wrapper for SPAs

The fingerprintjs-pro-spa open-source library is a framework-agnostic wrapper over the Fingerprint Pro JS Agent with a built-in caching mechanism. It is used by our other frontend libraries under the hood.

👍

SDKs tailor-made for your framework

If you are using React (including Next, Preact), Vue, Svelte or Angular, we recommend using the SDK made for your specific framework.

If you are using vanilla JavaScript, a different framework, or just you prefer a lower-level library, feel free to use fingerprintjs-pro-spa to integrate Fingerprint Pro into your website.

Installation

Install using your favorite package manager:

npm install @fingerprintjs/fingerprintjs-pro-spa
yarn add @fingerprintjs/fingerprintjs-pro-spa

Create the client

Create a FpjsClient instance before rendering or initializing your application. You should only have one instance of the client.

import { FpjsClient } from '@fingerprintjs/fingerprintjs-pro-spa';

// It can receive multiple parameters but the only required one is `loadOptions`, which contains the public API key
const fpjsClient = new FpjsClient({
  loadOptions: {
    apiKey: "your-fpjs-public-api-key" // insert your public api key from the dashboard here
  }
});

You can learn more about different load options here: https://dev.fingerprint.com/docs/js-agent#agent-initialization

Initialise the JS agent

Before you start making identification requests to the Fingerprint Pro API, you need to initialize the Agent
to allow it to gather browser signals.
Make sure the initialization has been completed before calling the getVisitorData method to avoid errors.

// with async/await
await fpjsClient.init()
const visitorData = await fpjsClient.getVisitorData()

// with promises
const visitorData = fpjsClient.init().then(() => {
  return fpjsClient.getVisitorData()
})

Call the Fingerprint Pro API

The getVisitorData method returns visitor identification data based on the request options.
The second parameter ignoreCache will make sure that a request to the API is made even if the data is present in the cache.

// with async/await
const visitorData = await fpjsClient.getVisitorData({ extendedResult: true })

// with promises
const visitorData = fpjsClient.getVisitorData({ extendedResult: true }).then((visitorData) => {
  // use visitor data in your fraud prevention logic
  console.log(visitorData.visitorId);
});

Full documentation and source code are available on GitHub.