Download the PHP package elegantly/laravel-cookies-consent without Composer

On this page you can find all versions of the php package elegantly/laravel-cookies-consent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cookies-consent

Laravel Cookies Consent Manager

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

laravel-cookies-consent

This package provides a simple yet extremely flexible way to manage cookie consent in your Laravel application.

The default cookie banner design requires Tailwind CSS and Alpine.js, but you can publish the component and customize it with your own stack.

Demo here

Requirements

Backend

Frontend

The default cookie consent banner included in this package requires:

Installation

You can install the package via Composer:

You can publish the config file with:

This is the content of the published config file:

Usage

This package covers both backend and frontend cookie consent management.

You can choose to use the package only for backend capabilities or for both.

Backend Usage

In the backend, you will register the cookies and a callback associated with each of them. This callback will be a JavaScript script to run when the consent is granted.

Register Your Cookies

First, you should register all the cookies requiring user consent.

To manage cookies, the package provides a service accessible via the Facade: Elegantly\CookiesConsent\Facades\CookiesConsent.

Cookie registration should be done in middleware to access the app and request context. This also allows you to choose the routes relying on those cookies.

To register your cookies, create a new middleware App\Http\Middleware\RegisterCookiesConsent. In this middleware, call CookiesConsent::register to register groups of cookies.

For example, all cookies related to "Marketing" can be registered together:

Registering Essential Cookies

The package provides a preset for essential cookies. Essential cookies are those that cannot be removed without compromising the application. By default, Laravel includes 2 essential cookies:

This package adds a third one:

You can automatically register these three essential cookies using:

Registering Cookie Callbacks

Using the onAccepted parameter, you can define the JavaScript code to execute when consent is granted to a specific cookie group.

In the previous example, we grant consent using the Facebook pixel.

Frontend Usage

Using the Default Cookie Banner

You can use the default cookie banner included with this package. It requires js-cookie, Alpine and tailwindcss.

js-cookie Requirement

The default banner implementation requires the js-cookie library to parse cookies in the browser.

Add it to your project using the CDN:

Or see their documentation to install it via npm.

Alpine.js Requirement

The default banner implementation requires Alpine.js for reactivity. Ensure it is included in your page.

Simply put the banner component <x-cookies-consent::banner /> at the end of your HTML page, and you are ready to go!

Tailwindcss Requirement

The default banner is based on elegantly/blade-kit which is styled with tailwindcss. You must then add the following paths to your tailwind config file:

Customizing the Default Component

You can customize the default component by publishing the views:

Using a Custom Component

You can design your own frontend cookie banner.

To retrieve all the cookie definitions, simply call:

Facebook Pixel Cookie Consent

The Facebook Pixel tracks users and conversions on the client side. Documentation available here.

This is the historic way to track conversions. Facebook & Meta now also provide a way to track your conversions directly from your backend. It is called "API conversions" and the documentation is available here.

This example will only cover the Facebook Pixel as the "API conversions" do not need cookie consent.

Example

The Pixel provides a built-in manager for consent. This example relies on this.

1. Revoke consent on load

Before calling fbq('init', ...) and immediately after the Pixel script, revoke the consent:

2. Grant consent

In your middleware, register a cookie group and call fbq('consent', 'grant') in the onAccepted callback. Every call to fbq done before the consent will be triggered after fbq('consent', 'grant') is called.

References

Facebook Guide: General Data Protection Regulation

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-cookies-consent with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
elegantly/blade-kit Version ^1.0.0
illuminate/contracts Version ^11.0||^12.0
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package elegantly/laravel-cookies-consent contains the following files

Loading the files please wait ....