All Products
Search
Document Center

Fraud Detection:Device Risk SDK Web/H5 Integration

Last Updated:May 28, 2026

Embed the device risk SDK on key pages such as logon, registration, and transaction pages to collect device fingerprint information and identify fraud risks. This topic describes the Web/H5 integration process and API usage.

Prerequisites

A Web/H5 application has been created in the Fraud Detection console and an AppKey has been obtained.

Step 1: Embed the JS SDK

Add the following script to the <head> or <body> of the page you want to protect to import the device risk SDK:

<script src="https://o.alicdn.com/captcha-frontend/aliyunFP/fp.min.js"></script>
Important

The JS file is updated periodically. Do not download it to a local server. Always load it from the CDN URL to avoid failures caused by outdated files.

You only need to embed the JS SDK once per page (including single-page applications). After embedding, you can initialize the SDK anywhere on the page.

Step 2: Initialize the SDK

Initialize the SDK immediately after embedding the JS SDK (only initialize once) to obtain the SDK object:

ALIYUN_FP.use('um', (state, um) => {
  if (state === 'loaded') {
    um.init({
        // Enter the AppKey obtained from the Fraud Detection console
        appKey: 'your_app_key',
        // Enter a custom name for your Web application
        appName: 'your_web_app_name'
        endpoints : ['https://cloudauth-device.ap-southeast-1.aliyuncs.com']
    }, (state) => {
        // state = success indicates successful initialization
        console.info(state);
    });
  }
});
Important

If you do not specify a service address, endpoints uses the default configuration.

Default endpoint addresses:

Region

Service address

Singapore

https://cloudauth-device.ap-southeast-1.aliyuncs.com

China (Hong Kong)

https://cloudauth-device.cn-hongkong.aliyuncs.com

Germany (Frankfurt)

https://cloudauth-device.eu-central-1.aliyuncs.com

US (Silicon Valley)

https://cloudauth-device.us-west-1.aliyuncs.com

init parameters

Parameter

Type

Required

Description

appKey

String

Yes

Identifies your application. You can obtain it from Device App Management in the Alibaba Cloud console.

appName

String

Yes

A custom name for your Web application.

endpoints

Array

No

An array of service addresses. If not specified, the default address is used.

Step 3: Get the deviceToken

Call the getToken API to obtain the device fingerprint deviceToken. We recommend that you call this API when a user triggers a business event. Allow an interval of at least 3 seconds between calling init and getToken to ensure initialization is complete.

// Get the deviceToken without passing bizId
window.z_um.getToken();

// Pass bizId to bind this token to a unique business identifier
window.z_um.getToken(bizId);

Parameters

Parameter

Type

Description

bizId

String

Optional. A unique business identifier. If specified, the token is bound to this bizId.

Full integration example

The following example shows the complete process of embedding the JS SDK, initializing the SDK, and sending a request after obtaining the deviceToken:

<body>
<button type="button" id='register' onclick="login();">Log on</button>
<script type="text/javascript" src="https://o.alicdn.com/captcha-frontend/aliyunFP/fp.min.js"></script>
<script>

// Initialize as soon as the page loads
ALIYUN_FP.use('um', (state, um) => {
  if (state === 'loaded') {
    um.init({
        appKey: 'your_app_key',
        appName: 'your_web_app_name'
        //endpoints : ['https://cloudauth-device.aliyuncs.com']
    }, (state) => {
         // success indicates successful initialization
         console.info(state);
      });
  }
});

// Business function, for example logon
function login(){
    // Get the device fingerprint deviceToken. Allow at least 2 seconds between getToken and init.
    deviceToken = window.z_um.getToken();
    // Pass the deviceToken to the business server
    var data = {
           "deviceToken": deviceToken,
           "otherBusinessParams":""
     };
    // Send a backend request... the server queries risk information using the deviceToken
}

</script>
</body>

Step 4: Call the Fraud Detection API

Send the deviceToken along with other parameters to the Fraud Detection API. For more information, see API integration.