← All docs

JavaScript SDK (cloak.js)

A single script tag adds decisioning, redirection and analytics.

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 tracking flow

The tracker SDK is a telemetry client. Decisioning is performed by the cloak.js decision flow or a server-side integration; the tracker does not expose a client-controlled decision API.

<script src="https://your-host/api/public/tracker.js"
        data-site-key="YOUR_SITE_KEY"></script>

API surface

MethodDescription
ShieldGate.track(kind, metadata?)Queues a bounded custom telemetry event
ShieldGate.step(name, metadata?)Records a step_viewed event
ShieldGate.button(name, metadata?)Records a button_clicked event
ShieldGate.conversion(payout?, metadata?)Records a conversion and flushes telemetry
ShieldGate.getFirstClick()Returns the first-click attribution record, if available
ShieldGate.sessionId()Returns the current anonymous session identifier

Auto-tracked events

  • pageview — on load and on history.pushState
  • click — 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', { plan: 'pro', event: 'signup_completed' });
ShieldGate.step('checkout');
ShieldGate.button('buy_now');
ShieldGate.conversion(129.00, { order_id: 'order_123' });

Data attributes

AttributeEffect
data-site-keyRequired — your site key
data-auto-redirectRedirect on money verdict
data-endpointOverride the API host
data-debugLog decisions to the console
data-no-trackDisable auto-tracking

SSR / no-JS fallback

Because bots often disable JS, use the server-side /decide or /dispatch contract for first-byte decisions and treat tracker telemetry as advisory. See Integrations.