68publishers-cookie-consent

中文文档
1.0.0发布于 2024/06/21MITES Module近 30 天下载 2823

Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.

此软件包已被标记为弃用

The package has been moved to @68publishers/cookie-consent.

原始使用文档
文档目录13 节
  1. Table of contents
  2. Integration into the GTM
  3. Configuration
  4. Basic options
  5. Consent & Setting modal options
  6. Cookies options
  7. Storage options
  8. Event triggers based on composite consent
  9. Translation settings
  10. Locale detection
  11. How to manage revisions
  12. Stylesheets
  13. Page scripts
Cookie Consent Logo

Cookie Consent

An extended integration of orestbida/cookieconsent with support of the Google Tag Manager.


  • :white_check_mark: Easy configurable GTM template
  • :white_check_mark: Configurable storages standardized by Google
  • :white_check_mark: Possibility to synchronize consents between more storages
  • :white_check_mark: Default translations

Table of contents

Integration into the GTM

Open Google Tag Manager web administration and select a container for your website. Next, go through the Templates link in the left navigation and click on the button New inside a section Tag Templates.

All you need is a file gtm_template.tpl from the root directory of this package. Download the file and import it in the Template editor:

Right dropdown

After successful import click on the button Save, leave the Template editor, and go through the Tags link in the left navigation. Then create the new tag with the imported Template, as trigger set an option Consent Initialization - All Pages and save it.

Cookie consent tag

Now you can open a preview of the website and as you can see the cookie widget is here! But let's configure it a bit.

Configuration

:exclamation: Locking the package version is highly recommended (see the field Package version below) after you successfully configure the template. Avoid using the latest version in production containers!

The plugin is configurable using fields inside the tag definition.

Basic options

FieldDescription
Package versionVersion of the package 68publishers/cookie-consent. Valid inputs are the latest or a version in formats x.x.x, x.x.x-beta.x and x.x.x-alpha-x. For available versions see the releases.
Make consent requiredThe page will be blocked until a user action.
Show the widget as soon as possibleThe widget will be displayed automatically on the page load. You must trigger the widget manually by calling CookieConsentWrapper.unwrap().show() if the option is disabled.
Hide from botsEnable if you don't want the plugin to run when a bot/crawler/webdriver is detected.
RevisionRevision number of your terms of use of cookies. For more information see below.
DelayNumber of milliseconds before showing the consent modal.

Both sections contain these fields: Layout, Position, Transition. These settings affect where modals appear and what shape they take. The behavior of the consent modal buttons can be configured through fields Primary button role, Secondary button role (accept necessary cookies or open the settings modal), and Buttons order. See the widget documentation for more details.

The consent modal has also an option Show third button that adds the third button to the modal. If the secondary button's role is Open settings the third button's role is Accept necessary and vice versa.

The settings modal has one special option with the name Settings modal trigger selector. A value of the option can be CSS selector for automatic creation of the trigger button that opens the modal. Check the example.

Cookies options

FieldDescription
Cookie nameThe name of a cookie value that holds information about the user's consent.
Cookie domainThe domain name for the cookie that holds information about the user's consent, for example ".example.com". If the value is empty, it is automatically set in a browser using the "window.location.hostname" variable.
Cookie expirationExpiration of the cookie in days.
Enable cookies auto-clearAll cookies will be deleted based on the user's consent and a selected strategy if the option is enabled.
Cookies auto-clear strategyStrategy for cookies auto-clear feature.
Cookie namesNames of the cookies that will be deleted or kept (based on a selected strategy).

The following strategies are implemented:

  1. Clear all except defined* - All cookies except those you define in the field Cookie names will be deleted when the user denies any storage.
  2. Clear defined only* - All cookies you defined in the field Cookie names will be deleted when the user denies any storage.
  3. Use cookie tables - Cookie clearing is based on cookie tables from the original plugin. Integration of CMP application is required for this option.

* There is no need to define a name from the Cookie name field because this cookie is never automatically deleted.

Storage options

The following types of storage are available:

  • Functionality storage
  • Security storage
  • Personalization storage
  • Ad storage
  • Ad user data
  • Ad personalization
  • Analytics storage

Each storage defines the name of a trigger that will be invoked if the user provides consent. It is not necessary to use or display each storage in the widget. Also, the consent for the storage can be synchronized with the consent of another storage.

FieldDescription
Visibility and default stateDefines whether the storage should be visible in the widget and what its default value is.
   - Visible, Enabled by defaultStorage is visible in the widget and is enabled by default.
   - Visible & Readonly, Enabled by defaultStorage is visible in the widget, it is always enabled and cannot be disabled (usually used for Functionality storage).
   - Visible, Disabled by defaultStorage is visible in the widget and is disabled by default.
   - Hidden, SynchronizedStorage is not visible in the widget and the consent is synchronized with another storage.
   - Hidden, Disabled alwaysStorage is not visible in the widget and is always disabled. Use for storages that are not used by the application at all.
Synchronize consent withThe consent can be synchronized with another storage. The option is available only if the option Visibility and default state is set to Hidden, Synchronized.
If the storage is denied show the modal again after x daysThe settings modal will be opened again after the specified number of days if the storage is denied. The option is available only if the option Display in the widget is set to Visible, Enabled by default or Visible, Disabled by default.
Event trigger nameThe name of an event trigger that will be invoked on granted consent with storage. The name may not be unique for each storage (unique triggers are invoked only). No trigger is invoked if the option has an empty value.

As mentioned above, each storage can define a trigger that is invoked when consent with the storage has been granted. In some situations, you may want some trigger to be fired only if the user gives consent with multiple storage types. For example, if you have a trigger called fb_pixel_trigger and you want to fire it only if the user gives consent with the analytics_storage and the ad_stroage. Then your configuration may look like this:

Revision message translation

Translation settings

The package comes with the default translations for the following languages:

Translations that will be loaded and accessible for the widget are taken from the field Locales. Each locale must be defined on a new line. Alternatively, from version 1.0.0, the URL from which the translations are to be downloaded can also be entered.

Locale options

In the example above, the default translations for the English language are downloaded and the translations for the German language are downloaded from the URL https://www.example.com/public/cc-translations/de.json. A translation file must always be in JSON format and its name must match a locale.

If you want to rewrite default translations, or you want to add translations for a new locale then you can define them in a table Translations.

Locale detection

Locale detection can be affected with the following fields:

FieldDescription
Locale detection strategyBrowser to get user's browser language or Document to read a value from <html lang="..."> of the current page.
LocaleYou must define the website locale when the detection strategy is disabled. The locale must be one of the previously defined locales in the field Locales.

How to manage revisions

The default revision number is 0 and the number can be changed through the field Revision. When you change the value the consent modal will be displayed for all users again. You can define a message that will be displayed in the consent modal's description. If you want to do that define custom translation with the key consent_modal_revision_message and rewrite a translation with the key consent_modal_description. The plugin will replace the placeholder [[revision_message]] in the consent modal description with your revision message.

Revision message translation

Note: the cookieconsent plugin uses the placeholder {{revision_message}} but this notation is used by GTM for variables so the package comes with the placeholder [[revision_message]] instead.

Stylesheets

FieldDescription
Include default stylesheetsThe default stylesheet for the widget will be loaded into the page if the option is checked. We recommend keeping the option checked and adding custom stylesheets through the next options.
External stylesheetsThe list of custom CSS stylesheets. One URL per line.
Internal stylesheetCustom CSS rules that will be injected into the page after default stylesheets and other external stylesheets.

Page scripts

FieldDescription
Manage page scriptsEnable if you want to easily manage existing <script> tags.
Script selectorThe name of a data attribute that is used for managed

版本与发布记录

68publishers-cookie-consent 共发布 72 个版本,首次发布于 2021/12/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/06/212 年前
1.0.0-beta.4beta2024/06/192 年前
1.0.0-beta.32024/06/192 年前
1.0.0-beta.22024/06/192 年前
1.0.0-beta.12024/06/182 年前
1.0.0-beta.02024/06/182 年前

关于 68publishers-cookie-consent 的常见问题

68publishers-cookie-consent 是什么?

Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.注意:该包已被作者标记为弃用——The package has been moved to @68publishers/cookie-consent.

如何安装 68publishers-cookie-consent?

在项目目录运行 npm install 68publishers-cookie-consent,或使用 pnpm add / yarn add / bun add。

68publishers-cookie-consent 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/68publishers-cookie-consent 是否存在。

68publishers-cookie-consent 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

68publishers-cookie-consent 可以商用吗?

68publishers-cookie-consent 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

68publishers-cookie-consent 的下载量有多少?

根据 npm 官方下载统计,68publishers-cookie-consent 在 2026/10/04 – 2026/11/02 这 30 天内被下载 2,823 次,日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

68publishers-cookie-consent 还在维护吗?

最新版本 1.0.0 发布于 2024/06/21(2 年前);至今共发布 72 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/12/09。作者已将其标记为弃用,新项目建议寻找替代方案。