statikbe / laravel-cookie-consent
欧盟 Cookie 允许模态框
Requires
- php: ^8.0
- illuminate/http: ^9.0|^10.0|^11.0
- dev-main
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.12
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/ws-8.17.1
- dev-dependabot/npm_and_yarn/braces-3.0.3
- dev-develop
- dev-dependabot/npm_and_yarn/browserify-sign-4.2.3
- dev-dependabot/npm_and_yarn/express-4.19.2
- dev-dependabot/npm_and_yarn/babel/traverse-7.24.1
- dev-dependabot/npm_and_yarn/postcss-8.4.38
- dev-dependabot/npm_and_yarn/webpack-dev-middleware-5.3.4
- dev-dependabot/npm_and_yarn/follow-redirects-1.15.6
- dev-master
This package is auto-updated.
Last update: 2024-09-19 16:14:29 UTC
README
Laravel Cookie 允许模态框
该软件包包括用于 Cookie 标语的脚本和样式,以及一个模态框,访客可以在其中选择自己的 Cookie 偏好。
此软件包主要基于 spatie 的软件包:https://github.com/spatie/laravel-cookie-consent
唯一的例外是您可以选择启用哪些 Cookie。这仅在 Google Tag Manager 正确配置时才有效(基于在 Cookie 中设置的值的正则表达式配置)。
升级
您可以在这里找到我们的升级指南。
安装
您可以通过 composer 安装此软件包
composer require statikbe/laravel-cookie-consent
该软件包将自动注册自己。
首先 您需要 发布 JavaScript 和 CSS 文件
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-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="cookie-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="cookie-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="cookie-config"
这是已发布配置文件的内容:这将从您的 env 中读取策略 URL。
return [ 'cookie_key' => '__cookie_consent', 'cookie_value_analytics' => '2', 'cookie_value_marketing' => '3', 'cookie_value_both' => 'true', 'cookie_value_none' => 'false', 'cookie_expiration_days' => '365', 'gtm_event' => 'pageview', '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="cookie-lang"
视图
php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-views"
配置 Google Tag Manager
配置 Google Tag Manager 的所有步骤都可以在这里找到。
安全
如果您发现任何安全相关的问题,请通过电子邮件 info@statik.be 而不是使用问题跟踪器。
许可证
麻省理工学院许可证(MIT)。有关更多信息,请参阅许可文件。