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 JS agent inside components but not inside getStaticProps or getServerSideProps. You can still use the JS 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 JS 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 JS 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 JS agent, wrap it inside a component that begins with the 'use client'; directive. This tells Next.js to render the component only in the browser. Then you can use it on a page inside app.
FpjsProvider. 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 FpjsProvider inside a client component:
Nuxt
When using Nuxt, make sure to import and call the Fingerprint JS 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 JS 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 Universal
When using server-side rendering with Angular Universal, you can use Fingerprint in component constructors and methods as these are executed in the browser only:app.component.ts
PLATFORM_ID constant into your function.
app.component.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.