Installation
This guide covers the complete installation process for Recapt using the script tag method.
Overview
Installing Recapt is a simple three-step process:
- Generate your API key
- Configure allowed domains
- Add the script tag to your website
Step 1: Generate Your API Key
- Log in to your Recapt dashboard
- Go to Installation in the sidebar
- Click Generate to create a new API key
- Your API key will be displayed - keep this safe
If you regenerate your API key, your existing installation will stop working until you update the key in your website's code.
Step 2: Configure Allowed Domains
For security, Recapt only accepts data from whitelisted domains.
- In the Installation wizard, go to Domain Settings
- Enter your domain (e.g.,
example.com) - Click Add Domain
- Repeat for all domains and subdomains
Examples of domains to add:
example.com- Your main domainwww.example.com- WWW subdomainapp.example.com- Application subdomainstaging.example.com- Staging environment
Step 3: Add the Script
Add this script tag to your website's <head> section:
<script
src="https://cdn.recapt.app/browser/recapt.js?key=YOUR_API_KEY"
async
data-public-key="YOUR_API_KEY"
data-persist
></script>
Replace YOUR_API_KEY with the API key you generated in Step 1.
Script Attributes
| Attribute | Required | Description |
|---|---|---|
src | Yes | The Recapt CDN URL with your API key as ?key= query parameter |
data-public-key | Yes | Your API key |
data-persist | No | Keeps sessions alive across page reloads |
async | No | Loads the script asynchronously (recommended) |
Complete HTML Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Website</title>
<!-- Recapt Installation -->
<script
src="https://cdn.recapt.app/browser/recapt.js?key=pk_live_abc123..."
async
data-public-key="pk_live_abc123..."
data-persist
></script>
</head>
<body>
<!-- Your content -->
</body>
</html>
Framework-Specific Examples
React / Next.js (Recommended Approach)
For React and Next.js applications, create a component that loads the Recapt script. The SDK auto-initializes from the script URL.
Create a RecaptSetup.tsx component:
"use client";
import { useEffect } from "react";
export function RecaptSetup() {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://cdn.recapt.app/browser/recapt.js?key=YOUR_API_KEY";
script.async = true;
script.setAttribute("data-public-key", "YOUR_API_KEY");
script.setAttribute("data-persist", "");
document.head.appendChild(script);
}, []);
return null;
}
Then include it in your app's root layout:
// app/layout.tsx (Next.js App Router)
import { RecaptSetup } from "@/components/RecaptSetup";
export default function RootLayout({ children }) {
return (
<html>
<body>
<RecaptSetup />
{children}
</body>
</html>
);
}
Identifying Users
To associate sessions with your users, wait for the SDK to be ready and then call recapt("identify", ...):
"use client";
import { useEffect, useRef } from "react";
import { useAuth } from "./your-auth-provider"; // Your auth hook
declare global {
interface Window {
Recapt: any;
recapt: (action: string, data: any) => void;
}
}
export function RecaptSetup() {
const { user, isLoading } = useAuth();
const scriptLoaded = useRef(false);
useEffect(() => {
if (scriptLoaded.current) return;
scriptLoaded.current = true;
const script = document.createElement("script");
script.src = "https://cdn.recapt.app/browser/recapt.js?key=YOUR_API_KEY";
script.async = true;
script.setAttribute("data-public-key", "YOUR_API_KEY");
script.setAttribute("data-persist", "");
document.head.appendChild(script);
}, []);
useEffect(() => {
if (isLoading || !user) return;
const identify = () => {
if (!window.Recapt) {
setTimeout(identify, 100);
return;
}
window.recapt("identify", {
uid: user.id,
email: user.email,
nickname: user.nickname,
});
};
identify();
}, [user, isLoading]);
return null;
}
Vue.js
Add the script tag to your index.html:
<!-- public/index.html -->
<!DOCTYPE html>
<html>
<head>
<script
src="https://cdn.recapt.app/browser/recapt.js"
async
data-public-key="YOUR_API_KEY"
data-persist
></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
Single Page Applications (SPAs)
For SPAs, the data-persist attribute is important to maintain session continuity across route changes. The script automatically handles navigation events within your application.
The dynamic script loading approach shown in the React/Next.js example above works well for any SPA framework. It ensures the script loads properly and gives you control over when to identify users.
Development Environment
By default, Recapt won't record sessions from localhost. To enable recording during development:
- Go to Settings > Organization in your dashboard
- Toggle Localhost to enable
- Sessions from
localhostwill now be recorded
We recommend keeping localhost disabled in production environments and only enabling it during active development.
Verifying Your Installation
After installation, verify that Recapt is working:
- Check the browser console: You should not see any Recapt-related errors
- Visit your Recapt dashboard: Navigate to Sessions
- Look for your session: New sessions typically appear within 1-2 minutes
If you don't see sessions appearing, check:
- Your API key is correct
- Your domain is whitelisted
- There are no JavaScript errors in the console
Troubleshooting
Script Not Loading
- Check that the script URL is correct:
https://cdn.recapt.app/browser/recapt.js - Verify there are no Content Security Policy (CSP) issues blocking the script
- Check your browser's Network tab for failed requests
Sessions Not Appearing
- Verify your domain is in the whitelist
- Check that the API key matches your organization
- Ensure you're not on localhost (unless localhost is enabled)
- Wait a few minutes - sessions may take 1-2 minutes to appear
Console Errors
If you see errors related to Recapt:
- Check that your API key is valid
- Verify the domain whitelist configuration
- Ensure the script is loaded before trying to use Recapt APIs
Next Steps
- User Identification - Associate sessions with your users
- Automatic Obfuscation - Protect sensitive data
- Painpoints - Control which sessions to keep