定制 la-haute-societe/craft-tarteaucitron 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

la-haute-societe/craft-tarteaucitron

Composer 安装命令:

composer require la-haute-societe/craft-tarteaucitron

包简介

Manage your sites' cookies with this tarteaucitron.js Craft CMS 5 integration

README 文档

README

Craft 5 - tarteaucitron.js

Handle GDPR in your Craft CMS projet the easy way with tarteaucitron.js.

This plugin currently support the following services :

  • Facebook Pixel
  • Google AdWords (conversion)
  • Google AdWords (remarketing)
  • Google Analytics (universal)
  • Google Maps
  • Google Tag Manager
  • Linkedin
  • reCAPTCHA
  • Twitter
  • Vimeo
  • Youtube
  • YouTube Js API

Requirements

This plugin requires Craft CMS 5.0.0 or later and PHP 8.2+. Version 3.x of this plugin supports Craft CMS 4.x, and version 2.x supports Craft CMS 3.x.

Installation

The easy way

Just install the plugin from the Craft Plugin Store.

From the command line

composer require la-haute-societe/craft-tarteaucitron
./craft install/plugin tarteaucitron

Tarteaucitron plugin Overview

tarteaucitron.js is a javascript library allowing you to handle GDPR compliance on your site. It allows end-users to give their consent before exposing them to third party services (such as Google, Facebook, Twitter…).

This plugin makes the integrating tarteaucitron.js in Craft CMS projects a breeze.

Using the Tarteaucitron plugin

Initialization script

Add the following twig code in the templates where you want the plugin to be loaded (in the <head> section of the layout page for example):

{{ craft.tarteaucitron.initScript }}

Loading services

Settings page

The plugin and its associated services are configurable from the plugin settings page.

To activate a service on your site, you need to activate it and then, depending on the service, add the given Twig code where you want the service to be loaded. The Twig code will output a tarteaucitron.js placeholder, that will get replaced by the content you wanted to load (e.g. a YouTube video, a Google Maps…) once tarteaucitron.js has loaded, and the user has given its consent for the service.

Service HTML Attributes

For some service templates, you can include a parameter named htmlAttributes. This parameter allows you to define html attributes for the html tag associated with the service.

Example :

{{ craft.tarteaucitron.vimeo({
    videoId: 'xxxxxxxx',
    width: '500px',
    height: '200px',
    htmlAttributes: {
        class: 'border-black',
    }
}) }}

Advanced usage

Manually instantiating services

If for some reason, you'd rather not use the craft.tarteaucitron.xxx() methods to instantiate your services, you can always add the tarteaucitron.js placeholder element by yourself.

These two examples will have the exact same result (you still need to enable the Vimeo service in the plugin settings):

{{ craft.tarteaucitron.vimeo({
    videoId: 'xxxxxxxx',
    width: '500px',
    height: '200px',
    htmlAttributes: {
        class: 'border-black',
    }
}) }}
<div
    class="border-black vimeo_player"
    data-videoID="xxxxxxxx"
    data-width="500px"
    data-height="200px"
></div>

Checking if a service is enabled

You may need to check whether a service is enabled (as in "enabled in the plugin settings", this has nothing to do with whether the user has given its consent):

{% if not craft.tarteaucitron.isTwitterEnabled() %}
    The site admin decided to disable Twitter widgets.
{% endif %}

Here are the available isXXXEnabled() methods:

  • isFacebookPixelEnabled()
  • isGoogleTagManagerEnabled()
  • isReCAPTCHAEnabled()
  • isGoogleMapsEnabled()
  • isGoogleAnalyticsUniversalEnabled()
  • isGoogleAdWordsConversionEnabled()
  • isGoogleAdWordsRemarketingEnabled()
  • isLinkedInEnabled()
  • isTwitterEnabled()
  • isVimeoEnabled()
  • isYoutubeEnabled()

JS - Dynamically adding elements managed by a service

Sometimes you need to dynamically add an element that should be managed by tarteaucitron.js (eg. you load a page fragment containing a Vimeo video using AJAX). Adding the tarteaucitron.js placeholder to the DOM isn't enough. You need to ask tarteaucitron.js to re-render the service :

// Create a tarteaucitron.js Vimeo placeholder element and add it to the document
var div = document.createElement('div');
div.className = 'vimeo_player';
div.attributes['data-videoID'] = 'XXXXXX';
div.dataset.width = '500px';
div.dataset.height = '300px';
document.body.appendChild(document.body.firstChild);

// Make tarteaucitron.js re-render the vimeo service
tarteaucitron.services.vimeo[tarteaucitron.state.vimeo ? 'js' : 'fallback']();

JS - Reacting to the user giving its consent to a service

Unfortunately, there is no clean way to do this at the moment, but a PR will be submitted to try to improve tarteaucitron.js.

Customizing JS output in the page

Instead of using {{ craft.tarteaucitron.initScript() }} to output both the tarteaucitron.js tag and the configuration JS tag, use:

  • {{ craft.tarteaucitron.javascriptImportTag() }} to output just the tarteaucitron.js import tag
  • {{ craft.tarteaucitron.javascriptConfigTag() }} to output just the tarteaucitron.js configuration inline JS tag

Customizing CSS output

By default, tarteaucitron.js imports the css/tarteaucitron.css stylesheet located next to the tarteaucitron.js file. You can prevent this using the useCustomCss setting of the plugin. You can provide your own stylesheet or use {{ craft.tarteaucitron.stylesheetTag() }} to output the tarteaucitron.js stylesheet import tag

Contribute

Want to contribute? See CONTRIBUTING.md

Brought to you by
Logo La Haute Société

la-haute-societe/craft-tarteaucitron 适用场景与选型建议

la-haute-societe/craft-tarteaucitron 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.48k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「craft-plugin」 「gdpr」 「rgpd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 la-haute-societe/craft-tarteaucitron 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 la-haute-societe/craft-tarteaucitron 我们能提供哪些服务?
定制开发 / 二次开发

基于 la-haute-societe/craft-tarteaucitron 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 6
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2019-03-29