Add the SiteGuardian cookie consent banner to your website. Choose your platform below.
Add this script tag before the closing </head> tag of your HTML:
<script src="https://cmp.siteguardian.io/v1/widget.js"
data-site-id="YOUR_SITE_ID" async></script>
Replace YOUR_SITE_ID with your site ID from the CMP settings in your monitor dashboard.
The widget exposes a stable JavaScript API for programmatic consent access. Use event-driven patterns since the widget loads asynchronously.
document.addEventListener('sg:ready', () => {
// CMP loaded and consent state resolved
const consent = SiteGuardianCMP.getConsent();
// consent = { categories_accepted: [...], action: "accept_all", ... } or null
});
if (window.SiteGuardianCMP) {
const hasAnalytics = SiteGuardianCMP.hasConsented('analytics'); // true/false
}
document.addEventListener('sg:consent', (e) => {
console.log('Accepted:', e.detail.categories_accepted);
console.log('Rejected:', e.detail.categories_rejected);
console.log('Action:', e.detail.action); // accept_all, reject_all, custom
});
SiteGuardianCMP.onConsent(function(consent) {
// Fires every time the user makes a consent decision
if (consent.categories_accepted.includes('analytics')) {
// Load analytics
}
});
Note: The primary integration path is the sg:consent event. Direct API calls (SiteGuardianCMP.getConsent()) require the sg:ready event first, or a window.SiteGuardianCMP guard, since the widget loads asynchronously.
When enabled (PRO+ plans), the widget automatically integrates with Google Consent Mode v2. It sets default denied state on page load and updates consent signals when the user makes a choice.
Supported signals:
analytics_storagead_storagead_user_dataad_personalizationNo additional configuration needed. Enable Google Consent Mode in your CMP settings, and the widget handles the rest.