Install
<script src="https://your-host/api/public/cloak.js"
data-site-key="YOUR_SITE_KEY"
data-auto-redirect="1"></script>With data-auto-redirect="1" the SDK calls /decide on load and redirects to the money page automatically when the verdict is money.
Custom flow
<script src="https://your-host/api/public/cloak.js"
data-site-key="YOUR_SITE_KEY"></script>
<script>
window.addEventListener('load', async () => {
const d = await ShieldGate.decide();
if (d.action === 'money' && d.url) location.replace(d.url);
else document.getElementById('content').style.display = 'block';
});
</script>API surface
| Method | Description |
|---|---|
ShieldGate.decide() | Returns { verdict, action, url, mode, ttl } |
ShieldGate.track(kind, name, meta?) | Records a custom event |
ShieldGate.identify(userId, traits?) | Associates events with a user |
ShieldGate.on('decision', fn) | Fires on every decision |
Auto-tracked events
pageview— on load and onhistory.pushStateclick— every<a>and<button>download— links to files (pdf, zip, exe, dmg, apk…)form_submit— form submissions (never captures values)
Custom events
ShieldGate.track('custom', 'signup_completed', { plan: 'pro' });
ShieldGate.track('custom', 'add_to_cart', { sku: 'X1', price: 49 });
ShieldGate.track('conversion', 'purchase', { revenue: 129.00 });Data attributes
| Attribute | Effect |
|---|---|
data-site-key | Required — your site key |
data-auto-redirect | Redirect on money verdict |
data-endpoint | Override the API host |
data-debug | Log decisions to the console |
data-no-track | Disable auto-tracking |
SSR / no-JS fallback
Because bots often disable JS, we recommend combining cloak.js with a server-side /decide call from your origin. See Integrations.