xddesigners/silverstripe-cookieconsent
Composer 安装命令:
composer require xddesigners/silverstripe-cookieconsent
包简介
Cookie bar and consent checker for Silverstripe
README 文档
README
GDPR compliant cookie bar and consent checker
Installation
Install the module trough composer:
composer require xddesigners/silverstripe-cookieconsent
Include the popup template in your base Page.ss
<% include CookieConsent %>
Configuration
You can configure the cookies and cookie groups trough the yml config. You need to configure by provider, for providers the dots are converted to underscores e.g. ads.marketingcompany.com becomes ads_marketingcompany_com.
By configuring cookies trough yml you can check for consent in your code and make the necessary changes e.g. require the analytics or other cookies or skip placing them.
The texts for the configured cookies are editable trough the Site Config, here other cookies can also be added by CMS users. For example if a site user decides to embed a Youtube video he or she can specify the cookies that are placed by Youtube. I reccomend the following three groups to be created, these have default content, of course you are free to configure groups as you see fit.
XD\CookieConsent\CookieConsent: cookies: Necessary: local: - CookieConsent - ShowPopUp Marketing: ads_marketingcompany_com: - _track Analytics: local: - _ga - _gid
This module comes with some default content for cookies we've encountered before. If you want to set default content for these cookies yourself that is possible trough the lang files. If you have cookie descriptions that are not in this module, contributions to the lang files are much appreciated! Translations are managed trough Transifex.
The files are structured as such:
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'
Then you can check for consent in your code by calling
if (CookieConsent::check('Analytics')) { // include google analytics }
You can also configure the requirement of the default js and css. Make sure you combine at least the javascript in you bundle if you chose not to require by default!
XD\CookieConsent\CookieConsent: include_javascript: true include_css: true create_default_pages: true
Enable XHR mode
When you use static publishing, you'll want to enable XHR mode. XHR mode accepts the cookies trough an xhr request and shows/hides the consent popup with the help of some javascript.
In your yml config set xhr_mode to true
XD\CookieConsent\CookieConsent: xhr_mode: true
In your javascript, you can make use of the utility class. This handles the xhr request and visibility of the popup:
import CookieConsent from '../vendor/xd/cookieconsent/javascript/src/cookieconsent'; const consent = new CookieConsent(); consent.enableXHRMode();
Include assets in your bundle
If you want to include the scss or js in your own bundle you can do that by:
// Import the CookieConsent utility import CookieConsent from '../vendor/xd/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();
For the scss you can just import the scss file
@import "cookieconsent/scss/cookieconsent";
Make sure the relative paths to the files match your use case.
Default Pages
This module also sets up 3 default pages on running dev/build.
If you want to prevent that behaviour you should disable the create_default_pages config setting.
The pages created are a CookiePolicyPage, PrivacyPolicyPage and TermsAndConditionsPage and are filled with bare bones content for each of the page types.
Of course it is your or your CMS users responsibility to alter these texts to make them fitting to your use case!
xddesigners/silverstripe-cookieconsent 适用场景与选型建议
xddesigners/silverstripe-cookieconsent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 213 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cookie」 「bar」 「silverstripe」 「consent」 「gdpr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xddesigners/silverstripe-cookieconsent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xddesigners/silverstripe-cookieconsent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xddesigners/silverstripe-cookieconsent 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bar with versions list of vendor libraries for Tracy
Simple PHP chart drawing library
Add a configurable cookie consent banner to the website.
A fork of runcmf/runtracy
Analytics chooser extensions for site settings.
统计信息
- 总下载量: 213
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-06-06