Client-Side Integration
Mubeen Device Intelligence gives every browser that visits your site a stable device ID, so you can catch fraud, deduplicate accounts, and spot suspicious sessions. This guide shows how to drop the JavaScript SDK into a plain HTML page and get a device ID you can send to your backend.
Overview
The JavaScript SDK collects browser fingerprint data and generates a unique device identifier. The SDK provides:
- Device Fingerprinting — Collects browser and device signals automatically
- Unique Device ID — Persistent identifier for fraud detection and risk analysis
- Async & Non-blocking — Loads with
deferso it never impacts page rendering
The device ID returned by the SDK must be sent to your backend alongside user data, allowing Mubeen to link the fingerprint with the user's request.
Prerequisites
| Requirement | Details |
|---|---|
| Site Key | Starts with public_ — obtain from your Mubeen dashboard |
| Backend URL | Region-specific collection endpoint — https://fp.sa.mubeen.ai (KSA), https://fp.de.mubeen.ai (EU) or https://fp.eg.mubeen.ai (Egypt). Required on every initialization. |
| Backend URL | Zain Cloud collection endpoint — https://fp.efm.zaincloud.com.sa. Required on every initialization. |
| Browser Support | Modern browsers with JavaScript enabled (Chrome, Firefox, Safari, Edge) |
Quick Start
Building a React SPA? See Client-Side Integration (React).
1. Add the SDK
<script src="https://cdn.mubeen.ai/fp/mub_fp.js" defer></script>
The defer attribute ensures the script loads after the page content is parsed, preventing any impact on page load performance. Your site_key and backend_url are passed to the SDK in Step 2 below.
2. Initialize the SDK
document.addEventListener('DOMContentLoaded', async () => {
await mub_fp.init({
site_key: 'public_your_site_key_here',
backend_url: 'https://fp.sa.mubeen.ai'
});
});
Call mub_fp.init() once the DOM is ready. The SDK is available to use after the returned promise resolves.
3. Retrieve the Device ID
Call init() once per page (see Step 2). Once it has resolved, you can call getDeviceId() as many times as you need — no re-initialization required.
document.addEventListener('DOMContentLoaded', async () => {
try {
await mub_fp.init({
site_key: 'public_your_site_key_here',
backend_url: 'https://fp.sa.mubeen.ai'
});
const deviceId = await mub_fp.getDeviceId();
console.log('Device ID:', deviceId);
} catch (error) {
console.error('Failed to get Device ID:', error);
}
});
getDeviceId() returns a string containing the unique device identifier. Send this value to your backend with user requests for risk validation.
Form Integration
The most common pattern is populating a hidden form field with the device ID so it is submitted alongside user data.
<form id="registrationForm">
<input type="text" name="name" placeholder="Name" required>
<input type="email" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<!-- Hidden field automatically populated with device fingerprint -->
<input type="hidden" id="mub_device_id" name="mub_device_id">
<button type="submit">Register</button>
</form>
<script>
document.addEventListener('DOMContentLoaded', async () => {
try {
await mub_fp.init({ site_key: 'public_your_site_key_here', backend_url: 'https://fp.sa.mubeen.ai' });
const deviceId = await mub_fp.getDeviceId();
document.getElementById('mub_device_id').value = deviceId;
} catch (error) {
console.error('Failed to get Mubeen Device ID:', error);
}
});
</script>
The hidden field mub_device_id is automatically filled with the device ID and submitted with your form data to your backend.
Not using forms? Pass the device ID in your API request body instead. See Server-Side Integration for the expected request format.
Complete Example
An end-to-end, copy-pasteable HTML page. The hidden mub_device_id field is populated with the device ID before the user submits the login form.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<!--
Load the SDK without any query parameters. `defer` waits for the
HTML to finish parsing before executing the script, so it never
blocks rendering. Credentials are supplied to init() below.
-->
<script src="https://cdn.mubeen.ai/fp/mub_fp.js" defer></script>
</head>
<body>
<h2>Log In</h2>
<form action="/api/login" method="POST">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
<!--
Hidden field submitted with the form. Your backend uses this
device ID to run risk checks against the login attempt.
-->
<input type="hidden" id="mub_device_id" name="mub_device_id">
<button type="submit">Log In</button>
</form>
<script>
// Wait for the DOM (and the deferred SDK script) before touching mub_fp.
document.addEventListener('DOMContentLoaded', async () => {
try {
// Explicit init — you choose when this runs, useful if the
// site_key is fetched dynamically or gated behind user consent.
await mub_fp.init({
site_key: 'public_your_site_key_here',
backend_url: 'https://fp.sa.mubeen.ai' // 'https://fp.de.mubeen.ai' for EU data residency
});
// Safe to call any SDK method once init() has resolved.
const deviceId = await mub_fp.getDeviceId();
document.getElementById('mub_device_id').value = deviceId;
} catch (error) {
// Fail open — the form still submits without a device ID so a
// transient SDK error doesn't block real users from logging in.
console.error('Failed to get device ID:', error);
}
});
</script>
</body>
</html>
Configuration Reference
mub_fp.init() Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
site_key | String | Required | Your unique site key (starts with public_) |
backend_url | String | Required | Region-specific collection endpoint — https://fp.de.mubeen.ai (EU / default), https://fp.sa.mubeen.ai (KSA) or https://fp.eg.mubeen.ai (Egypt)https://fp.efm.zaincloud.com.sa (Zain Cloud). Accepts a bare domain or full URL. |
backend_url is requiredIf backend_url is omitted, the SDK silently sends data to the EU endpoint (fp.de.mubeen.ai), which may be outside your region. Always set it. Choose the region that matches your data-residency obligations — see Regional Endpoints in the advanced reference for details.
Troubleshooting
mub_fp is not defined
The SDK script has not loaded yet when your code runs. Ensure:
- The
<script>tag for the SDK appears before your code in the HTML - Your code runs inside a
DOMContentLoadedevent listener
getDeviceId() returns an error
- Verify that
init()has resolved before callinggetDeviceId() - Confirm your
site_keyis correct and active - Check the browser console for network errors — the SDK needs to reach Mubeen's servers
Device ID not populated in form
- Confirm the hidden input
idmatches what your JavaScript uses (mub_device_id) - Ensure the SDK initializes before the user submits the form — add error handling to verify the field is populated
- Check the browser console for SDK errors
SDK impacts page load performance
The SDK uses defer by default and should not block rendering. If you observe performance issues:
- Confirm the
deferattribute is present on the script tag - Check that you are not calling SDK methods synchronously at the top level
- Use browser DevTools Network tab to verify the script loads after DOM content
Next Steps
- Client-Side Integration (React) — React hook-based integration for SPAs
- Server-Side Integration — Send the device ID to your backend for risk validation
- Android Integration — Native Android SDK for mobile applications