@orcafraud/devicesense
v0.0.6
Published
Orca Fraud device fingerprinting for advanced fraud detection.
Downloads
352
Readme
@orcafraud/devicesense
Orca Fraud device fingerprinting for advanced fraud detection.
Usage
Note: To use this package you need an Orca Fraud account
Install
npm install @orcafraud/devicesenseScript setup
// page-script.ts
import { DeviceSense } from '@orcafraud/devicesense';
export async function initDeviceSense(): Promise<DeviceSense> {
const deviceSense = new DeviceSense({
// This needs to be a valid URI and be contained within window.location.href
siteUrl: window.location.href,
// either integration or production
environment: 'integration',
// this will be given to you during onboarding
authKey: '<auth-key>',
// You can opt in to logging errors - this could help debug issues during development
logErrors: true,
});
// The instance has to be initialised to function correctly
await deviceSense.init();
return deviceSense;
}
// This makes it easier to access directly in a frontend script in this example but is not required
Object.assign(globalThis, { initDeviceSense });<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Test Site</title>
<!-- Here we load the built page-script.js compiled from the above implementation.
Once this is loaded we run the setupDeviceSense function -->
<script
type="module"
src="./dist/page-script.js"
onload="setupDeviceSense()"
></script>
<script>
function setupDeviceSense() {
if (globalThis.initDeviceSense === undefined) {
console.error('Failed to load deviceSense');
return;
}
globalThis
.initDeviceSense()
.then((deviceSense) => {
deviceSense
.getUserDeviceId({ userId: 'some-user-id' })
.then((userDeviceId) => {
console.log('Got user device ID:', userDeviceId);
})
.catch((error) => {
console.error(`Failed to get user device ID: ${error}`);
});
})
.catch((error) => {
console.error(`Failed to initialize DeviceSense: ${error}`);
});
}
</script>
</head>
<body>
Hello 👋
</body>
</html>