Skip to main content
Build a small JavaScript page that identifies a visitor when they click a button. You will see the Request ID on the page and open the completed result in the analytics dashboard.

Before you start

You need a modern browser, a code editor and a website domain you can deploy to. The npm example uses a JavaScript project with a build tool, such as Vite. For a website without a build tool, use the CDN snippet. You can also explore results in the Playground before setting up a project.

1. Create a ShieldLabs account and get your API key

  1. Start Free to create a ShieldLabs account, or sign in.
  2. In the analytics dashboard, open Integration > Domains and add your website’s hostname.
  3. Select the domain and open Integration > API keys.
  4. Copy the Public Key. You will replace PUBLIC_API_KEY in step 4 with this value.
Register your test domain too if it differs from production. Domain verification is automatic once identification traffic arrives; see Domains.

2. Set up your project

If you already have a JavaScript project, continue to step 3. Otherwise, create a plain JavaScript app with Vite using a Node.js version supported by Vite:
Open the project in your code editor. Replace index.html with this page:
index.html

3. Install the SDK

Run this in the project folder:

4. Initialize ShieldLabs and identify a visitor

Replace src/main.js with the following code. Replace PUBLIC_API_KEY with the Public Key from step 1.
src/main.js
load() loads the browser agent. identify() starts a new check and returns its Request ID. Each click starts a new identification and counts toward your plan usage. Keep the page open while the browser sends the check.

5. Run the page and view the result

  1. Run npm run dev to preview the page locally.
  2. Build with npm run build and deploy the dist folder to the HTTPS domain registered in step 1.
  3. Open that website and click Run identification. The page displays a Request ID.
  4. In the analytics dashboard, open Analytics > Identifications, find the Request ID and open its identification card.
  5. Review the Risk Score, risk signals and device and network details.
Use the registered domain to test the identification. Localhost can display a Request ID even when the check is rejected for an unregistered hostname. The completed result is available asynchronously; allow it to appear in the analytics dashboard.

6. Identify signed-in users

For authenticated activity, pass a stable pseudonymous account ID supplied by your backend:
Use the same value for the same account. This links its identifications and supports detection of multi-accounting, account sharing and takeovers. Accounts and identifications explains user linking.

7. Send the Request ID to your backend

In your application, send the requestId with the signup, login or checkout action. For example, after your backend implements /api/signup:
/api/signup belongs to your application. Follow the Node.js guide or choose another server SDK to retrieve the identification with your Private API Key and validate it before processing the action. Keep the page open until your request has been sent. For forms that navigate on submission, start identification on interaction.

Troubleshooting

  • The module does not load: check your connection, content blockers and Content Security Policy.
  • The Request ID has no result: check the registered hostname and Public Key, and keep the page open while the check is sent.
  • The result is pending or unavailable: handle that state on your backend; use the server SDK’s bounded retrieval helper.

Next steps

Node.js backend

Retrieve results and handle your protected action.

Signed webhooks

Receive completed results on your server.

JavaScript SDK reference

Options, background checks and form helpers.

Playground

Explore identification and risk results.