WEB
Svelte
Integrate the Geelab Device Fingerprint v2 Web SDK into a Svelte or SvelteKit application
Before you begin, follow the JavaScript integration guide to load the SDK, create the shared client module, and configure the TypeScript declarations. This page covers only Svelte-specific initialization and usage.
Integration Steps
Load gld_v2.js from the host HTML file, then reuse the shared client module:
<script>
import { onMount } from 'svelte';
import { preloadGeeGuard, getGeeToken } from './geeGuardClient';
let submitting = false;
onMount(function () {
preloadGeeGuard().catch(function (error) {
console.error('GeeLabGuard initialization failed:', error);
});
});
async function checkout() {
submitting = true;
try {
const { token, offline } = await getGeeToken();
await fetch('/api/checkout', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ gee_token: token, offline }),
});
} finally {
submitting = false;
}
}
</script>
<button type="button" disabled={submitting} on:click={checkout}>
{submitting ? 'Processing…' : 'Submit order'}
</button>When using an SSR framework such as SvelteKit, call the SDK only from a browser lifecycle.