Skip to main content

The DeviceScan object

To use the device scan service, you must instantiate the DeviceScan class, which has the following constructor parameters:

ParameterPurposeRequired
.setSandbox()If this parameter is used in the constructor, the library will be configured to send data to the sandbox environment. If omitted, requests are sent to the production environment.No.
.setGeoLocation(true)If this parameter is set to true, the library will request permission to collect GPS data. If omitted or set to false, geolocation information will not be extracted.No.
Attention

If the user denies access to location data, the library will run normally, but without collecting that information.

The deviceScan.info() function

To run the user data analysis function, you must send the following parameters to the library. They will identify your company and the user session to which the information belongs. In addition, the event_id and event_type arguments, although optional, help us identify the user’s navigation pattern on your page and therefore prevent fraud even more effectively.

Below are the details for each argument:

NameTypeDescription
web_tokenStringCustomer key that identifies that the collected data comes from your application. If you have not yet received your web-token, contact support. required
session_idStringKey that identifies the session from which the collected data originates. required
event_idStringAn identifier for the event being reported
event_typeStringAn enum that defines the type of event being reported — Care is requested so that very similar events are reported with the same enum, so that intelligence can be built on top of this data.

Implementation example

A simple implementation example is shown below:

   html>
<head>
<script src="https://ds.viewpkg.com/device-scan-2-0-1.js"></script>
</head>

<script>
var deviceScan = new vPkg.DeviceScan('web_token', 'session_id')
deviceScan.setSandbox()
deviceScan.setGeoLocation(true)
async function callDeviceScan(eventType, eventId) {
await deviceScan.info(eventType, eventId)
.then((res) => console.log(res))
.catch((error) => console.log(error))
}
</script>

<body>
<input id="login" type="button" value="login" onclick="callDeviceScan('login', '1');" />
<input id="buy" type="button" value="buy" onclick="callDeviceScan('buy', '2');" />
</body>
</html>

In the example above, a helper function called callDeviceScan was created to associate Device Scan usage with a button click. The data collection function can be called twice:

  • First, when the user presses the login button, the user’s characteristics and behavior up to that event will be sent to QI Tech’s servers with the identifiers web_token, session_id, event_type ("login"), and event_id ("1").

  • Second, when the user presses the buy button, collecting the user’s behavior using the same identifiers web_token (your company) and session_id (your user’s session) but a different event_type ("buy") and event_id ("2"), indicating that a different event has occurred. This maps the entire user journey throughout your website.