> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fingerprint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Svelte Quickstart

> Get started using the Fingerprint Svelte SDK

## Overview

In this quickstart, you'll add Fingerprint to a new [Svelte 5](https://svelte.dev/) project and identify the user's device.

The example use case in this quickstart is stopping new account fraud, where attackers create multiple fake accounts to abuse promotions, exploit systems, or evade bans. However, the steps you'll follow apply to most use cases. By identifying the device behind each sign-up attempt, login, or transaction, you can flag and block suspicious users early.

This guide focuses on the frontend integration. You'll install the [Fingerprint Svelte SDK](/docs/v3/svelte) and initialize the JavaScript agent to generate a request ID to send to your backend for analysis. **To see how to implement fraud prevention with this ID, continue to one of the [backend quickstarts](/docs/v3/server-quickstarts-overview) after completing this quickstart.**

> Estimated time: \< 10 minutes

## Prerequisites

Before you begin, make sure you have the following:

* [Node.js](https://nodejs.org/) (v20 or later) and npm installed
* Your favorite code editor
* Basic knowledge of [Svelte 5](https://svelte.dev/) and JavaScript

<Note>
  This quickstart only covers the **frontend setup**. You'll need a [backend
  server](/reference/server-sdks) to receive and process the device identification event to enable
  fraud detection. Check out one of the [backend quickstarts](/docs/v3/server-quickstarts-overview)
  after completing this quickstart.
</Note>

## 1. Create a Fingerprint account and get your API key

1. [Sign up](https://dashboard.fingerprint.com/signup) for a free Fingerprint trial if you don't already have an account.
2. After signing in, go to the [**API keys**](https://dashboard.fingerprint.com/api-keys) page in the dashboard.
3. Copy your **public API key**; you'll need it to initialize the JavaScript agent.

## 2. Set up your project

To get started, scaffold a new Svelte app. If you already have a project you want to use, you can skip to the next section.

1. Create a new Vite project with the Svelte template:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm create vite@latest fingerprint-svelte-quickstart -- --template svelte
cd fingerprint-svelte-quickstart
npm install
```

2. Open the `fingerprint-svelte-quickstart` folder in your code editor and you're ready to go! To run your project, run:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm run dev
```

3. In your browser, go to [http://localhost:5173](http://localhost:5173/) (Vite's default), and you should see the Vite welcome page.

## 3. Set up your account creation form

1. Before adding Fingerprint, create a new component at `src/lib/CreateAccountForm.svelte` with the following:

```svelte src/lib/CreateAccountForm.svelte theme={"theme":"github-dark-dimmed"}
<script>
  // Logic will be added later
</script>

<div class="wrapper">
  <h1>Create an account</h1>
  <div class="input-group">
    <label for="username">Username</label>
    <input
      id="username"
      bind:value={username}
      type="text"
      placeholder="Username"
      required
    />
  </div>
  <div class="input-group">
    <label for="password">Password</label>
    <input
      id="password"
      bind:value={password}
      type="password"
      placeholder="Password"
      required
    />
  </div>
  <button disabled={$isLoading} onclick={handleSubmit}>
    {$isLoading ? "Loading…" : "Create Account"}
  </button>
</div>

<style>
  .wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 1rem;
    padding: 1rem;
  }

  input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
  }

  .input-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  button {
    background-color: #f35b22;
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
  }

  button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
</style>
```

2. Import and add the component to your main app in `src/App.svelte`. You can replace the whole file with:

```svelte src/App.svelte theme={"theme":"github-dark-dimmed"}
<script>
  import CreateAccountForm from "./lib/CreateAccountForm.svelte";
</script>

<CreateAccountForm />
```

## 4. Install and initialize the JavaScript agent

1. To integrate Fingerprint into your Svelte app, first add the Fingerprint Svelte SDK via npm:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm install @fingerprintjs/fingerprintjs-pro-svelte --legacy-peer-deps
```

*Note: This quickstart is written for version 2.x of the Fingerprint Svelte SDK. The SDK has a dependency for Svelte 4 but works with Svelte 5.*

2. Now that the Svelte SDK is installed, you can import and configure the Fingerprint provider. Update `App.svelte` and add the following to the `<script>` block:

```svelte src/App.svelte theme={"theme":"github-dark-dimmed"}
<script>
  import CreateAccountForm from "./lib/CreateAccountForm.svelte";
  import { FpjsProvider } from "@fingerprintjs/fingerprintjs-pro-svelte"; // [!code ++]

  const options = { // [!code ++:7]
    loadOptions: {
      apiKey: "PUBLIC_API_KEY",
      region: "us", // Ensure this matches your workspace region
      // For more information, see https://docs.fingerprint.com/docs/regions
    },
  };
</script>
```

3. Replace `PUBLIC_API_KEY` with your actual public API key from the [Fingerprint dashboard](https://dashboard.fingerprint.com/api-keys).

*Note: For production, consider using* [*Vite Env Variables*](https://vite.dev/guide/env-and-mode) *to configure the key.*

4. Wrap `<CreateAccountForm />` with the `FpjsProvider` component:

```svelte src/App.svelte theme={"theme":"github-dark-dimmed"}
<FpjsProvider {options}>
  <CreateAccountForm />
</FpjsProvider>
```

## 5. Trigger visitor identification

Now that the JavaScript agent is initialized, you can identify the visitor only when needed. In this case, that's when the user taps the **Create Account** button.

When making the visitor identification request, you will receive the `visitorId` as well as a `requestId`. Instead of using the `visitorId` returned directly on the frontend (which could be tampered with), you'll send the `requestId` to your backend. This ID is unique to each identification event. Your server can then use the [Fingerprint Events API](/reference/v3/server-api-get-event) to retrieve complete identification data, including the trusted visitor ID and other actionable insights like whether they are using a VPN or are a bot.

1. Within the empty script tags in `CreateAccountForm.svelte`, declare `username` and `password` as reactive variables to track your form inputs, and import the Fingerprint `useVisitorData` hook:

```svelte src/lib/CreateAccountForm.svelte theme={"theme":"github-dark-dimmed"}
<script>
  import { useVisitorData } from "@fingerprintjs/fingerprintjs-pro-svelte";

  let username = $state("");
  let password = $state("");
</script>
```

2. Initialize `useVisitorData` and access the returned values you'll need:

```svelte src/lib/CreateAccountForm.svelte theme={"theme":"github-dark-dimmed"}
<script>
  import { useVisitorData } from "@fingerprintjs/fingerprintjs-pro-svelte";

  let username = $state("");
  let password = $state("");

  const { data, isLoading, getData } = useVisitorData({}, { immediate: false }); // [!code ++]
</script>
```

This gives you:

* `getData()`: A function to trigger visitor identification on demand.
* `data`: A data store that holds the `visitorId`, `requestId`, and more details.
* `isLoading`: A flag to monitor visitor identification progress.

By setting `immediate` to `false` you're triggering device identification only when needed with the `getData()` method.

*Check our* [*GitHub repo*](https://github.com/fingerprintjs/fingerprintjs-pro-svelte) *for available* *`useVisitorData`* *options.*

3. Define the submit handler to trigger identification when the user clicks **Create Account**:

```svelte src/lib/CreateAccountForm.svelte theme={"theme":"github-dark-dimmed"}
async function handleSubmit() {
  await getData();
  if (!$data) return;

  const { visitorId, requestId } = $data;
  console.log("Visitor ID:", visitorId);
  console.log("Request ID:", requestId);

  // Send requestId and form data to your server
  // await fetch('/api/create-account', {
  //   method: 'POST',
  //   headers: { 'Content-Type': 'application/json' },
  //   body: JSON.stringify({ username, password, requestId }),
  // });
}
```

In this function:

* `getData()` is being called, and Fingerprint is analyzing the visitor's browser; the result of the identification will be stored in `data`.
* The `data` object will include a `requestId`, which you can then send to your backend along with the username and password.

## 6. Test the app

1. If your dev server isn't already running, start it with:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm run dev
```

2. In your browser, go to [http://localhost:5173](http://localhost:5173) (Vite's default).
3. If you have any ad blockers, turn them off for localhost. View the [documentation](/docs/v3/protecting-the-javascript-agent-from-adblockers) to learn how to protect your Fingerprint implementation from ad blockers in production.
4. Enter a username and password, then click **Create Account**.
5. Open the developer console in your browser, and you should see the `visitorId` and `requestId` in the output:

```text Output theme={"theme":"github-dark-dimmed"}
Visitor ID: JkLmNoPqRsTuVwXyZaBc
Request ID: 1234566477745.abc1GS
```

## Next steps

To use the identification data for fraud detection (like blocking repeat fake account creation attempts), you'll need to send the `requestId` to your [backend](/docs/v3/server-quickstarts-overview). From there, your server can call the [Fingerprint Events API](/reference/v3/server-api-get-event) to retrieve the full visitor information data and use it to make decisions and prevent fraud.

Check out these related resources:

* [Svelte SDK reference](https://github.com/fingerprintjs/fingerprintjs-pro-svelte)
* [Node.js backend quickstart](/docs/v3/node-server-quickstart)
* [API reference for the Events endpoint](/reference/v3/server-api-get-event)
* [Use case tutorial: Detecting new account fraud](/docs/v3/new-account-fraud-use-case-tutorial)
* [Protecting from client-side tampering and replay attacks](/docs/v3/protecting-from-client-side-tampering)
