> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snitcher.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cookie Consent

> Configure Snitcher to work with your cookie consent management solution for GDPR and privacy compliance.

Snitcher supports integration with popular Consent Management Platforms (CMPs) to help you comply with GDPR, CCPA, and other privacy regulations.

## Enabling Consent Management

To enable consent management, add `waitForConsent: true` to your tracking script configuration:

```javascript theme={null}
{
  "profileId": "YOUR_PROFILE_ID",
  "apiEndpoint": "radar.snitcher.com",
  "cdn": "cdn.snitcher.com",
  "namespace": "Snitcher",
  "waitForConsent": true
}
```

<Warning>
  Without `waitForConsent: true`, Snitcher grants consent automatically on page load and visitor identity persists immediately—bypassing your consent flow.
</Warning>

## How It Works

When `waitForConsent` is enabled:

1. **Before Consent**: Snitcher tracks pageviews and sessions, but visitor identity is not persisted across browser sessions.

2. **After Consent**: Visitor identity persists across sessions, enabling cross-session recognition and attribution.

<Info>
  Even without consent, Snitcher still tracks pageviews and sessions—visitors just won't be recognized when they return.
</Info>

## Automatic CMP Integration

Snitcher automatically integrates with these Consent Management Platforms:

| CMP           | Detection | Notes                                  |
| ------------- | --------- | -------------------------------------- |
| **Cookiebot** | Automatic | Listens for consent events             |
| **CookieYes** | Automatic | Listens for CookieYes consent events   |
| **OneTrust**  | Automatic | Integrates with OneTrust's consent API |
| **Transcend** | Automatic | Detects Transcend consent signals      |

If you use one of these CMPs, Snitcher will automatically:

* Detect when a visitor grants analytics or marketing consent
* Enable persistent visitor recognition

<Tip>
  Just ensure your CMP script loads before the Snitcher tracking script.
</Tip>

## Manual Consent Handling

For custom cookie banners or other CMPs, you can manually grant consent:

```javascript theme={null}
// Call this when your visitor accepts cookies
Snitcher.giveCookieConsent();
```

### Example: Custom Cookie Banner

```html theme={null}
<div id="cookie-banner">
  <p>We use cookies to improve your experience. Do you accept?</p>
  <button id="accept-cookies">Accept</button>
  <button id="decline-cookies">Decline</button>
</div>

<script>
  document.getElementById('accept-cookies').addEventListener('click', function() {
    // Grant consent to Snitcher
    Snitcher.giveCookieConsent();

    // Hide the banner
    document.getElementById('cookie-banner').style.display = 'none';

    // Store preference (optional)
    localStorage.setItem('cookie_consent', 'granted');
  });
</script>
```

### Checking Existing Consent

If a visitor has previously granted consent (stored in your own cookie/localStorage), grant consent on page load:

```javascript theme={null}
// Check your own consent storage
if (localStorage.getItem('cookie_consent') === 'granted') {
  Snitcher.giveCookieConsent();
}
```

## Integration with Tag Managers

### Google Tag Manager

Create a Custom HTML tag that fires when your consent trigger activates:

```javascript theme={null}
<script>
  if (window.Snitcher) {
    Snitcher.giveCookieConsent();
  }
</script>
```

Set this tag to fire on your consent-granted trigger (e.g., when a user accepts cookies).

### Cookiebot via GTM

If using Cookiebot through GTM, create a trigger for the `CookiebotOnAccept` event:

```javascript theme={null}
<script>
  window.addEventListener('CookiebotOnAccept', function() {
    if (Cookiebot.consent.statistics && window.Snitcher) {
      Snitcher.giveCookieConsent();
    }
  });
</script>
```

## Best Practices

1. **Load order matters**: Ensure your CMP script loads before the Snitcher tracking script
2. **Test both scenarios**: Verify tracking works both with and without consent
3. **Don't over-complicate**: If using a supported CMP, automatic integration should "just work"

## Troubleshooting

<AccordionGroup>
  <Accordion title="Consent not being detected">
    * Ensure the CMP script loads before Snitcher
    * Check browser console for CMP-related errors
    * Verify the CMP is correctly configured
  </Accordion>

  <Accordion title="Visitors not being recognized across sessions">
    * Confirm `giveCookieConsent()` was called
    * Check if localStorage is being cleared by the browser
    * Verify consent was actually granted in your CMP
  </Accordion>

  <Accordion title="Data not appearing in dashboard">
    * Tracking still works without consent—just without cross-session recognition
    * Check network requests to `radar.snitcher.com` in DevTools
  </Accordion>
</AccordionGroup>
