Menginstal kunci tantangan berbasis kebijakan di situs
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menginstal kunci tantangan berbasis kebijakan di situs Anda.
Dengan kunci tantangan berbasis kebijakan, reCAPTCHA dapat memicu tantangan CAPTCHA secara deterministik berdasarkan nilai minimum skor dan kesulitan tantangan.
Untuk kunci tantangan berbasis kebijakan, Anda harus menentukan tingkat kesulitan tantangan yang menentukan kompleksitas dan frekuensi tantangan CAPTCHA, serta menentukan nilai minimum skor kustom untuk tindakan tertentu yang menggantikan nilai minimum default.
Untuk menentukan nilai minimum skor kustom, gunakan penggeser Tetapkan nilai minimum tindakan.
Klik Selesai.
Klik Simpan.
Menambahkan reCAPTCHA pada tombol HTML
Untuk memuat reCAPTCHA di halaman web Anda, tambahkan JavaScript API dengan
kunci tantangan berbasis kebijakan Anda dalam elemen <head></head>
di halaman web Anda.
reCAPTCHA menggunakan bahasa browser secara default. Jika Anda ingin
menentukan bahasa lain, gunakan atribut hl=LANG
dalam skrip Anda.
Misalnya, untuk menggunakan bahasa Prancis, tentukan hal berikut:
<script src="https://www.google.com/recaptcha/enterprise.js?hl=fr"></script>.
Untuk mempelajari bahasa yang didukung, lihat
kode bahasa untuk reCAPTCHA.
Untuk menambahkan reCAPTCHA pada tombol HTML sederhana, lakukan
tindakan berikut:
Tentukan fungsi callback untuk menangani token.
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
} // Use `requestSubmit()` for extra features like browser input validation.
</script>
Jika Anda ingin menentukan lokasi untuk badge, gunakan atribut data-badge=LOCATION
pada elemen yang memiliki class=g-recaptcha. Secara default, lokasi ditetapkan ke bottomright.
Nilai lain yang mungkin adalah inline dan bottomleft.
Saat tombol ini digunakan untuk mengirimkan formulir di situs Anda, parameter POST
g-recaptcha-response berisi token respons.
Setelah token dibuat, kirim token reCAPTCHA
ke backend Anda dan buat penilaian dalam waktu dua menit.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]