gridonic/statamic-consent-manager

There is no license information available for the latest version (v1.1.1) of this package.

A Statamic 3 addon to manage consent for cookies.

v1.1.1 2024-12-11 07:33 UTC

This package is not auto-updated.

Last update: 2024-12-11 09:03:51 UTC


README

A Statamic 3 addon to manage consent for cookies 🍪.

Features

  • Define consent groups and scripts loaded dynamically only when consent for a group is given.
  • Provides a simple javascript API to read and change consent for users.
  • Consent is stored client-side only, making it possible to use the static cache.

Installation

Run the following commands:

composer require gridonic/statamic-consent-manager
php artisan vendor:publish --tag=statamic-consent-manager-config

Configuration

Edit the configuration file located in config/statamic/consent_manager.php:

<?php

return [
    // Where to store the consent settings of any user (javascript).
    // Choose "local" for local storage or "session" for session storage.
    'storage' => 'local',

    // Consent groups managed by the addon. Feel free to change, remove or add your own groups.
    // Scripts are dynamically added to the DOM only if consent for their group is given.
    'groups' => [
        'necessary' => [
            'required' => true,
            'consented' => true,
            'scripts' => [
                [
                    // The full script tag to include in the page if consent is given.
                    'tag' => '<script>console.log(\'script dynamically loaded with consent manager\');</script>',
                    // Choose "head" or "body" to append the script to the page.
                    'appendTo' => 'head',
                ],
            ],
        ],
        'marketing' => [
            'required' => false,
            'consented' => false,
            'scripts' => [],
        ],
        'statistics' => [
            'required' => false,
            'consented' => false,
            'scripts' => [],
        ]
    ],
];

Usage

  1. Define your consent groups and their scripts in the configuration.
  2. Add the {{ consent_manager }} tag in the head of your layout.

That's it! 🥳 What's left up to you is to design a nice cookie banner and modify consent data by using the javascript API.

Rendering a cookie banner

The addon provides the tag {{ consent_manager:groups }} which can be used to loop over consent groups in Antlers.

{{ consent_manager:groups }}
    Group ID: {{ id }}
    Consented by default: {{ consented }}
    Required: {{ required }}  
{{ /consent_manager:groups }}

ℹ️ To read of modify consent, you need to use the javascript API, because the data is stored client-side only.

Javascript API

The addon exposes a window.consentManager object to read and write consent data.