# Web (JavaScript)

## Web (JavaScript)
Add the script tag to your HTML, ideally as early as possible so the SDK has time to collect device signals before you ask for a token:

```html
<script defer src="https://sdk.dv.socure.io/latest/device-risk-sdk.js"
        data-public-key="YOUR_SDK_KEY">
</script>
```
The SDK **auto-initializes** from the `data-public-key` attribute — there is no separate init call. Just make sure the script is loaded before the user reaches the Prefill step.
When the user submits their name and phone number, do two things before your Prefill request: get a session token, then **trigger Silent Network Authentication** with `performSilentNetworkAuth()`. Send the token on the request afterward:

```typescript
let diSessionToken: string | undefined;
try {
  if (window.SigmaDeviceManager) {
    diSessionToken = await window.SigmaDeviceManager.getSessionToken();
    // Trigger SNA. Pass the mobile number in E.164 format (e.g. +15551234567).
    // Await it so the SNA result is ready for decisioning; swallow failures so
    // a problem here never blocks the flow.
    await window.SigmaDeviceManager
      .performSilentNetworkAuth(`+1${mobileNumber}`)
      .catch(() => {});
  }
} catch (e) {
  // Continue without token — the user falls back to OTP verification
}

// ...then include diSessionToken on your Prefill request
```
> **Important — call Prefill only after SNA finishes.** The Prefill request must be sent **after** `performSilentNetworkAuth()` has resolved, not before it and not in parallel. Awaiting SNA first is what makes its result available to decisioning on the Prefill call — if you fire Prefill early, the SNA signal won't be there and the user is unnecessarily pushed to OTP.
**Don't check the SNA response.** `performSilentNetworkAuth()` doesn't return a result you act on — the outcome is consumed server-side during decisioning, not on the client. Just run it, wait for it to settle (whether it succeeds or throws), and then call Prefill **either way**. Never branch your flow on its result or block Prefill because it failed.

On the **Onboarding** request, call `getSessionToken()` again for a fresh token — you don't need to repeat the SNA step.
> **Key points**
- **`performSilentNetworkAuth()` is the call that actually runs SNA** — `getSessionToken()` alone only produces the token. Await it *before* the Prefill call so the SNA result is available to decisioning.
- The mobile number must be in **E.164 format** (`+1` followed by the 10-digit number for US).
- **Swallow SNA errors** (`.catch(() => {})`) — a failure here must not block the flow; the user simply falls back to OTP.

Version: v3

## Description:

  - `Web (JavaScript)` ()
    Add the script tag to your HTML, ideally as early as possible so the SDK has time to collect device signals before you ask for a token: <script defer src="https://sdk.dv.socure.io/latest/device-risk-sdk.js"
        data-public-key="YOUR_SDK_KEY">
</script>
<script defer src="https://sdk.dv.socure.io/latest/device-risk-sdk.js"
        data-public-key="YOUR_SDK_KEY">
</script> The SDK auto-initializes from the data-public-key attribute — there is no separate init call. Just make sure the script is loaded before the user reaches the Prefill step. When the user submits their name and phone number, do two things before your Prefill request: get a session token, then trigger Silent Network Authentication with performSilentNetworkAuth(). Send the token on the request afterward: let diSessionToken: string | undefined;
try {
  if (window.SigmaDeviceManager) {
    diSessionToken = await window.SigmaDeviceManager.getSessionToken();
    // Trigger SNA. Pass the mobile number in E.164 format (e.g. +15551234567).
    // Await it so the SNA result is ready for decisioning; swallow failures so
    // a problem here never blocks the flow.
    await window.SigmaDeviceManager
      .performSilentNetworkAuth(`+1${mobileNumber}`)
      .catch(() => {});
  }
} catch (e) {
  // Continue without token — the user falls back to OTP verification
}

// ...then include diSessionToken on your Prefill request
let diSessionToken: string | undefined;
try {
  if (window.SigmaDeviceManager) {
    diSessionToken = await window.SigmaDeviceManager.getSessionToken();
    // Trigger SNA. Pass the mobile number in E.164 format (e.g. +15551234567).
    // Await it so the SNA result is ready for decisioning; swallow failures so
    // a problem here never blocks the flow.
    await window.SigmaDeviceManager
      .performSilentNetworkAuth(`+1${mobileNumber}`)
      .catch(() => {});
  }
} catch (e) {
  // Continue without token — the user falls back to OTP verification
}

// ...then include diSessionToken on your Prefill request Important — call Prefill only after SNA finishes. The Prefill request must be sent after performSilentNetworkAuth() has resolved, not before it and not in parallel. Awaiting SNA first is what makes its result available to decisioning on the Prefill call — if you fire Prefill early, the SNA signal won't be there and the user is unnecessarily pushed to OTP.Don't check the SNA response. performSilentNetworkAuth() doesn't return a result you act on — the outcome is consumed server-side during decisioning, not on the client. Just run it, wait for it to settle (whether it succeeds or throws), and then call Prefill either way. Never branch your flow on its result or block Prefill because it failed. On the Onboarding request, call getSessionToken() again for a fresh token — you don't need to repeat the SNA step. Key pointsperformSilentNetworkAuth() is the call that actually runs SNA — getSessionToken() alone only produces the token. Await it before the Prefill call so the SNA result is available to decisioning.The mobile number must be in E.164 format (+1 followed by the 10-digit number for US).Swallow SNA errors (.catch(() => {})) — a failure here must not block the flow; the user simply falls back to OTP.

