Skip to content

Mount the widget

The class and the sitekey are the whole integration. The loader scans the page for the container itself, so there is nothing to call and nothing to sequence against the script tag.

<!-- Anywhere in the form the widget protects. -->
<div class="goust-captcha" data-sitekey="gk_7Qa1XvN3mZ0pR8LdKt2Yb4c9WfHs0EjTqA"></div>

<!-- Once per page, ideally in <head>. -->
<script src="https://cdn.goust.io/sdk/sdk.js" async defer></script>

Put the container anywhere inside the form the widget protects, and the script once per page — in <head> ideally, with async defer since nothing on the page waits for it.

When the visitor passes, the widget writes their token into a hidden input named goust-response inside the container, so the form around it posts the token to your backend, where Verify the token picks it up.

A token is single-use and short-lived. It exists to be verified once, promptly, by your server.

The loader fetches a challenge for your sitekey, then mounts the widget in a sandboxed iframe served from Goust’s own origin. The checkbox and its text live in that frame, not in your page.

Every option can be written on the container as a data- attribute.

Attribute Value
data-sitekey Your site’s sitekey. Required.
data-size normal, the checkbox card (the default), or invisible for no UI — see below.
data-theme dark (the default) or light.
data-language en or tr. By default the visitor’s browser language, then English.
data-field-name The hidden input’s name. goust-response by default.
data-attest-url A path on your own domain that forwards to Goust, for Private Access Tokens. Optional.
data-callback A global function, called with { token, expires } when the visitor passes.
data-error-callback A global function, called with { reason } when verification fails.
data-expired-callback A global function, called when the token expires.
data-ready-callback A global function, called once the widget is ready.

The loader scans the page once, when it loads. For a container added after that — in a single-page app, say — or to hold a handle on a widget, call goust.render with the same options in camelCase. An option passed here wins over the attribute of the same name, and fieldName: "" creates no hidden input at all. Called on a container the loader has already mounted, render hands back that widget’s handle.

const widget = goust.render({
  element: "#signup-captcha", // a selector, or the element itself
  sitekey: "gk_7Qa1XvN3mZ0pR8LdKt2Yb4c9WfHs0EjTqA",
  size: "normal",
  theme: "light",
  onSolved: ({ token, expires }) => {}, // expires: epoch milliseconds
  onFailed: ({ reason }) => {}, // a numeric code: log it
  onExpired: () => {},
});

goust exists once sdk.js has run. If your own code can run first, wait for the script tag’s load event before calling render.

render returns a handle:

Method What it does
execute() Runs the verification now. Only an invisible widget has it.
reset() Returns the widget to idle and drops its token.
remove() Tears the widget down, so its container can be mounted again.
token() The current token, or null when there is none.

Instead of mounting, render throws { code } when it is called without a sitekey (330) or with an element it cannot find (331).

An invisible widget has no UI and runs only when you call execute(), so it needs the JavaScript API. It is part of a paid plan: on Free the widget is the checkbox card, with the Goust mark, and an invisible one fails with onFailed reason 310. The pricing page lists the plans that include it.

Run it when the visitor submits, and submit once the token is in the form:

const form = document.querySelector("#signup");
const widget = goust.render({
  element: "#signup-captcha", // inside the form
  sitekey: "gk_7Qa1XvN3mZ0pR8LdKt2Yb4c9WfHs0EjTqA",
  size: "invisible",
  onSolved: () => form.submit(),
});

form.addEventListener("submit", (event) => {
  if ( widget.token() === null ) {
    event.preventDefault();
    widget.execute();
  }
});

theme also takes an object, applied over a built-in theme, on a paid plan. On Free the widget keeps the built-in the object’s palette.mode names, dark unless it says light; the pricing page lists the plans that include your own colours. Name only what you want to change:

goust.render({
  element: "#signup-captcha",
  sitekey: "gk_7Qa1XvN3mZ0pR8LdKt2Yb4c9WfHs0EjTqA",
  theme: { palette: { primary: { main: "#1e6ef5" } } },
});

primary colours the focus ring, the spinner’s leading edge and the ticked checkbox. Set palette.mode to "light" to start from the light built-in rather than the dark one.