Skip to main content
You can use Fingerprint with any frontend framework or meta-framework, whether your page is rendered in the browser, on the server, or statically generated. You just need to ensure that loading the Fingerprint JavaScript agent and performing the visitor analysis happens on the client and not on the server. Since fingerprinting relies on signals from various browser APIs it cannot run outside the browser. Each (meta-)framework has its own way of specifying which code is client-only. If you use any of our client SDKs, it typically handles this for you automatically, but the details can vary depending on the SDK. You can find more information in the respective framework sections below. This guide will demonstrate the common patterns for Next.js, Nuxt, Gatsby, and Angular SSR.

Next.js

Using our React SDKWe recommend using the Fingerprint React SDK which exposes the getData function and its result in a useVisitorData() hook. Since hooks cannot be used inside server components or server-side functions, you are forced to do the right thing by default.
TypeScript
In Next.js, the boundary between client and server is defined differently depending on if you are using the pages directory (how Next.js worked traditionally) or the new app directory (introduced in Next.js 13).

The pages directory

You can import and use the JavaScript agent inside components but not inside getStaticProps or getServerSideProps. You can still use the JavaScript agent on a page that is server-side rendered or statically generated, just do it in the component itself.
Note: In this context, “inside the component” means inside an event handler (e.g., onClick), a life cycle method (e.g., componentDidMount), or an effect (e.g., useEffect). Calling the JavaScript agent at the base of the component definition or its render method would also result in document is not defined error on server-side rendered pages.
Examples of correct JavaScript agent usage in a static page (with or without static props) and a server-rendered page:
Some examples of antipatterns:

The app directory

All components inside the app directory are server-side by default. To use the JavaScript agent, put it in a Client Component that begins with the 'use client'; directive, and call the agent from useEffect or an event handler. This lets the component use client-side React APIs while ensuring the Fingerprint call runs in the browser.
If you are using the Fingerprint React SDK, you need to wrap your app (or the part of it that uses Fingerprint) inside FingerprintProvider. You can do this by putting the provider in a layout.tsx file. Since the provider uses Context under the hood, you either need to turn the entire layout into a client-side component with 'use client'; or wrap the FingerprintProvider inside a client component:
See the Next.js documentation for more details on client and server-side rendering.

Nuxt

Using our Vue SDKInstead of importing the JavaScript agent directly, we recommend you take advantage of the Fingerprint Vue SDK, available as @fingerprint/vue. The same principle applies here:
  • Register Fingerprint as a client-side plugin by creating a fingerprintjs.client.ts file inside the plugins folder (the client suffix is important).
  • Wrap the component using Fingerprint inside the <ClientOnly> tag in your app template.
See the Vue SDK documentation for more details and examples.
When using Nuxt, make sure to import and call the Fingerprint JavaScript agent in client-side code only. For example, you can create a component that calls the JS client inside its <script setup> tag, then wrap the component inside <ClientOnly>.
Learn more in Nuxt documentation.

Gatsby

Similar to Next.js, you can use the Fingerprint JavaScript agent inside component effects, event handlers and lifecycle methods. Using it inside getServerData(), component render functions and other server-side code will not work.
See the Gatsby documentation for more details and alternative approaches to running client-side-only code. For a smoother development experience, consider using the useVisitorData() hook from the Fingerprint React SDK.

Angular SSR

The Fingerprint Angular SDK (@fingerprint/angular) does not initialize the JavaScript agent on the server. FingerprintService checks isPlatformBrowser internally, so server rendering will not run the agent. Call getVisitorData() from browser-only flows, such as hydrated user interactions, or handle the rejected promise if the method can run during SSR. If you prefer to use the JavaScript agent directly instead of the Angular SDK, make sure to run Fingerprint only in the browser. You can inject the Angular-provided PLATFORM_ID constant and check it with isPlatformBrowser:
app.ts
Learn more about server-side rendering in the Angular SSR documentation.

Other frameworks

  • Astro is a multi-page application framework where all pages are static by default with “islands” of client-side interactivity. Use Fingerprint inside an island. Read more about Astro’s island architecture.
  • Remix is a React meta-framework similar to Next.js. For information on how to avoid running browser-only code on the server with Remix, see their Module constraints documentation.
  • SvelteKit is a Svelte meta-framework providing static generation and server-side rendering capabilities. You can run Fingerprint client-side only inside event handlers, lifecycle methods like onMount or by checking the browser constant in the @app/environment module.
Regardless of the framework you use, the principle is the same. Fingerprint relies on browser-only APIs so you can only run it in the browser, not on the server.