keepsuit / laravel-cookie-solution
使您的网站符合欧盟cookie法规
Requires
- php: ^8.1
- illuminate/contracts: ^9.0 || ^10.0 || ^11.0
- spatie/laravel-package-tools: ^1.13.0
- symfony/intl: ^6.2 || ^7.0
Requires (Dev)
- larastan/larastan: ^2.8
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0 || ^7.0 || ^8.0
- orchestra/testbench: ^7.28 || ^8.8 || ^9.0
- pestphp/pest: ^1.21 || ^2.0
- pestphp/pest-plugin-laravel: ^1.1 || ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
- spatie/pest-plugin-snapshots: ^1.1 || ^2.0
- spatie/test-time: ^1.3
README
此软件包为Laravel应用程序提供可配置的cookie横幅。它还包括cookie政策和隐私政策页面的模板。
请注意,此软件包不是法律建议。您应始终咨询律师并根据您的需求更改文本和政策。
安装
您可以通过composer安装此软件包
composer require keepsuit/laravel-cookie-solution
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="cookie-solution-config"
这是已发布配置文件的内容
return [ /** * Enable or disable the cookie solution. */ 'enabled' => env('COOKIE_SOLUTION_ENABLED', true), /** * Name of the cookie where we store the user's consent. */ 'cookie_name' => 'laravel_cookie_solution', /** * The cookie's lifetime in days. */ 'cookie_lifetime' => 365, /** * Banner highlight color (ex. #3522dd). * If null, the default color will be used. */ 'highlight_color' => null, /** * Cookie toggle position (left or right). */ 'toggle_position' => 'right', /** * The entity responsible for the processing of the data. */ 'data_owner' => [ /** * Email address of the data owner. */ 'contact_email' => null, /** * Name/Company name and address of the data owner. * This is parsed as Markdown (you can use __text__ for bold and _text_ for italic). */ 'name_and_address' => null, ], ];
可选地,您可以使用以下命令发布资源、视图和翻译
php artisan vendor:publish --tag="cookie-solution-assets" php artisan vendor:publish --tag="cookie-solution-views" php artisan vendor:publish --tag="cookie-solution-translations"
如果您发布资源,请记住在更新软件包时发布新版本。您可以使用composer的post-update-cmd
脚本来自动化此操作
{ "scripts": { "post-update-cmd": [ // ... "@php artisan vendor:publish --tag=cookie-solution-assets --force" ] } }
用法
将cookie解决方案脚本包含在您的布局中(建议包含在<head>
标签中)
@include('cookie-solution::script')
在您的'AppServiceProvider'中注册使用的服务(您可以使用Service
类注册自己的服务)
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Keepsuit\CookieSolution\CookieSolution; use Keepsuit\CookieSolution\ServiceFactories\Google\GoogleAnalytics4ServiceFactory; use Keepsuit\CookieSolution\ServiceFactories\Google\GoogleDataProcessingLocation; use Keepsuit\CookieSolution\ServiceFactories\Google\GoogleTagManagerServiceFactory; use Keepsuit\CookieSolution\ServiceFactories\Meta\FacebookPixelServiceFactory; use Keepsuit\CookieSolution\ServiceFactories\Meta\MetaDataProcessingLocation; class AppServiceProvider extends ServiceProvider { public function boot(): void { $this->app->afterResolving(CookieSolution::class, function (CookieSolution $cookieSolution) { $cookieSolution->register(GoogleAnalytics4ServiceFactory::new()->location(GoogleDataProcessingLocation::IRELAND)->build()) ->register(GoogleTagManagerServiceFactory::new()->location(GoogleDataProcessingLocation::IRELAND)->build()) ->register(FacebookPixelServiceFactory::new()->location(MetaDataProcessingLocation::IRELAND)->build()); }); } }
使用您数据所有者的联系邮箱和姓名以及地址更新配置文件config/cookie-consent.php
return [ // ... /** * The entity responsible for the processing of the data. */ 'data_owner' => [ /** * Email address of the data owner. */ 'contact_email' => 'your_email@example.com', /** * Name/Company name and address of the data owner. * This is parsed as Markdown (you can use __text__ for bold and _text_ for italic). */ 'name_and_address' => <<<MARKDOWN __Your Company Name__ Your Street 1 City, Country MARKDOWN, ], ];
为cookie政策页面创建一个路由并包含cookie政策部分
<body> @include('cookie-solution::cookie-policy') </body>
为隐私政策页面创建一个路由并包含隐私政策部分
<body> @include('cookie-solution::privacy-policy') </body>
有关部分和如何自定义它们的更多信息,请参阅视图自定义部分。
自定义
突出颜色
您可以通过更改highlight_color
配置值来自定义横幅的突出颜色。
切换位置
您可以通过更改toggle_position
配置值将切换位置更改为left
或right
(默认为right
)。如果您需要进行更高级的自定义,您可以使用一些CSS编辑切换位置
:root { --cs--toggle-position-bottom: 4rem; /* position from the bottom */ --cs--toggle-position-x: 2rem; /* position from the left or right (depending on `toggle_position` value) */ } /* change the position for desktop */ @media (min-width: 1024px) { :root { --cs--toggle-position-bottom: 2rem; --cs--toggle-position-x: 1rem; } }
视图
如果您想自定义视图,您可以使用php artisan vendor:publish --tag="cookie-solution-views"
发布它们,并按您的喜好进行样式设计。自定义组件<cookie-solution-policy-formatter/>
用于应用默认样式,您可以安全地移除它来自定义视图。
检查状态
您可以使用CookieSolution::status()
方法从Laravel中检查用户的同意状态,该方法返回一个包含检查是否已接受目的的辅助函数的CookieSolutionStatus
对象。
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
有关如何报告安全漏洞的更多信息,请参阅我们的安全策略。
鸣谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。