A GDPR cookie banner only works if analytics, marketing scripts and embeds stay blocked until the visitor agrees. Here is what the rules ask for in plain language, the mistakes that make banners decorative, and how to do it in Laravel.
Open your website in a private window, open the network tab of the browser developer tools, and do not touch the cookie banner. If requests to analytics or advertising domains already appear, the banner is decoration. It asks for permission after the data has already gone.
This is the most common cookie consent failure we see on company websites, and it is usually not malice. The banner was added as a widget, while the tracking scripts stayed in the layout where they always were. Below: what the rules ask for in plain language, the mistakes that break them, and how to build it properly in Laravel.
The short answer
A cookie banner works only if analytics, marketing and third-party embeds do not run until the visitor agrees. That means the scripts must be held back by the page itself, refusing must be as easy as accepting, the visitor must be able to change their mind later, and you should keep a record of what was chosen. A banner that merely sits on top of already running scripts does none of this.
What the rules ask for, in plain language
This is a general description, not legal advice. Details differ between countries and depend on what your site does, so have your privacy lead or a lawyer confirm your case. The principles below are the common core that the GDPR and the EU rules on cookies are generally understood to require.
- Consent comes before non-essential cookies. Cookies and similar storage that are not strictly needed to deliver the service you were asked for (analytics, advertising, many embedded players) are set only after the visitor agrees.
- The choice must be real. Refusing has to be as easy as accepting. No pre-ticked boxes, no hiding the reject option behind a second screen while accept sits on the first.
- Choices are per purpose. Visitors can accept analytics and refuse marketing. One all-or-nothing switch is not enough once you have more than one purpose.
- Withdrawing is as easy as giving. The visitor can reopen their choices at any time, from a link that is always reachable.
- You can show that consent was given. If someone asks, you should be able to say what they agreed to, when, and under which version of your policy.
Strictly necessary cookies, such as a session or a shopping basket, do not need consent. Be honest when you classify: a tool that measures visits is analytics, even if you call it "statistics".
Four mistakes that turn a banner into decoration
Scripts sit in the layout regardless of choice
The analytics snippet is pasted into layouts/app.blade.php, and the banner is a separate library. The visitor clicks "Reject" and the page keeps sending data, because nothing connects the two.
Embeds set cookies on page load
A YouTube iframe or a Google map in the contact page contacts its provider as soon as the page renders, before anyone presses play. The fix is a placeholder that loads the real embed only after a click or after consent.
No way back into the preferences
Many banners show once and never again. The visitor who accepted by accident, or changed their mind, has no visible way to withdraw. A permanent "Cookie settings" link in the footer solves this.
No record of what was chosen
Without a log, "the visitor consented" is an assertion you cannot back up. A consent record needs a time, the choices, and the policy version in force.

How to do it in Laravel with core45/laravel-cookieconsent
We maintain an open-source package for this, laravel-cookieconsent, and it runs on this website too. It wraps orestbida/cookieconsent and its companion iframemanager. The package adds a PHP configuration file instead of a hand-written JavaScript blob, translations through normal Laravel lang files, Blade directives that gate scripts, server-side reads of the visitor's choice, and a database audit trail. The library files are bundled and served from your own site, with no CDN request. Source and issues are in the package repository.
1. Install and place the banner
composer require core45/laravel-cookieconsent
php artisan vendor:publish --tag=cookieconsent-config
php artisan vendor:publish --tag=cookieconsent-assets
php artisan migrate
Then add @cookieconsent to the <head> of your layout. The published assets are copies, so re-publish them with --force after a package update that changes the bundled JavaScript or CSS.
2. Define categories and the opt-in mode
In config/cookieconsent.php you set 'mode' => 'opt-in' and list your categories, with necessary read-only and the others, such as analytics, off until chosen. Banner texts come from lang/vendor/cookieconsent/{locale}/cookieconsent.php, and the package ships translations for English, Polish and Spanish among others.
3. Hold back scripts with @cookiescript
This is the part most banners lack. The directive emits a blocked <script type="text/plain"> that runs only once the visitor accepts that category:
@cookiescript('analytics', 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX')
@cookiescript('analytics')
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
@endcookiescript
Remove the old unconditional snippet from the layout, otherwise you now load the tracker twice and the gate is pointless.
4. Gate embeds and add a way back
Enable iframemanager in the config, define a service with the category that unlocks it, and use the click-to-load placeholder:
@cookieconsent
@iframemanager
@iframe('youtube', $videoId)
For withdrawal, put @cookiepreferences where your privacy links live. It renders a button that reopens the preferences modal, and you can pass your own label and attributes: @cookiepreferences('Cookie settings', ['class' => 'footer__link']).
5. Read the choice on the server
Blade can branch on consent without waiting for JavaScript:
@consent('analytics')
<p>Shown only to visitors who accepted analytics.</p>
@endconsent
There is also a consent:analytics route middleware that returns 403 when consent is missing. One caveat from the README: the consent cookie can be edited by the visitor, so treat these checks as a compliance gate that reflects their stated preference, never as access control.
Keeping proof of consent
With logging enabled, every first consent and every later change is posted to an internal route and stored in a consent_logs table: the accepted and rejected categories, the language, a policy version and a hash of the effective configuration, and optionally IP address and user agent. The model refuses updates to existing rows, though the README is clear that raw SQL bypasses that, so for a hard guarantee revoke UPDATE and DELETE on the table from the application's database user.
Two decisions are yours. Storing an IP address next to a consent decision is itself processing personal data, so the package lets you hash it or skip it with capture_ip and set a retention_days limit. And you retrieve evidence with php artisan cookieconsent:export --format=csv, while php artisan cookieconsent:prune removes rows past retention. An optional read-only Filament resource lists the log for support staff.
A ten-minute audit for an existing site
- Open a private window with no extensions, and open the browser developer tools on the Network tab before loading the site.
- Load the home page and do not click the banner. List every third-party domain contacted.
- Check the Application tab for cookies and local storage set before any choice. Anything that is not strictly necessary is a finding.
- Click reject, or close the banner without accepting, and reload. The list of requests must not grow.
- Open a page with a video or a map. Confirm it shows a placeholder, not a live player.
- Accept only one category and check that only that category's scripts now load.
- Find the link that reopens the preferences. It should be on every page, not only in the privacy policy.
- Withdraw consent and confirm the scripts stop on the next page and the matching cookies are cleared.
- Ask where the record of consent lives and how you would export one visitor's entry.
- Compare the cookie list in your privacy policy with what you actually observed.
If steps 2 and 3 already show tracking, fix the layout first. That one change matters more than any banner design.
What to do next
If the audit shows scripts that run too early, the repair is usually small: move them behind a category, gate the embeds, add the footer link. It is a good moment to look at the rest of the stack too. We explain why we build on this framework in why Laravel suits business applications, and consent affects measurement, so see our technical SEO checklist before you change how analytics loads.
If you would rather not do it yourself, we build and repair websites with consent handled properly. For forms we publish a companion package, laravel-h-captcha. To talk it through with a person, write to us.