Next.js
In Next.js, the boundary between client and server is defined differently depending on if you are using thepages 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.,Examples of correct JavaScript agent usage in a static page (with or without static props) and a server-rendered page: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 indocument is not definederror on server-side rendered pages.
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.
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:
Nuxt
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>.
Gatsby
Similar to Next.js, you can use the Fingerprint JavaScript agent inside component effects, event handlers and lifecycle methods. Using it insidegetServerData(), component render functions and other server-side code will not work.
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
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
onMountor by checking thebrowserconstant in the@app/environmentmodule.