nickdekruijk/cookie-consent

符合欧盟法律的一个简单的cookie接受弹窗

2.4.0 2024-09-10 12:41 UTC

This package is auto-updated.

Last update: 2024-09-10 12:42:01 UTC


README

根据欧盟法律,访客应选择接受所有跟踪cookies/pixels/code。此软件包将为您的Laravel应用程序添加一个简单的“接受Cookies”弹出窗口。

安装

使用composer require nickdekruijk/cookie-consent安装软件包

如果需要自定义,请发布配置文件

php artisan vendor:publish --provider=NickDeKruijk\\CookieConsent\\CookieConsentServiceProvider

对于低于5.5版本的Laravel,将服务提供者添加到config/app.php文件中的'providers'数组中

NickDeKruijk\CookieConsent\CookieConsentServiceProvider::class,

前端

将以下内容添加到您希望显示弹出窗口的每个视图/页面中

@include('cookieconsent::show')

并将放置跟踪cookies/pixels/code的任何代码用cookieConsentAccepted()辅助函数包裹,例如

@if (cookieConsentAccepted())
// Your tracking code here
@endif

并根据需要样式化弹出窗口,例如

.cookieconsent-container {position:fixed;bottom:0;left:0;right:0;background-color:red;text-align:center;padding:50px;z-index:9999;color:#fff}
.cookieconsent-close {position:absolute;top:0;right:0;color:red;font-size:50px;padding:10px;line-height:.7;font-weight:bold;display:block}
.cookieconsent-button {display:inline-block;padding:10px 20px;border:2px solid #fff;border-radius:5px;text-decoration:none;color:inherit;margin:10px}
.cookieconsent-button:hover {background-color:rgba(255,255,255,0.5)}
.cookieconsent-button-accept {background-color:#fff;color:red}
.cookieconsent-button-accept:hover {background-color:rgba(255,255,255,0.8)}

更改文本/本地化

要更改文本/按钮/信息链接,请将文件从https://github.com/nickdekruijk/cookie-consent/tree/master/src/translations复制到/resources/lang/vendor/cookieconsent/文件,并根据需要进行编辑。