All Products
Search
Document Center

Device Fingerprint JavaScript SDK For Web, H5, And WAP

Last Updated: Jul 02, 2019

Integrate the SDK

1. Embed the JavaScript SDK.

Embed the JavaScript SDK into the webpage that needs to be protected. Note: You need to embed the SDK into a webpage only once (including a single-page application). Embed the SDK behind HTML tags.

  1. <script type="text/javascript" src="//g.alicdn.com/AWSC/AWSC/awsc.js"></script>

2. Initialize the SDK.

After embedding the JavaScript SDK, you can immediately initialize the SDK (initialize it once only) to obtain the SDK object. Initialize the bot detection and device fingerprint modules separately.

The sample code is as follows:

  1. var uabModule;
  2. var webUmidToken;
  3. // Initializes the bot detection module once only.
  4. AWSC.use("uab", function (state, uab) {
  5. if(state === "loaded") {
  6. uabModule = uab;
  7. }
  8. });
  9. // Initializes the device fingerprint module once only to obtain the webUmidToken.
  10. AWSC.use("um", function (state, um) {
  11. if(state === "loaded") {
  12. um.init({
  13. appName: 'saf-aliyun-com',
  14. }, function (initState, result) {
  15. if(initState === 'success') {
  16. webUmidToken = result.tn;
  17. }
  18. });
  19. }
  20. });

3. Obtain the uaToken.

Call the getUA method to obtain the uaToken. Call method:

  1. uabModule.getUA();

4. Use the SDK.

  1. <body>
  2. <button type="button" id='register' onclick="loginForm();">Log on</button>
  3. <script type="text/javascript" src="//g.alicdn.com/AWSC/AWSC/awsc.js"></script>
  4. <script>
  5. var uabModule;
  6. var webUmidToken;
  7. // Initializes the bot detection module once only.
  8. AWSC.use("uab", function (state, uab) {
  9. if(state === "loaded") {
  10. uabModule = uab;
  11. }
  12. });
  13. // Initializes the device fingerprint module once only to obtain the webUmidToken.
  14. AWSC.use("um", function (state, um) {
  15. if(state === "loaded") {
  16. um.init({
  17. // You can set the appName parameter to saf-aliyun-com.
  18. appName: 'saf-aliyun-com',
  19. }, function (initState, result) {
  20. if(initState === 'success') {
  21. webUmidToken = result.tn;
  22. }
  23. });
  24. }
  25. });
  26. // Logs on to the system.
  27. function loginForm(){
  28. // Obtains the uaToken.
  29. var uaToken = uabModule.getUA();
  30. // Uses the uaToken and webUmidToken to call the service API.
  31. var data = {
  32. "webUmidToken": webUmidToken,
  33. "uaToken": uaToken,
  34. "Other business parameters":""
  35. };
  36. // Sends a request.
  37. }
  38. </script>
  39. </body>

5. Call the Fraud Detection API

Use the uaToken and webUmidToken in combination with other parameters to call the Fraud Detection API in accordance with the following topics:

Registration Fraud Detection - Advanced Edition event and response parameters

Marketing Fraud Detection - Advanced Edition event and response parameters

Suspicious Logon Fraud Detection - Advanced Edition event and response parameters

The following figure shows the sequence diagram for integrating and using the SDK. Steps 1 and 2 are required only when you load the SDK for the first time. You can perform steps 3 through 9 in a loop as needed.

JSpic