elleracompany / craft-cookie-consent
Craft Cookie Consent 插件
Requires
- ext-json: *
- craftcms/cms: ^5.0
Requires (Dev)
- craftcms/phpstan: dev-main
- dev-master
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- v1.x-dev
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.0.0
- 1.1.0.1
- 1.1.0
- 1.0.0.3
- 1.0.0.2
- 1.0.0.1
- 1.0.0
- dev-release/5.0.2
- dev-bugfix/#109
- dev-feature/craft-5-update
- dev-release/v4.0.5
This package is not auto-updated.
Last update: 2024-09-23 07:11:29 UTC
README
Ellera Cookie Consent 插件
安装插件
您可以从插件商店安装此插件。
在模板中创建钩子
以完全控制插件渲染同意模板的位置。对于键盘和屏幕阅读器用户,cookie横幅应该是DOM中的第一件事。
您需要在相关布局文件中在您的start-body-tag之后添加此行
{% hook 'after-body-start' %}
为您的网站激活插件
导航到控制面板中的插件。如果您有正确的权限,它应该会在菜单中可见。
转到"网站设置"并添加您的cookie和cookie组(我们已为您添加了一些基本的)。
切换"激活"开关,您就完成了!
自定义
使用自定义模板
更新网站设置下的模板文件以指向您的模板文件。路径由Craft::$app->view->renderTemplate()
渲染。
使用自定义CSS和/或JS
如果您有自己的,您可以在网站设置中关闭加载资源。
您可以在vendor/elleracompany/craft-cookie-consent/src/resources
中查看插件当前实现的功能。
检查用户同意
您可以使用此功能来管理脚本的cookie生成
{% if craft.cookieConsent.getConsent('slug') %}
您可以在SEOmatic中使用它,通过导航到admin/seomatic/tracking
并更新脚本模板。
计划中的功能
- Project.yaml 兼容性
使用SEOmatic的示例
您需要在twig模板中清除SEOmatic缓存(不在SEOmatic脚本字段中)
{# -- START Cache-bust seomatic -- #}
{% set scriptContainer = seomatic.script.container() %}
{% do scriptContainer.clearCache(true) %}
{# -- END Cache-bust seomatic -- #}
之后,您可以将SEOmatic中的脚本字段更新为以下内容
{% if trackingId.value is defined and trackingId.value %}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','{{ analyticsUrl.value }}','ga');
ga('create', '{{ trackingId.value |raw }}', 'auto'{% if linker.value %}, {allowLinker: true}{% endif %});
{% if ipAnonymization.value or craft.cookieConsent.getConsent('default-marketing') != true %}
ga('set', 'anonymizeIp', true);
{% endif %}
{% if displayFeatures.value and craft.cookieConsent.getConsent('default-marketing') %}
ga('require', 'displayfeatures');
{% endif %}
{% if ecommerce.value and craft.cookieConsent.getConsent('default-marketing') %}
ga('require', 'ecommerce');
{% endif %}
{% if enhancedEcommerce.value and craft.cookieConsent.getConsent('default-marketing') %}
ga('require', 'ec');
{% endif %}
{% if enhancedLinkAttribution.value and craft.cookieConsent.getConsent('default-marketing') %}
ga('require', 'linkid');
{% endif %}
{% if enhancedLinkAttribution.value and craft.cookieConsent.getConsent('default-marketing') %}
ga('require', 'linker');
{% endif %}
{% set pageView = (sendPageView.value and not craft.app.request.isLivePreview) %}
{% if pageView %}
ga('send', 'pageview');
{% endif %}
{% endif %}
清理旧的同意
您可以使用控制台命令从数据库中清除旧的同意。
./craft cookie-consent/retention/clear
此命令有三个可选参数
注意:您只能传递sid或handle - 不能同时传递。如果没有指定站点,则将从所有站点删除同意。
示例:从ID为1的站点中删除所有超过2年的同意
./craft cookie-consent/retention/clear -sid 1 -d 730
window.ccc对象
从版本1.6.0开始,默认模板中添加了一个新的对象window.ccc。
该对象包含同意及其状态的键值对。
如果默认javascript文件已加载,并且存在一个ID为#elc-cookie-consent-form的表单,并且具有data-show-attribute的url指向同意显示端点(/cookie-consent/show),则将创建该对象
致谢
插件图标由Flaticon的Trinh Ho设计