Richtlinienbasierte Schlüssel für Aufgaben auf Websites installieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird erläutert, wie Sie einen richtlinienbasierten Schlüssel für die Herausforderung auf Ihrer Website installieren.
Mit einem richtlinienbasierten Aufgabenschlüssel kann reCAPTCHA CAPTCHA-Aufgaben deterministisch basierend auf einem Punktzahl-Schwellenwert und dem Schwierigkeitsgrad der Aufgabe auslösen.
Halten Sie in der Liste der reCAPTCHA-Schlüssel den Mauszeiger auf den Schlüssel, den Sie kopieren möchten, und klicken Sie dann auf
content_copy
.
Verwenden Sie die Methode projects.keys.list, um die ID eines vorhandenen Schlüssels mithilfe der REST API zu kopieren.
Verwenden Sie den Befehl gcloud recaptcha keys list, um die ID eines vorhandenen Schlüssels mit der gcloud CLI zu kopieren.
Schlüssel für richtlinienbasierte Aufgaben konfigurieren
Für Ihren richtlinienbasierten Schlüssel für die Aufgabe müssen Sie den Schwierigkeitsgrad der Aufgabe angeben, der die Komplexität und Häufigkeit von CAPTCHA-Aufgaben bestimmt, und einen benutzerdefinierten Score-Schwellenwert für bestimmte Aktionen definieren, der den Standardschwellenwert überschreibt.
Rufen Sie in der Google Cloud Console die Seite reCAPTCHA auf.
Verwenden Sie den Schieberegler Aktionsschwellenwert festlegen, um einen benutzerdefinierten Grenzbereich für die Punktzahl festzulegen.
Klicken Sie auf Fertig.
Klicken Sie auf Speichern.
reCAPTCHA auf einer HTML-Schaltfläche hinzufügen
Wenn Sie reCAPTCHA auf Ihre Webseite laden möchten, fügen Sie die JavaScript API mit Ihrem richtlinienbasierten Schlüssel für die Aufgabe im Element <head></head> Ihrer Webseite hinzu.
reCAPTCHA verwendet standardmäßig die Sprache des Browsers. Wenn Sie eine andere Sprache angeben möchten, verwenden Sie das Attribut hl=LANG in Ihrem Script.
Wenn Sie beispielsweise Französisch verwenden möchten, geben Sie Folgendes an: <script src="https://www.google.com/recaptcha/enterprise.js?hl=fr"></script>.
Informationen zu den unterstützten Sprachen finden Sie unter Sprachcodes für reCAPTCHA.
So fügen Sie reCAPTCHA auf einer einfachen HTML-Schaltfläche hinzu:
Definieren Sie eine Callback-Funktion, um das Token zu verarbeiten.
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
} // Use `requestSubmit()` for extra features like browser input validation.
</script>
Wenn Sie einen Speicherort für das Logo angeben möchten, verwenden Sie das Attribut data-badge=LOCATION für das Element mit class=g-recaptcha. Standardmäßig ist der Speicherort auf bottomright festgelegt.
Die anderen möglichen Werte sind inline und bottomleft.
Wenn diese Schaltfläche verwendet wird, um ein Formular auf Ihrer Website zu senden, enthält der POST-Parameter g-recaptcha-response das Antworttoken.
Nachdem das Token generiert wurde, wird das reCAPTCHA-Token an Ihr Backend gesendet und es wird innerhalb von zwei Minuten eine Bewertung erstellt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[],[],null,["# Install policy-based challenge keys on websites\n\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page explains how to install a policy-based challenge key on your website.\nWith a policy-based challenge key, reCAPTCHA can deterministically\ntrigger CAPTCHA challenges based on a score threshold and challenge difficulty.\n\nBefore you begin\n----------------\n\n1.\n\n [Prepare your environment for reCAPTCHA](/recaptcha/docs/prepare-environment).\n\n2. [Create a policy-based challenge key](/recaptcha/docs/create-key-website).\n\n Alternatively, you can copy the ID of an existing policy-based challenge key by\n performing one of the following steps:\n\n\n - To copy the ID of an existing key from the **Google Cloud console**,\n do the following:\n\n 1. Go to the **reCAPTCHA** page.\n\n [Go to reCAPTCHA](https://console.cloud.google.com/security/recaptcha)\n 2. In the reCAPTCHA keys list, hold the pointer over the key you want to copy, and then click content_copy .\n - To copy the ID of an existing key using the **REST API** , use the [projects.keys.list](/recaptcha/docs/reference/rest/v1/projects.keys/list) method.\n - To copy the ID of an existing key using the **gcloud CLI** , use the [gcloud recaptcha keys list](/sdk/gcloud/reference/recaptcha/keys/list) command.\n\n \u003cbr /\u003e\n\nConfigure the policy-based challenge key\n----------------------------------------\n\nFor your policy-based challenge key, you must specify the challenge difficulty\nthat determines the complexity and frequency of CAPTCHA challenges, and\ndefine a custom score threshold for specific actions that overrides the default\nthreshold.\n\n1. In the Google Cloud console, go to the **reCAPTCHA** page.\n\n [Go to reCAPTCHA](https://console.cloud.google.com/security/recaptcha)\n\n The **reCAPTCHA** page has two views: **Tables** and **Cards** .\n If your project has many reCAPTCHA keys, only the **Table** view is available.\n2. Verify that the name of your project appears in the resource selector\n at the top of the page.\n\n If you don't see the name of your project, click the resource selector,\n and then select your project.\n3. In the **reCAPTCHA keys** section, identify the policy-based challenge key\n that you want to configure, and click the key.\n\n4. In the **Key details** page, go to the **Overview tab**.\n\n5. In the **Configuration** section, click **Configure** for **Challenge settings**.\n\n6. In the **Configure challenge settings** page, select the challenge difficulty.\n\n7. To trigger CAPTCHA challenges, use the slider to specify the default\n threshold value.\n\n The default threshold of `0.0` does not trigger any challenge. `1.0`\n triggers a challenge for every request.\n8. To configure a custom score threshold for individual actions, which overrides\n the default threshold value, do the following:\n\n 1. Enter an [action name](/recaptcha/docs/actions-website).\n\n | **Note:** You cannot use more than 100 action names.\n 2. To specify a custom score threshold, use the **Set action threshold**\n slider.\n\n 3. Click **Done**.\n\n9. Click **Save**.\n\nAdd reCAPTCHA on an HTML button\n-------------------------------\n\n1.\n\n To load reCAPTCHA on your web page, add the JavaScript API with\n your policy-based challenge key within the `\u003chead\u003e\u003c/head\u003e`\n element of your web page.\n\n \u003cbr /\u003e\n\n ```scdoc\n \u003chead\u003e\n \u003cscript src=\"https://www.google.com/recaptcha/enterprise.js?render=KEY_ID\"\u003e\u003c/script\u003e\n ....\n \u003c/head\u003e\n \n ```\n\n \u003cbr /\u003e\n\n reCAPTCHA uses the browser's language by default. If you want to\n specify a different language, use the `hl=`\u003cvar translate=\"no\"\u003eLANG\u003c/var\u003e attribute\n in your script.\n For example, to use French, specify the following:\n `\u003cscript src=\"https://www.google.com/recaptcha/enterprise.js?hl=fr\"\u003e\u003c/script\u003e`.\n To learn about the supported languages, see\n [language codes for reCAPTCHA](/recaptcha/docs/language).\n\n \u003cbr /\u003e\n\n2. To add reCAPTCHA on a simple HTML button, do the\n following:\n\n 1. Define a callback function to handle the token.\n\n ```text\n \u003cscript\u003e\n function onSubmit(token) {\n document.getElementById(\"demo-form\").submit();\n } // Use `requestSubmit()` for extra features like browser input validation.\n \u003c/script\u003e\n ```\n\n For more information, see [requestSubmit() method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit).\n 2. Add attributes to your html button.\n\n ```scdoc\n \u003cbutton class=\"g-recaptcha\"\n data-sitekey=\"KEY_ID\"\n data-callback=\"onSubmit\"\n data-action=\"submit\"\u003eSubmit\u003c/button\u003e\n ```\n\n If you want to specify a location for the badge, then use the `data-badge=`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\n attribute on the element that has `class=g-recaptcha`. By default, the location is set to `bottomright`.\n The other possible values are `inline` and `bottomleft`.\n 3. When this button is used to submit a form on your site, the\n `g-recaptcha-response` POST parameter contains the response token.\n\n | **Note:** If you set the `g-recaptcha` button as `disabled`, the button is enabled when reCAPTCHA is loaded.\n3.\n\n After the token is generated, send the reCAPTCHA token\n to your backend and create an assessment within two minutes.\n | **Important:** The `action` that you specify is returned as part of the assessment. You must verify that the `action` in the JSON response of the assessment matches the expected action that you specify when creating an assessment. For example, a `login` action should be returned on your **login** page. If there is a mismatch, it indicates that an attacker is attempting to falsify actions.\n\n \u003cbr /\u003e\n\nWhat's next\n-----------\n\n- To assess the reCAPTCHA response token, [create an assessment](/recaptcha/docs/create-assessment-website)."]]