承接 docono/cookie-consent-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

docono/cookie-consent-bundle

最新稳定版本:v2.0.3

Composer 安装命令:

composer require docono/cookie-consent-bundle

包简介

cookie consent for pimcore

README 文档

README

setup

define in the config the consents

dcc:
    consents:
        - analytics
        - youtube
        - my-consent

include the js:

{% do pimcore_inline_script().appendFile(asset(dcc().jsFile())) %}

or

{{ dcc().jsScript()|raw }}

there is also a basic styling if needed

{% do pimcore_head_link().appendStylesheet(dcc().cssFile()) %}

css vars:

  --dcc-clr-white: #FBFAF5;
  --dcc-clr-black: #2A363B;
  --dcc-clr-green: #99B898;

  --dcc-body-w: 50rem;
  --dcc-gap: 2rem;
  --dcc-my: 3rem;
  --dcc-mx: auto;

  --dcc-yt-width: 50rem;
  --dcc-yt-ratio: 16/9;

  --dcc-switch-size: 1.5rem;

consent dialog

Create your consent dialog whatever you like it. Just ensure:

  • the main container has the id "dc-consent"
  • the "accept essential" button has the id "accept-essential"
  • the "accept selected consents" button has the id "accept-selected"
  • the name of the checkbox response with the defined consent
{% do dcc().dialog() %}
<div id="dc-consent" data-ttl="48">
    <div class="dcc-body">
        <h3>{{ 'dcc.dialog.title'|trans }}</h3>
        <p>
            {{ ('dcc.dialog.text'|trans)|raw }}
        </p>

        <div class="dcc-consents">
            <label>
                <div class="dcc-slider">
                    <input type="checkbox" name="essential" checked disabled>
                    <div class="slider"></div>
                </div>

                {{ ('dcc.consent.essential')|trans }}
            </label>

            {% for permission in dcc().permissionList() %}
                <label>
                    <div class="dcc-slider">
                        <input type="checkbox" checked name="{{ permission }}">
                        <div class="slider"></div>
                    </div>

                    {{ ('dcc.consent.' ~ permission)|trans }}
                </label>
            {% endfor %}
        </div>


        <div class="dcc-actions">
            <button id="accept-essential" class="dcc-button -inverted">{{ 'dcc.button.essential'|trans }}</button>
            <button id="accept-selected" class="dcc-button -selected">{{ 'dcc.button.selected'|trans }}</button>
        </div>
    </div>
</div>
{{ dcc().endDialog()|raw }}

JavaScript

To prevent any JavaScript from execution, such as google analytics, use the JS functionality: Set the "data-consent" to the required consent name.

{% do dcc().js().start() %}
<script
        data-consent="analytics"
        src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxx"
        async
></script>
{{ dcc().js().end()|raw }}

The "src" attribute will be replaced with "data-src". Is the consent given, the script will be loaded.

or

{% do dcc().js().start() %}
<script data-consent="analytics" type="text/javascript">
    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments)
    }

    gtag('consent', 'default', {ad_storage: 'denied', analytics_storage: 'denied'});
    gtag('set', 'ads_data_redaction', true);
    gtag('set', 'url_passthrough', true);
    gtag('js', new Date());
    gtag('config', 'xxxx');
</script>
{{ dcc().js().end()|raw }}

The script "type" attribute value will be replaced with "text/plain", which prevents the script of being executed. If the consent is given, the script tag will be executed.

Youtube

With the youtube helper, you ensure that no call will be made to youtube from the client browser. If the the consent "youtube" is not accepted, a placeholder with a base64 thumbnail will be shown. Is the thumbnail clicked, a consent prompt for that video will be shown.

styling

  • container: .dcc-youtube
  • play icon: .dcc-youtube__play
  • consent prompt: .dcc-youtube__consent
  • consent prompt buttons: .consent-youtube__decline, .consent-youtube__accept

translations

  • dcc.youtube.message
  • dcc.youtube.decline
  • dcc.youtube.accept
{{ dcc().youtube('https://www.youtube-nocookie.com/embed/xxxxxx?controls=0')|raw }}

or get html tag with getHtml(thumbnailQuality='high', attributes=[])

{{ dcc().youtube('https://www.youtube-nocookie.com/embed/xxxxxx?controls=0').getHtml('low', {role: 'video'})|raw }}

Slots

If you want to show any content only if the consent is accepted, then there are slots

<% do dcc().slot('mySlot').start('requiredConsent') %}
<div>
    content if 'requiredConsent' is accepted
</div>
{{ dcc().slot('mySlot').end()|raw }}}

cookie blocker

There is a cookie blocker integrated, which blocks all cookies if the name is not white listed. To block all cookies, the js need to be included inline to ensure it is executes first.

{{ dcc().jsScript()|raw }}

Activate the blocker and register a cookie-namespace with all the cookie names

<script>
    window.dccBlock = true
    window.dccData = window.dccData || []

    function dcc() {
        window.dccData.push(arguments)
    }

    dcc('my-cookie-namespace', ['cookie-name-one', 'cookie-name-two'])
</script>

Bind the cookie-namespace to the consent

<input type="checkbox" checked name="my-consent" data-dcc-cn="my-cookie-namespace">

There are also predefined cookie-namespaces with all the necessary cookie names:

  • matomo
  • google-analytics
  • google-tag-manager
  • google-ad-sense

统计信息

  • 总下载量: 384
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2023-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固