The GDPR (General Data Protection Regulation) is an EU’s General Data Protection Regulation. GDPR Personal data includes names, email, addresses, numbers, information about appearance, health, location, as well as online identifiers such as cookies, IP addresses, search, and browser history.

In this article, we’re going to see few different approaches in integrating the cookie consent in the Laravel website.

Option # 01:

The very first option is by using a really cool package by spatie.

Before installing the package, please note that, this package utilizes TailwindCSS styles, so if you’re not using Tailwind within your application. you may need to modify the styles according to yourself.

composer require spatie/laravel-cookie-consent

Publish the config, and view files:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config" 

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-views"

Now, the package is all set, you can simply put the following line of code within your body tags to make it work, likeso:

//in your blade template
@include('cookie-consent::index')

Option # 02:

This option is quite straight forward as well and requires a bit of custom code and placing the files within their respective directories and finally showing the cookie popup. Basically this option can be used for any kind of web application other than Laravel, let’s just say WordPress or even simple static HTML website.

Cookie Consent CSS

.cookiealert {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
margin: 0 !important;
z-index: 999;
opacity: 0;
visibility: hidden;
border-radius: 0;
transform: translateY(100%);
transition: all 500ms ease-out;
color: #ecf0f1;
background: #212327 url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEECAIAAAAd4J55AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZ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e8ZfH1nnOTgZeLO6QAIwNABv7x+a9l6MzvcDjVPxO2o63dZJ/dpMAAEYJiAovXs81QRcO7rFQl+5WKSRNSRLgAEYJiA4vX1ixSmV/tY2wV9vaLC3wpFEh0AARg44P8LMACM4cURIdXaEQAAAABJRU5ErkJggg==');
}

.cookiealert.show {
opacity: 1;
visibility: visible;
transform: translateY(0%);
transition-delay: 1000ms;
}

.cookiealert a {
text-decoration: underline
}

.cookiealert .acceptcookies {
margin-left: 10px;
vertical-align: baseline;
}

Cookie Consent JS

(function () {
"use strict";

var cookieAlert = document.querySelector(".cookiealert");
var acceptCookies = document.querySelector(".acceptcookies");

if (!cookieAlert) {
return;
}

cookieAlert.offsetHeight; // Force browser to trigger reflow (https://stackoverflow.com/a/39451131)

// Show the alert if we cant find the "acceptCookies" cookie
if (!getCookie("acceptCookies")) {
cookieAlert.classList.add("show");
}

// When clicking on the agree button, create a 1 year
// cookie to remember user's choice and close the banner
acceptCookies.addEventListener("click", function () {
setCookie("acceptCookies", true, 365);
cookieAlert.classList.remove("show");

// dispatch the accept event
window.dispatchEvent(new Event("cookieAlertAccept"))
});

// Cookie functions from w3schools
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
})();

Cookie Consent HTML

Finally, place the following HTML code in your blade template to make it work. Don’t forget to include CSS and JS files within your applications & make sure to upgrade your cookie URL.

<div class="alert text-center cookiealert" role="alert">
    <b>Do you like cookies?</b> &#x1F36A; We use cookies to ensure you get the best experience on our website. <a
        href="<your_cookie_url>" target="_blank">Learn more</a>
    <button type="button" class="btn btn-primary btn-sm acceptcookies">
        I agree
    </button>
</div>

Conclusion

Let us know in the comment section below which option works best for you while integrating GDPR cookie consent popup within your Laravel Application.

You may also Like