bramdeleeuw / cookieconsent
符合GDPR的Cookie栏和同意检查器
Requires
- dev-master
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.2.17
- 1.2.16
- 1.2.15
- 1.2.14
- 1.2.13
- 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.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-6.5.3
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-no-js-popup
This package is auto-updated.
Last update: 2024-09-07 07:42:29 UTC
README
符合GDPR的Cookie栏和同意检查器
安装
通过composer安装模块
composer require bramdeleeuw/cookieconsent
将弹出模板包含在您的base Page.ss中
<% include CookieConsent %>
配置
您可以通过yml配置文件配置Cookie和Cookie组。您需要按提供者进行配置,对于提供者,点号被转换为下划线,例如ads.marketingcompany.com变为ads_marketingcompany_com。
通过通过yml配置Cookie,您可以在代码中检查同意并在必要时进行更改,例如要求分析或其他Cookie或跳过放置它们。
配置的Cookie的文本可以通过网站配置进行编辑,在这里CMS用户还可以添加其他Cookie。例如,如果网站用户决定嵌入YouTube视频,他或她可以指定由YouTube放置的Cookie。我建议创建以下三个组,这些组具有默认内容,当然您可以根据需要配置组。
Broarm\CookieConsent\CookieConsent: cookies: Necessary: local: - CookieConsent - ShowPopUp Marketing: ads_marketingcompany_com: - _track Analytics: local: - _ga - _gid
此模块包含了一些我们之前遇到的Cookie的默认内容。如果您想自己设置这些Cookie的默认内容,这是可能的,通过lang文件。如果您有此模块中不存在的Cookie描述,对lang文件的贡献将非常受欢迎!翻译通过 Transifex 管理。
文件结构如下
en: CookieConsent_{provider}: {cookie}_Purpose: 'Cookie description' {cookie}_Expiry: 'Cookie expire time' # for cookies from your own domain: CookieConsent_local: PHPSESSID_Purpose: 'Session' PHPSESSID_Expiry: 'Session' # for cookies from an external domain: CookieConsent_ads_marketingcompany_com: _track_Purpose: 'Cookie description' _track_Expiry: 'Cookie expire time'
然后您可以通过调用
if (CookieConsent::check('Analytics')) { // include google analytics }
您还可以配置默认js和css的要求。如果您选择默认不要求,请确保至少将javascript与您的bundle组合!
Broarm\CookieConsent\CookieConsent: include_javascript: true include_css: true create_default_pages: true
启用XHR模式
当您使用静态发布时,您将想要启用XHR模式。XHR模式通过xhr请求接受Cookie,并使用一些javascript通过显示/隐藏同意弹出窗口。
在您的yml配置中设置 xhr_mode
为 true
Broarm\CookieConsent\CookieConsent: xhr_mode: true
在您的javascript中,您可以利用实用程序类。这处理xhr请求和弹出窗口的可见性
import CookieConsent from '../vendor/bramdeleeuw/cookieconsent/javascript/src/cookieconsent'; const consent = new CookieConsent(); consent.enableXHRMode();
将资源包含在您的bundle中
如果您想将scss或js包含在您自己的bundle中,您可以通过以下方式做到这一点
// Import the CookieConsent utility import CookieConsent from '../vendor/bramdeleeuw/cookieconsent/javascript/src/cookieconsent'; const consent = new CookieConsent(); // This tool let's you check for cookie consent in your js files before you apply any cookies if (consent.check('Marketing')) { // add marketing cookie } // If you use Google Tag Manager this tool can also push the consent into the dataLayer object consent.pushToDataLayer();
对于scss,您只需导入scss文件
@import "cookieconsent/scss/cookieconsent";
确保文件的相对路径与您的用例匹配。
默认页面
此模块在运行dev/build时还会设置3个默认页面。如果您想防止这种行为,您应该禁用 create_default_pages
配置设置。创建的页面是CookiePolicyPage、PrivacyPolicyPage和TermsAndConditionsPage,并为每种页面类型填充了裸骨内容。当然,更改这些文本以适应您的用例是您或您的CMS用户的责任!