Skip to main content

Web Integration

On this page you'll find integration guides for web platforms. Use the tabs to pick your framework.

React Integration

Consent URL: https://consent.example.com/consent?cr_id=...&callback_url=http://localhost:3000/consent-callback

Basic Implementation

import { useState } from 'react';

export default function ConsentWidget() {
const openConsent = () => {
const consentUrl = 'https://consent.example.com/consent?cr_id=...&callback_url=' +
encodeURIComponent(window.location.origin + '/consent-callback');
window.open(consentUrl, 'consentWindow', 'width=500,height=600');
};

return (
<button
onClick={openConsent}
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
>
Manage Consent
</button>
);
}

Handling Callback Response

Listen for callback messages from the consent window:

import { useEffect, useState } from 'react';

export default function ConsentPage() {
const [consentStatus, setConsentStatus] = useState(null);

useEffect(() => {
const handleMessage = (event) => {
if (event.origin !== 'https://consent.example.com') return;

const { status, receiptId, crId } = event.data;

if (status && receiptId && crId) {
setConsentStatus({ status, receiptId, crId });
console.log('Consent completed:', { status, receiptId, crId });
}
};

window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, []);

return (
<div>
{consentStatus && (
<div className="p-4 bg-green-100 text-green-700 rounded">
Consent Status: {consentStatus.status}
</div>
)}
</div>
);
}

## Handling Callback Response