bramdeleeuw/cookieconsent

符合GDPR的Cookie栏和同意检查器

安装次数: 9,497

依赖项: 3

建议者: 1

安全: 0

星级: 16

关注者: 3

分支: 7

开放问题: 6

类型:silverstripe-vendormodule


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_modetrue

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用户的责任!

维护者

Bram de Leeuw