# reCAPTCHA Plugin The reCAPTCHA plugin integrates Google reCAPTCHA v3 into TrueHuman's analysis pipeline. When included as a detector plugin, it automatically injects the reCAPTCHA API script into the page, requests a challenge token on behalf of the user, and sends that token to your backend for server-side score verification. The resulting score is then interpreted as a signal within TrueHuman's overall risk assessment. Unlike reCAPTCHA v2, which presents visible checkbox or image challenges, reCAPTCHA v3 operates entirely in the background. It assigns a continuous score between `0.0` and `1.0` based on behavioral analysis, where scores near `1.0` indicate likely human activity and scores near `0.0` indicate likely automated behavior. The plugin maps this score onto TrueHuman's error code system and contributes to the final risk total when a suspicious score is detected. ## Usage ```typescript import { analyze, detector } from "truehuman" const result = await analyze({ plugins: [ detector.grecaptcha({ siteKey: "6Lc...", action: "submit", endpoint: "https://your-api.com/verify-recaptcha", threshold: 0.5, }), ], }) ``` ## Options | Option | Type | Default | Description | |--------|------|---------|-------------| | `siteKey` | `string` | (required) | Your Google reCAPTCHA v3 site key, obtained from the Google reCAPTCHA admin console | | `endpoint` | `string` | (required) | The URL of your backend endpoint that will receive the token and perform server-side verification | | `action` | `string` | `"submit"` | A label identifying the context of the reCAPTCHA challenge; used for scoring differentiation in the Google dashboard | | `threshold` | `number` | `0.5` | The minimum acceptable score; sessions scoring below this value are flagged with risk code `90.1` | | `referrer` | `string` | (unset) | When set, restricts the plugin to run only when the page referrer matches the specified type: `"direct"`, `"internal"`, or `"external"` | | `saveTokens` | `boolean` | `false` | When `true`, skips reCAPTCHA execution entirely if the feathers layer has already emitted integrity codes for this session | ### `action` The `action` string is a free-form label you define to identify the interaction being protected, such as `"login"`, `"checkout"`, or `"contact_form"`. Google uses this value to group score statistics in the reCAPTCHA admin console, making it easier to monitor bot activity per interaction type. It does not affect scoring logic on TrueHuman's side. ### `referrer` The `referrer` option provides a lightweight traffic-source filter. When set, the plugin inspects `document.referrer` and compares it against the specified type before executing: - `"direct"` matches sessions with no referrer, typically direct URL entry or bookmark access - `"internal"` matches referrers from the same origin as the current page - `"external"` matches referrers from a different origin If the referrer does not match the configured type, the plugin exits silently without injecting the reCAPTCHA script or issuing any error codes. ### `saveTokens` When `saveTokens` is enabled, the plugin checks whether TrueHuman's feathers detection layer has already emitted integrity-related codes before executing the reCAPTCHA challenge. If integrity codes are present, the plugin skips the reCAPTCHA request entirely. This avoids redundant network calls in sessions where bot evidence has already been collected through other signals, reducing latency and unnecessary third-party requests. ## Execution Flow The plugin follows a deterministic sequence of steps each time `analyze()` is called with it included: **Step 1 - Referrer Filter** If a `referrer` value is configured, the plugin checks whether the current session's referrer matches the expected type. If it does not match, the plugin halts immediately and emits no codes, as though it was never invoked. **Step 2 - saveTokens Check** If `saveTokens` is `true`, the plugin inspects the feathers layer output. If any integrity codes have already been emitted in this session, the plugin exits without executing reCAPTCHA, treating the session as already evaluated. **Step 3 - Script Injection** The reCAPTCHA v3 API script is injected into the page as a `