Browser fingerprinting
Prerequisites
Fingerprint.js is used to compute all the required information for the fingerprint, plus a hash that determines the uniqueness of the browser.
Make sure you include it in your project using one of the following methods.
- CDN
https://cdnjs.com/libraries/fingerprintjs2
- Bower:
bower install fingerprintjs2
- NPM:
npm install fingerprintjs2
- Yarn:
yarn add fingerprintjs2
Calling the api for further analyze
In order to send the browser's fingerprint to the api, you need to call the following function. The function accepts a parameter which should be an object containg details about the transaction.
const generateAndStoreFingerprint = async function (fingerprint) {
const url = 'https://lacent-fingerprint-service.trusted.nl.lacent.dev.tinka.host/fingerprint';
return new Promise((resolve) => {
const callback = async (components) => {
const hash = fingerprint2.x64hash128(components.map((pair) => pair.value).join(), 31);
const now = new Date();
fingerprint.deviceFingerprint = hash;
fingerprint.currentDate = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
fingerprint.currentTime = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
fingerprint.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
fingerprint.userAgent = navigator.userAgent;
const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(fingerprint)
};
try {
const result = await fetch(url, options);
resolve(result);
} catch (e) {
reject(e);
}
};
if (window.requestIdleCallback) {
requestIdleCallback(() => fingerprint2.get({ excludes: { userAgent: true } }, callback));
} else {
setTimeout(() => fingerprint2.get(callback), 500);
}
});
};
The parameter of the function should be an object in the format described below.
{
merchantId: 'merchant', // string value that should contain only letters (a-zA-Z)
shopperCustomerId: '32323232', // string value that should contain only numbers
shopperSessionId: 'ssid9621', // string value that should contain only letters and numbers
};
When the api call is complete, the function returns a promise with the response object.