All articles Integration

Add Device Fingerprinting to a React App

Adding device intelligence to a React app is mostly about doing three things in the right order: load the agent without blocking your UI, get a stable visitor ID at the moments that matter, and verify that ID on your server before you trust it. Get the order wrong and you either slow down first paint or, worse, make security decisions on a value the client can fake.

This guide walks through a clean integration with a stable visitor ID and a confidence score, then shows how to feed the signals into a login and checkout flow. The patterns apply to any modern React setup; where Next.js differs, we note it and point to the Next.js integration guide.

Load the agent once, expose it through context

The agent should initialize a single time for the whole app, not per component. A tiny loader module pulls Prynt’s browser agent from the CDN once, and a small provider makes it available anywhere via a hook and keeps identification off the render path.

Packages: Prynt’s npm package is coming. Until then, use the script tag and the plain REST calls below; they work today.

// lib/prynt.js: loads Prynt's browser agent from the CDN once and reuses it.
let agent;

export function getPrynt() {
  agent ??= new Promise((resolve, reject) => {
    const s = document.createElement('script');
    s.src = 'https://api.pryntid.com/cdn/prynt.umd.js';
    s.async = true;
    s.onload = () => resolve(window.Prynt.load({
      apiKey: import.meta.env.VITE_PRYNT_PUBLIC_KEY,                    // pk_live_…
      endpoint: import.meta.env.VITE_PRYNT_URL || 'https://api.pryntid.com', // or your first-party origin
      extendedResult: true,
    }));
    s.onerror = () => { agent = undefined; reject(new Error('Prynt agent failed to load')); };
    document.head.appendChild(s);
  });
  return agent;
}
import { createContext, useContext, useEffect, useState } from 'react';
import { getPrynt } from './lib/prynt';

const FpContext = createContext(null);

export function FingerprintProvider({ children }) {
  const [agent, setAgent] = useState(null);

  useEffect(() => {
    let active = true;
    getPrynt()
      .then((a) => { if (active) setAgent(a); })
      .catch(() => {});  // agent blocked or offline: identify() just returns null
    return () => { active = false; };
  }, []);

  return <FpContext.Provider value={agent}>{children}</FpContext.Provider>;
}

export const useFingerprintAgent = () => useContext(FpContext);

Wrap your app once. Because it lives in useEffect, it runs after mount and never blocks first paint. Serving Prynt’s agent from your own first-party origin means endpoint points at a domain you control, which sidesteps ad blockers; see first-party agent serving for why that matters.

Identify at the moments that matter

Do not fingerprint on every render. Request identification at decision points, login submit, signup, checkout, so you spend the work where a signal changes an outcome.

import { useFingerprintAgent } from './FingerprintProvider';

export function useIdentify() {
  const agent = useFingerprintAgent();
  return async () => {
    if (!agent) return null;
    const { visitorId, confidence, requestId } = await agent.identify();
    return { visitorId, confidence, requestId };
  };
}

Two return values drive everything downstream. The visitorId is the stable device fingerprint that persists across cookie clears and incognito. The confidence is how sure the match is; a confidence score below your threshold means treat the identification as uncertain rather than authoritative. The requestId is the handle your server uses to fetch the verified result from Prynt’s API.

Verify on the server, always

This is the rule that separates a real integration from a toy: the browser value is a hint, never a decision. Anything client-side can be replayed or forged, so your server re-fetches the result from the API using the requestId and makes the call from that verified copy. This mirrors the Node server-side verification pattern.

// Express handler
app.post('/api/login', async (req, res) => {
  const { requestId, email } = req.body;

  const r = await fetch(`https://api.pryntid.com/v1/events/${encodeURIComponent(requestId)}`, {
    headers: { Authorization: `Bearer ${process.env.PRYNT_SECRET_KEY}` },
  });
  if (!r.ok) return res.status(400).end();          // 404 = unknown requestId
  const result = await r.json();

  const { visitorId, confidence } = result;
  const bot = result.smartSignals?.bot?.result;

  if (confidence.score < 0.8) return stepUp(res);  // uncertain device
  if (bot) return res.status(403).end();           // automation
  return continueLogin(res, { email, visitorId });
});

The API does not expire or burn a requestId, so add that check yourself: reject events whose createdAt is more than a minute old and record each requestId you accept, so a captured one cannot be replayed later. Everything you act on, the visitor ID, the confidence, the bot signal, comes from the server-fetched result, not from the request body.

If you would rather skip that API call, turn on Sealed Results (sealedResult: true in Prynt.load). The browser then receives only an encrypted sealedResult, which your server decrypts locally with the sealing key from the console (AES-256-GCM; a ten-line unsealResult helper using node:crypto is shown in the Sealed Results post). Both paths are sound; fetching by requestId is the simpler default.

Wire signals into real flows

With a verified visitor ID and confidence in hand, the integration becomes a set of small policy decisions rather than a big rewrite.

A compact policy table keeps the React side honest about what each decision needs:

FlowTrust thresholdAction on fail
Loginconfidence >= 0.8, no bot flaglight step-up
Signupdevice seen < N accountsmanual review
Checkouttrusted device history3-D Secure or hold

Common mistakes to avoid

A few pitfalls turn a good integration into a fragile one.

  • Blocking render on identification — never await the agent before first paint. Load async, identify on interaction.
  • Deciding client-side — a gate written purely in React is bypassed with the console open. Decide on the server.
  • Ignoring confidence — treating a 0.5 match as certain manufactures false positives. Thread confidence through every decision.
  • Fingerprinting on mount everywhere — wasteful and noisy. Identify at decision points only.
  • Forgetting consent and privacy — collect what you need, document it, and follow GDPR guidance for your jurisdiction.

Frequently asked questions

Can I trust the visitor ID returned in the browser?

Never for a security decision. Always re-verify the ID server-side against the vendor API, because anything the client sends can be forged; the browser value is only useful for UX hints.

Where should I call the fingerprinting SDK in a React app?

Load the agent once at app startup and expose the result through context or a hook, then request a fresh identification at the specific moments that matter, such as login submit or checkout.

Does fingerprinting hurt React performance?

The agent is small and runs asynchronously, so identify off the render path and after interaction rather than blocking first paint, and cache the result for the session.

A clean React integration is small: one provider, one hook, and a server route that verifies before it trusts. From there, the visitor ID and confidence score become inputs to whatever fraud logic your product needs, from login step-up to checkout review. Browse the SDKs, try the playground, and read the docs to go from this skeleton to production.

Try it free

Prynt is device intelligence with a free plan: 5,000 identifications a month, visitor IDs with confidence and bot detection — no credit card. Upgrade to Pro for VPN, proxy, tampering and behavioral signals.

Keep reading