setono/consent-bundle

A Symfony bundle that integrates the consent contracts

Installs: 9 431

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 2

Type:symfony-bundle

v0.1.1 2021-11-08 14:03 UTC

README

Latest Version Latest Unstable Version Software License Build Status Code Coverage Mutation testing

This bundle integrates the consent contracts into Symfony.

Installation

composer require setono/consent-bundle

This installs and enables the plugin automatically if you're using Symfony Flex. If not, add the bundle manually to bundles.php.

Configuration

The default configuration has all permissions (marketing, preferences, and statistics) set to false. If you want to change these defaults, you can easily do so:

# config/packages/setono_consent.yaml

setono_consent:
    marketing_granted: true
    preferences_granted: true
    statistics_granted: true

The above configuration will effectively changes the default consent to true for all permissions.

Usage

The bundle provides a default consent context that you can easily inject and use inside your application:

<?php
use Setono\Consent\Context\ConsentContextInterface;

final class YourMarketingTrackingService
{
    private ConsentContextInterface $consentContext;
    
    public function __construct(ConsentContextInterface $consentContext) {
        $this->consentContext = $consentContext;
    }
    
    public function track(): void
    {
        if(!$this->consentContext->getConsent()->isMarketingConsentGranted()) {
            return;
        }
        
        // do your marketing tracking
    }
}