PHPackages                             moritz-sauer-13/silverstripe-cookie-consent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. moritz-sauer-13/silverstripe-cookie-consent

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

moritz-sauer-13/silverstripe-cookie-consent
===========================================

Creates a cookie consent popup and cookie policy page.

0.2(7mo ago)0122BSD-3-ClausePHP

Since Dec 2Pushed 7mo agoCompare

[ Source](https://github.com/moritz-sauer-13/silverstripe-cookie-consent)[ Packagist](https://packagist.org/packages/moritz-sauer-13/silverstripe-cookie-consent)[ Docs](http://github.com/xini/silverstripe-cookie-consent)[ RSS](/packages/moritz-sauer-13-silverstripe-cookie-consent/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

\#This is a fork from  to add support for Silverstripe 6

Silverstripe Cookie Consent
===========================

[](#silverstripe-cookie-consent)

[![Version](https://camo.githubusercontent.com/06db7db01cea8af782acf272cb639d1c79d2dec478098f145bb040e828d4ec15/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e6e6f7765622f73696c7665727374726970652d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/innoweb/silverstripe-cookie-consent)[![License](https://camo.githubusercontent.com/ac03ad900b88a0256b36a1ad720e691add95dfc333b81f1e1798b8a8ad2541ae/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e6e6f7765622f73696c7665727374726970652d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](license.md)

Overview
--------

[](#overview)

Creates a cookie consent popup and cookie policy page.

While we try to tick as many legal boxes as we can, we give no warranty for this module to adhere to any legislation, including GDPR.

This is an amended and simplified version of [TheBnl's cookie consent module](https://github.com/TheBnl/silverstripe-cookie-consent). Thanks for your work and inspiration!

Requirements
------------

[](#requirements)

- Silverstripe CMS 6.x

Note: this version is compatible with Silverstripe 6.

Installation
------------

[](#installation)

Install the module using composer:

```
composer require innoweb/silverstripe-cookie-consent
```

Then run dev/build.

Include the popup template in your base Page.ss

```

```

Configuration
-------------

[](#configuration)

You can configure the cookies and cookie groups trough the yml config. You need to configure by provider, for providers the dots are converted to underscores e.g. ads.marketingcompany.com becomes ads\_marketingcompany\_com.

By configuring cookies trough yml you can check for consent in your code and make the necessary changes e.g. require the analytics or other cookies or skip placing them.

The texts for the configured cookies are editable trough the Site Config, here other cookies can also be added by CMS users. For example if a site user decides to embed a Youtube video he or she can specify the cookies that are placed by Youtube. I reccomend the following three groups to be created, these have default content, of course you are free to configure groups as you see fit.

```
Innoweb\CookieConsent\CookieConsent:
  cookies:
    Necessary:
      local:
        - PHPSESSID
        - CookieConsent
    Marketing:
      ads_marketingcompany_com:
        - _track
    Analytics:
      local:
        - _ga
        - _gid
```

This module comes with some default content for cookies we've encountered before. If you want to set default content for these cookies yourself that is possible trough the lang files. If you have cookie descriptions that are not in this module, contributions to the lang files are much appreciated!

The files are structured as such:

```
en:
  CookieConsent_{provider}:
    {cookie}_Purpose: 'Cookie description'
    {cookie}_Expiry: 'Cookie expire time'
  # for cookies from your own domain:
  CookieConsent_local:
    PHPSESSID_Purpose: 'Session'
    PHPSESSID_Expiry: 'Session'
  # for cookies from an external domain:
  CookieConsent_ads_marketingcompany_com:
    _track_Purpose: 'Cookie description'
    _track_Expiry: 'Cookie expire time'
```

You can also configure the requirement of the default css styles.

```
Innoweb\CookieConsent\CookieConsent:
  include_css: true
```

If your site uses multiple domains (e.g. domain.com and domain.de), you can configure the module to set consent cookies for all hosts allowed through SS\_ALLOWED\_HOSTS config:

```
Innoweb\CookieConsent\CookieConsent:
  include_all_allowed_hosts: true
```

Caution: If you are using the `CookieConsent.cookie_domain` setting, `CookieConsent.include_all_allowed_hosts` will be ignored.

Usage
-----

[](#usage)

Then you can check for consent in your PHP code by calling

```
if (CookieConsent::check('Analytics')) {
    // include analytics script
}
```

In templates, you can check for consent using

```

    // include analytics script

```

The CookieConsent popup fires a custom JavaScript event `updateCookieConsent` when the acceptance buttons in the popup are clicked. You can use that event to conditionally load parts of your site depending on what cookies have been set.

### JavaScript example

[](#javascript-example)

Here an example that lazy-loads a video embed only if marketing cookies have been accepted:

Template:

```

    Please accept marketing cookies to view this video.
    Please enable JavaScript to view this video.

```

Script:

```
let loadVideos = function() {

    // unwraps hidden embed code if correct cookie value is set
    let showVideo = function(video) {
        let requiredCookies = video.getAttribute('data-required-cookies');
        let cookieValue = Cookies.get('CookieConsent');
        if (requiredCookies === null || requiredCookies === '' || (cookieValue !== null && cookieValue.indexOf(requiredCookies) !== -1)) {
            let hidden = video.querySelector('[hidden]');
            let content = hidden.innerHTML;
            // get content from within html comment
            content = content.replace(//g, '$1');
            // replace content
            video.innerHTML = content;
            video.classList.remove('js-load-video');
            video.classList.add('js-video-loaded');
            return true;
        }
        return false;
    };

    // intersection observer to load video if in viewport
    let observer = new IntersectionObserver(function(entries, observer) {
        entries.forEach(function(entry) {
            if (entry.isIntersecting) {
                if (showVideo(entry.target)) {
                    observer.unobserve(entry.target);
                }
            }
        });
    });

    // load all videos and observe
    let videos = document.querySelectorAll('.js-load-video');
    videos.forEach(function(video) {
        observer.observe(video);
    });
};
// load videos on page init
loadVideos();
// load videos when JavaScript event is fired
document.addEventListener('updateCookieConsent', loadVideos);
```

Default Pages
-------------

[](#default-pages)

This module also sets up one default privacy policy page on running dev/build.

If you want to prevent that behaviour you should disable the `create_default_pages` config setting.

```
Innoweb\CookieConsent\CookieConsent:
  create_default_pages: false
```

The page created is filled with bare-bones content. *Of course, it is your or your CMS users responsibility to alter these texts to make them fit your use case!*

todo
----

[](#todo)

- Remove `Innoweb\CookieConsent\Control\CookieJar` workaround for SS6

License
-------

[](#license)

BSD 3-Clause License, see [License](license.md)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance65

Regular maintenance activity

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

215d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/237ff98c98e71b509c4dac62b31efaf7823cca011952ded67579a6cf763b7a47?d=identicon)[moritz-sauer-13](/maintainers/moritz-sauer-13)

---

Top Contributors

[![xini](https://avatars.githubusercontent.com/u/1152403?v=4)](https://github.com/xini "xini (67 commits)")[![moritz-sauer-13](https://avatars.githubusercontent.com/u/43135946?v=4)](https://github.com/moritz-sauer-13 "moritz-sauer-13 (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![RoyalPulp](https://avatars.githubusercontent.com/u/2283640?v=4)](https://github.com/RoyalPulp "RoyalPulp (4 commits)")

---

Tags

silverstripecookiegdprconsent

### Embed Badge

![Health badge](/badges/moritz-sauer-13-silverstripe-cookie-consent/health.svg)

```
[![Health](https://phpackages.com/badges/moritz-sauer-13-silverstripe-cookie-consent/health.svg)](https://phpackages.com/packages/moritz-sauer-13-silverstripe-cookie-consent)
```

###  Alternatives

[silverstripe/userforms

UserForms enables CMS users to create dynamic forms via a drag and drop interface and without getting involved in any PHP code

1371.1M85](/packages/silverstripe-userforms)[statikbe/laravel-cookie-consent

Cookie consent modal for EU

219426.2k](/packages/statikbe-laravel-cookie-consent)[bramdeleeuw/cookieconsent

GDPR compliant cookie bar and consent checker

1511.7k2](/packages/bramdeleeuw-cookieconsent)[codingfreaks/cf-cookiemanager

Manage cookies, scripts, and GDPR compliance on your Typo3 website with CodingFreaks Typo3 Cookie Manager. Customize cookie banners, streamline workflow, and enhance user experience. Ensure GDPR compliance and take control of cookie management with our Typo3 cookie management extension. Visit the official Typo3 Documentation page to learn more.

1830.7k](/packages/codingfreaks-cf-cookiemanager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
