apility / netflex-cookie-consent
用于Netflex SDK的欧盟Cookie同意模态框
Requires
- php: ^7.0|^8.0
- illuminate/http: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
README
该软件包包括用于Cookie横幅和模态框的脚本和样式,访客可以在其中选择自己的Cookie偏好设置。
本软件包主要基于spatie的版本:https://github.com/apility/netflex-cookie-consent
唯一例外是您可以选择您想启用的哪些Cookie。这仅在Google Tag Manager正确配置时才起作用(基于在Cookie中设置的值的正则表达式配置)。
升级
您可以在这里找到我们的升级指南。
安装
您可以通过composer安装此软件包
composer require apility/netflex-cookie-consent
该软件包将自动注册自身。
首先,您需要发布javascript和css文件
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="public"
将css/cookie-consent.css包含到您的base.blade.php或您使用的任何其他基本模板中。
<link rel="stylesheet" type="text/css" href="{{asset("vendor/cookie-consent/css/cookie-consent.css")}}">
javascript文件包含在cookie片段中,并将添加到您的body末尾。
使用
我们不会在视图中包含片段,而是会自动添加。这是通过中间件使用两种方法完成的
- 第一种选择:使用kernel在您的整个项目中包含它
// app/Http/Kernel.php class Kernel extends HttpKernel { protected $middleware = [ // ... \Statikbe\CookieConsent\CookieConsentMiddleware::class, ]; // ... }
- 第二种选择:将其作为路由中间件包含,并将其添加到您想要的任何路由中。
// app/Http/Kernel.php class Kernel extends HttpKernel { // ... protected $routeMiddleware = [ // ... 'cookie-consent' => \Statikbe\CookieConsent\CookieConsentMiddleware::class, ]; } // routes/web.php Route::group([ 'middleware' => ['cookie-consent'] ], function(){ // ... });
这将添加cookieConsent::index
到响应内容中,在关闭body标签之前。
自定义对话框文本
如果您想修改对话框中显示的文本,可以使用此命令发布lang文件
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="lang"
这将此文件发布到resources/lang/vendor/cookieConsent/en/texts.php
。
return [ 'alert_title' => 'Deze website gebruikt cookies', 'setting_analytics' => 'Analytische cookies', ];
如果您想将值翻译成例如英语,只需将该文件复制到resources/lang/vendor/cookieConsent/fr/texts.php
并填写英语翻译。
自定义对话框内容
如果您需要完全控制对话框的内容,可以发布软件包的视图
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="views"
这将index
视图文件复制到resources/views/vendor/cookieConsent
。
cookie-settings
视图文件只是您需要在页面上放置的片段。最好放在cookie政策url旁边,通常是页脚。
<a href="javascript:void(0)" class="js-lcc-settings-toggle">@lang('cookie-consent::texts.alert_settings')</a>
这给了您的访客再次更改设置的机会。
发布
配置
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="config"
这是发布配置文件的配置内容:这将从您的env中读取策略url。
return [ 'cookie_key' => '__cookie_consent', 'cookie_domain' => env('SESSION_DOMAIN'), 'cookie_value_analytics' => 'analytics', 'cookie_value_marketing' => 'marketing', 'cookie_value_both' => 'all', 'cookie_value_none' => 'none', 'cookie_expiration_days' => '365', 'gtm_event' => 'cookie_refresh', 'ignored_paths' => [], 'policy_url_en' => env('COOKIE_POLICY_URL_EN', null), 'policy_url_fr' => env('COOKIE_POLICY_URL_FR', null), 'policy_url_nl' => env('COOKIE_POLICY_URL_NL', null), ];
您可以自定义一些与您的GTM一起工作的设置。
不在cookie政策页或其他页面上显示模态框
如果您不希望在特定页面上显示模态框,可以将相对URL添加到忽略路径设置中。这也接受通配符(请参阅Laravel Str::is()
辅助器)。
'ignored_paths => ['/en/cookie-policy', '/api/documentation*'];
翻译
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="lang"
视图
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="views"
配置Google Tag Manager
您可以在这里找到配置Google Tag Manager的所有步骤。
使用同意模式v2配置Google Tag Manager
您可以在这里找到配置同意模式v2的Google Tag Manager的所有步骤。
安全
如果您发现任何与安全相关的问题,请通过电子邮件发送到 info@statik.be,而不是使用问题跟踪器。
许可证
MIT许可(MIT)。请参阅 许可文件 以获取更多信息。