Admin → Modules → CookieMonster
- Banner aktivieren
- Cookie-Kategorien definieren
- Security Headers nach Bedarf
- Optional Google Analytics Property-ID
Wenn abgefragt werden soll, ob Tracking erlaubt ist, nutze allowTracking():
<?php
/** @var CookieMonster $cmnstr */
if ($cmnstr->allowTracking()): ?>
<script>
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime())});
(function() {
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.src='https://analytics.example.com/matomo.js';
s.parentNode.insertBefore(g,s);
})();
</script>
<?php endif; ?>Wenn eine direkte Kategorie geprüft werden soll:
<?php
/** @var CookieMonster $cmnstr */
if ($cmnstr->isUnlocked('external')): ?>
<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"></iframe>
<?php else: ?>
<p>Video benötigt externe Inhalte.</p>
<?php endif; ?>Oder für Marketing:
<?php
if ($cmnstr->isUnlocked('marketing')): ?>
<!-- Facebook Pixel -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
// ...
</script>
<?php endif; ?>Mit maskContent() kannst du externe Inhalte maskieren, bis der Nutzer der Kategorie zustimmt:
<?php
/** @var CookieMonster $cmnstr */
$videoIframe = '<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"></iframe>';
echo $cmnstr->maskContent($videoIframe, 'external');
?>Ohne Zustimmung wird eine Maske mit Hinweis angezeigt. Mit Zustimmung wird der Inhalt direkt geladen.
Funktioniert für alle Kategorien:
<?php
$html = '<script>/* Facebook Pixel */</script>';
echo $cmnstr->maskContent($html, 'marketing');
$widget = '<div><!-- Third-party Widget --></div>';
echo $cmnstr->maskContent($widget, 'external');
?>Prüft ob Nutzer Statistik-Tracking erlaubt hat.
if ($cmnstr->allowTracking()) {
// Tracking laden
}Prüft eine spezifische Kategorie.
if ($cmnstr->isUnlocked('marketing')) {
// Marketing-Scripts laden
}Alle freigeschalteten Kategorien.
$categories = $cmnstr->getUnlockedCategories();
// ['essential', 'statistics', ...]Google Consent Mode v2 States.
$states = $cmnstr->getGoogleConsentStates();
// ['ad_storage' => 'granted', 'analytics_storage' => 'denied', ...]Maskiert HTML-Inhalte bis zur Zustimmung der Kategorie.
$iframe = '<iframe src="..."></iframe>';
echo $cmnstr->maskContent($iframe, 'external');- Essential — Immer aktiv.
- Functional — Nutzerpräferenzen, Sprache, Konfiguratoren, ...
- Statistics — z.B. Matomo, Google Analytics
- Marketing — Facebook Pixel, Google Ads
- External — YouTube, iFrames, externe Widgets
- PHP 8.1+
- ProcessWire 3+