PHPackages                             radosavleovac/laravel-consent-mode - 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. [Security](/categories/security)
4. /
5. radosavleovac/laravel-consent-mode

ActiveLibrary[Security](/categories/security)

radosavleovac/laravel-consent-mode
==================================

GDPR Compliant Google Consent Mode V2 for Laravel

1.0.7(1y ago)057MITPHP

Since Feb 5Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/leovacdigital/laravel-consent-mode)[ Packagist](https://packagist.org/packages/radosavleovac/laravel-consent-mode)[ RSS](/packages/radosavleovac-laravel-consent-mode/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (1)Versions (3)Used By (0)

Laravel Consent Mode
====================

[](#laravel-consent-mode)

**GDPR Compliant Google Consent Mode V2 for Laravel**

This package provides an easy way to implement Google Consent Mode V2 in Laravel applications while complying with GDPR regulations. It supports TailwindCSS for styling and offers customizable cookie consent management.

🚀 Features

✅ Google Consent Mode V2 compliant ✅ Supports TailwindCSS for styling ✅ Easy integration with Laravel ✅ Customizable cookie categories ✅ Consent-based loading of Google Tag Manager (GTM) ✅ Multi-language support ✅ Publishable assets (JS, CSS, Views, and Config)

---

📌 Installation
--------------

[](#-installation)

### 1️⃣ Install the package via Composer

[](#1️⃣-install-the-package-via-composer)

Run the following command in your Laravel project:

```
composer require radosavleovac/laravel-consent-mode
```

### 2️⃣ Publish the configuration file

[](#2️⃣-publish-the-configuration-file)

After installation, publish the configuration file using:

```
php artisan vendor:publish --tag=consent-config
```

This will create a configuration file at:

```
config/consent.php

```

### 3️⃣ Publish assets (JS &amp; CSS)

[](#3️⃣-publish-assets-js--css)

To publish the required JavaScript and CSS files, run:

```
php artisan vendor:publish --tag=consent-assets
```

This will place the assets in the `public/js` and `public/css` folders.

### 4️⃣ Publish translations (optional)

[](#4️⃣-publish-translations-optional)

To publish language files for customization:

```
php artisan vendor:publish --tag=cookie-consent-translations
```

### 5️⃣ Publish views (optional)

[](#5️⃣-publish-views-optional)

If you want to override the default views:

```
php artisan vendor:publish --tag=cookie-consent-views
```

This will copy the views to:

```
resources/views/vendor/cookie-consent/

```

---

📖 Configuration
---------------

[](#-configuration)

Edit the `config/consent.php` file to configure the cookie categories and default settings:

```
return [
    'gtm_id' => env('GTM_ID', 'GTM-XXXXXXX'),

    'cookie_name' => env('COOKIE_CONSENT_NAME', 'cookie_consent'),

    'cookie_expiration_days' => env('COOKIE_EXPIRATION_DAYS', 365),

    'categories' => [
            'necessary' => [
            'label' => 'necessary', // This key is used in the cookie settings modal
            'description' => 'necessary_description', // This key is used in the cookie settings modal
            'required' => true, // This key is used in the cookie settings modal
            'gtag_key' => 'security_storage', // This key is used in the Google Tag Manager
            'cookies' => ['XSRF-TOKEN', 'laravel_session'], // Cookies that are set when the category is accepted
        ]
    ],

    'default_consent' => [
        'ad_storage' => 'denied',
        'analytics_storage' => 'denied',
        'security_storage' => 'granted',
    ]
];
```

---

🚀 Usage
-------

[](#-usage)

### 1️⃣ Add the consent banner

[](#1️⃣-add-the-consent-banner)

Include the following Blade directive in your main layout, near or in footer (e.g., `resources/views/layouts/app.blade.php`):

```
@include('cookie-consent::cookie-banner')
```

### 2️⃣ Add the Google Tag after head opening

[](#2️⃣-add-the-google-tag-after-head-opening)

```
@include('cookie-consent::gtm')
```

### 2️⃣ Add the noscript Tag after body opening

[](#2️⃣-add-the-noscript-tag-after-body-opening)

```
@include('cookie-consent::gtm-noscript')
```

🎯 Example: Handling Consent in JavaScript
-----------------------------------------

[](#-example-handling-consent-in-javascript)

When the user accepts all cookies, the following function is executed:

```
function acceptAllCookies() {
  gtag("consent", "update", {
    ad_storage: "granted",
    analytics_storage: "granted",
    security_storage: "granted",
  });

  document.cookie =
    "cookie_consent=accepted; path=/; max-age=" + 365 * 24 * 60 * 60;
  document.getElementById("cookie-banner").style.display = "none";
}
```

---

🔧 Customization
---------------

[](#-customization)

- Edit **views** in `resources/views/vendor/cookie-consent/`
- Modify **translations** in `resources/lang/vendor/cookie-consent/`
- Adjust **CSS styles** in `public/css/cookie.css`

To enable visitors to change settings you can place a button in your code

```

    Settings

```

To display map after user gave permission you can use

```
@if(isset($_COOKIE['maps_cookies']) && $_COOKIE['maps_cookies'] === 'granted')

    @else

        {{ __('cookie-consent::messages.enable_map') }}

            {{ __('cookie-consent::messages.cookie_settings') }}

@endif
```

---

📄 License
---------

[](#-license)

This package is licensed under the MIT licence.

To do - tutorial how to setup Google Tag manager

---

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance60

Regular maintenance activity

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 70.8% 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 ~11 days

Total

2

Last Release

502d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0081c20f687dffbfc1745c760b7d8ce5da21bf1e69102ba71d9114db9734b79?d=identicon)[leovacdigital](/maintainers/leovacdigital)

---

Top Contributors

[![RadosavLeovac](https://avatars.githubusercontent.com/u/35815479?v=4)](https://github.com/RadosavLeovac "RadosavLeovac (17 commits)")[![leovacdigital](https://avatars.githubusercontent.com/u/166610466?v=4)](https://github.com/leovacdigital "leovacdigital (7 commits)")

### Embed Badge

![Health badge](/badges/radosavleovac-laravel-consent-mode/health.svg)

```
[![Health](https://phpackages.com/badges/radosavleovac-laravel-consent-mode/health.svg)](https://phpackages.com/packages/radosavleovac-laravel-consent-mode)
```

###  Alternatives

[illuminate/encryption

The Illuminate Encryption package.

9630.7M326](/packages/illuminate-encryption)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)

PHPackages © 2026

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