Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Cookie Consent Laravel Package

jeffersongoncalves/laravel-cookie-consent

Simple Laravel cookie consent banner with GDPR/CCPA-friendly preferences. Drop-in head/body includes, optional view publishing for customization, and settings stored in the database via spatie/laravel-settings with helper access for runtime updates.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Laravel-native: Built for Laravel, leveraging Laravel’s service container, migrations, and Blade templating. Minimal abstraction overhead.
    • Dynamic Configuration: Uses spatie/laravel-settings for runtime-adjustable settings (e.g., GDPR/CCPA compliance text, UI themes). Aligns with modern Laravel practices (e.g., Filament/Nova admin panels).
    • Unobtrusive: Lightweight (~2KB CDN assets) with minimal frontend footprint. Integrates via Blade includes (@include('cookie-consent::...')), avoiding global JS pollution.
    • Compliance-First: Explicitly designed for GDPR/CCPA, with structured consent management (e.g., content_allow/content_deny settings).
    • Extensible: Underlying Osano CookieConsent plugin supports advanced features (e.g., cookie categories, auto-blocking scripts) if needed.
  • Cons:

    • Vendor Lock-in: Relies on spatie/laravel-settings (not a core Laravel dependency). May require additional setup if not already in use.
    • Limited Customization Hooks: UI/UX customization is constrained by the underlying Osano library’s templates. Advanced theming would require overriding published views or CSS.
    • No Built-in Analytics: Lacks native integration with tools like Google Analytics or Matomo for tracking consent status. Would need manual implementation (e.g., via middleware).

Integration Feasibility

  • Low Effort for Basic Use:

    • Prerequisites: Laravel 9+ (tested up to 13.x), PHP 8.1+. Compatible with most modern Laravel stacks (Lumen excluded).
    • Steps:
      1. composer require jeffersongoncalves/laravel-cookie-consent
      2. php artisan migrate (creates settings table).
      3. Add Blade includes to resources/views/layouts/app.blade.php:
        @include('cookie-consent::cookie-consent-head')
        @include('cookie-consent::cookie-consent-body')
        
    • Zero Config: Defaults are pre-populated; only customize if needed (e.g., for branding).
  • Advanced Use Cases:

    • Dynamic Consent Logic: Extend via middleware to block scripts until consent is given:
      // app/Http/Middleware/CheckCookieConsent.php
      public function handle(Request $request, Closure $next) {
          if (!$request->cookie('cookie_consent') && !$request->ipIsTrusted()) {
              abort(403, 'Cookie consent required.');
          }
          return $next($request);
      }
      
    • Multi-Language Support: Override published views (resources/views/vendor/cookie-consent/) to support translations (though v3.x removed built-in i18n).
    • Custom Cookie Categories: Leverage Osano’s cookieconsent JS API to define granular categories (e.g., analytics, marketing) via data-cookieconsent attributes.

Technical Risk

Risk Area Severity Mitigation Strategy
Dependency Updates Medium Monitor spatie/laravel-settings and Osano for breaking changes. Use composer why-not to test updates.
CDN Failures Low Publish assets locally via php artisan vendor:publish --tag=cookie-consent-assets (if CDN downtime is a concern).
Consent Logic Errors High Test edge cases (e.g., user clears cookies, returns later). Use middleware to validate consent before sensitive actions.
Compliance Gaps Medium Audit against GDPR/CCPA requirements (e.g., explicit consent for analytics cookies). Consider adding a "Do Not Sell" link for CCPA.
Performance Low CDN-hosted assets are lazy-loaded by default. No significant impact on TTFB.

Key Questions for Stakeholders

  1. Regulatory Requirements:

    • Are there specific cookie categories (e.g., "necessary," "analytics," "ads") that must be explicitly labeled or managed separately?
    • Is there a requirement to log consent decisions (e.g., for audits)? If so, how should this be implemented (database table, third-party service)?
  2. User Experience:

    • Should the consent banner be dismissible without explicit "Allow" or "Deny" (e.g., for "necessary" cookies only)?
    • Are there brand-specific UI/UX requirements (e.g., custom colors, animations)?
  3. Technical Constraints:

    • Is spatie/laravel-settings already in use in the codebase? If not, is there appetite to add it?
    • Are there existing analytics tools (e.g., Google Analytics, Mixpanel) that need to be gated behind consent?
  4. Maintenance:

    • Who will manage updates to the consent text (e.g., for legal changes)?
    • Should a Filament/Nova admin panel be built to expose settings to non-technical users?

Integration Approach

Stack Fit

  • Laravel Ecosystem:

    • Core Laravel: Seamless integration with Blade, middleware, and migrations. No framework modifications required.
    • Admin Panels: Works natively with Filament, Nova, or Backpack for managing settings via UI.
    • Testing: Compatible with Pest/Testbench (Laravel 13.x support confirmed).
    • Frontend: Agnostic to JS frameworks (React/Vue/Angular). Uses vanilla JS for consent management.
  • Non-Laravel Components:

    • Osano CookieConsent: Underlying library handles consent logic. No direct integration needed unless extending functionality.
    • spatie/laravel-settings: Required for dynamic configuration. Lightweight (~10KB) and widely adopted.
  • Anti-Patterns:

    • Avoid using this for non-Laravel projects (e.g., Symfony, WordPress). Not a standalone JS library.
    • Avoid overriding core package files (e.g., vendor/jeffersongoncalves/...). Use published assets or custom views.

Migration Path

Phase Steps Rollback Plan
Discovery Audit existing cookie usage (e.g., via browser dev tools). Identify categories (analytics, ads, etc.) that need consent. None.
Installation composer require jeffersongoncalves/laravel-cookie-consent composer remove jeffersongoncalves/laravel-cookie-consent
Configuration Run migrations (php artisan migrate). Customize settings via code or admin panel. Add Blade includes to layout file. Revert migrations (php artisan migrate:rollback). Remove Blade includes.
Testing Verify banner appears, consent is stored in cookies, and scripts are blocked until consent. Test edge cases (e.g., cookie deletion). Rollback to pre-integration state.
Deployment Deploy to staging, validate compliance, then production. Use feature flags or middleware to toggle consent enforcement.
Monitoring Log consent-related events (e.g., "user denied cookies") for compliance audits. Disable logging if privacy concerns arise.

Compatibility

  • Laravel Versions: Tested on 9.x–13.x. Avoid 8.x due to PHP 8.1+ requirement.
  • PHP Extensions: None critical. Standard Laravel stack (e.g., fileinfo, mbstring) suffices.
  • Frontend Frameworks: No conflicts with React/Vue/Angular if using Blade includes correctly. Ensure no duplicate cookieconsent JS/CSS.
  • Third-Party Packages:
    • Conflict Risk: Low with most packages. Potential overlap with other cookie managers (e.g., laravel-cookie-manager). Audit for duplicates.
    • Synergy: Works well with:
      • Filament/Nova: For managing settings via admin panel.
      • Laravel Fortify/Sanctum: For consent-related user preferences.
      • Laravel Analytics: To gate script loading (e.g., Google Analytics).

Sequencing

  1. Pre-requisites:

    • Ensure spatie/laravel-settings is compatible with your Laravel version (check Spatie’s docs).
    • Audit existing cookie usage to define consent categories.
  2. Core Integration:

    • Install package → Migrate → Add Blade includes.
    • Customize settings (e.g., branding, text) via CookieConsentSettings class.
  3. Enhancements (Optional):

    • Build a Filament resource for settings management.
    • Add middleware to block scripts until consent.
    • Extend with custom cookie categories or analytics integration.
  4. Post-Launch:

    • Monitor consent
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor