Ir al contenido principal

CMP Integration Guide

Add the SiteGuardian cookie consent banner to your website. Choose your platform below.

HTML / Any Website

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.

JavaScript API

The widget exposes a stable JavaScript API for programmatic consent access. Use event-driven patterns since the widget loads asynchronously.

Wait for CMP ready

document.addEventListener('sg:ready', () => { // CMP loaded and consent state resolved const consent = SiteGuardianCMP.getConsent(); // consent = { categories_accepted: [...], action: "accept_all", ... } or null });

Check consent for a category

if (window.SiteGuardianCMP) { const hasAnalytics = SiteGuardianCMP.hasConsented('analytics'); // true/false }

React to consent changes

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 });

Callback API

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.

Google Consent Mode v2 PRO+

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_storage
  • ad_storage
  • ad_user_data
  • ad_personalization

No additional configuration needed. Enable Google Consent Mode in your CMP settings, and the widget handles the rest.