Implement the new reCAPTCHA enterprise in Salesforce Marketing Cloud
Not too long ago, Google reCAPTCHA officially became part of Google Cloud. If you’ve been using the older reCAPTCHA implementation, you might have noticed that it suddenly stopped working — without much warning. The migration introduced new endpoints, API keys tied to Google Cloud projects, and updated payload requirements.
reCAPTCHA has moved under cloud google environment
In this post, I’ll walk you through how to verify reCAPTCHA Enterprise on the server side using Server-Side JavaScript (SSJS) in Salesforce Marketing Cloud.
To get started with reCAPTCHA Enterprise, you’ll need to log into Google Cloud Console, create a new project, and enable the reCAPTCHA Enterprise API. As part of the setup, Google will prompt you to create a billing account — don’t worry, though. reCAPTCHA Enterprise is free for up to 10,000 assessments per month, and pricing only kicks in beyond that, making it a safe choice for most small to mid-sized projects.
If you’ve been using reCAPTCHA before the migration, you can migrate your existing keys to the new reCAPTCHA Enterprise setup. Google provides an option to upgrade your old keys within the Cloud Console. Alternatively, you can simply create new reCAPTCHA keys tied to your new project — especially if you want to take advantage of the improved scoring and risk analysis features.
Before we dive into the implementation, make sure you have the essentials ready. You’ll need to have a Google Cloud project set up, with a billing profile configured (required even for the free tier). Additionally, ensure you have your site key and API key from the reCAPTCHA Enterprise setup. These credentials will be used to generate the token on the frontend and to verify it on the backend via SSJS.
Process the form with Cloud Page
Some developers prefer to split the form and data processing across two separate Cloud Pages — one for input and another for handling submissions. While this approach works, I personally prefer to keep both the form and the processing logic on a single Cloud Page.
Why? Because after processing the form (including reCAPTCHA validation), I typically redirect the user to a dedicated thank-you page. This avoids the common issue where refreshing the page causes the form to be resubmitted, potentially leading to duplicate entries or actions. Keeping everything in one place simplifies debugging and makes the flow easier to manage — especially when paired with a proper redirect after successful submission.
Add reCAPTCHA to your Cloud Page
On the front end we build our form that we want to protect from spam. When this has been done, we need to hook reCAPTCHA into our form. In the official documentation is explained how to add reCAPTCHA with different option. We will choose the very basic one that will suffice for our needs.
- Load the JavaScript reCAPTCHA library.
<head> <script src="https://www.google.com/recaptcha/enterprise.js?render=<site_key>"></script> <!-- Your code --> </head>
- Add a callback function to handle the token.
<script> function onSubmit(token) { document.getElementById("your-form-id").submit(); } </script>
- Add attributes to your html button.
<button class="g-recaptcha" data-sitekey="<site_key>" data-callback='onSubmit' data-action='submit'> Submit </button>
reCAPTCHA server side validation
For the backend, we’ll use a combination of AMPScript and Server-Side JavaScript (SSJS) to handle the submitted form data se
đź”’ This content is for Premium Subsribers only.
Please log in to preview content. Log in or RegisterYou must log in and have a Premium Subscriber account to preview the content. When upgrading, please provide the same email address as for your WordPress account; otherwise, we will not be able to link your Premium membership. Please also provide your Discord username or contact me directly to get access to the Discord community once your subscription is purchased. You can subscribe even before your account is created; the subscription will be linked to your WordPress email address.
Premium Subscriber
9.99 € / Month
- Access to exclusive blog content
- In-depth articles not available online
- Insights from industry experts
- Free Discord community invite
- Unlimited questions in Solution Station
- Limited seats at this price