gridonic/statamic-consent-manager

此软件包最新版本(v1.1.0)没有提供许可证信息。

Statamic 3 插件,用于管理 cookie 的同意。

v1.1.0 2023-06-26 09:45 UTC

This package is not auto-updated.

Last update: 2024-09-16 15:20:29 UTC


README

Statamic 3 插件,用于管理 cookie 的同意 🍪。

功能

  • 定义同意组 只有在给予组同意时才动态加载的脚本。
  • 提供简单的 JavaScript API,用于读取和更改用户的同意。
  • 同意仅在客户端存储,使得使用静态缓存成为可能。

安装

运行以下命令

composer require gridonic/statamic-consent-manager
php artisan vendor:publish --tag=statamic-consent-manager-config

配置

编辑位于 config/statamic/consent_manager.php 的配置文件。

<?php

return [
    // Where to store the consent settings of any user (javascript).
    // Choose "local" for local storage or "session" for session storage.
    'storage' => 'local',

    // Consent groups managed by the addon. Feel free to change, remove or add your own groups.
    // Scripts are dynamically added to the DOM only if consent for their group is given.
    'groups' => [
        'necessary' => [
            'required' => true,
            'consented' => true,
            'scripts' => [
                [
                    // The full script tag to include in the page if consent is given.
                    'tag' => '<script>console.log(\'script dynamically loaded with consent manager\');</script>',
                    // Choose "head" or "body" to append the script to the page.
                    'appendTo' => 'head',
                ],
            ],
        ],
        'marketing' => [
            'required' => false,
            'consented' => false,
            'scripts' => [],
        ],
        'statistics' => [
            'required' => false,
            'consented' => false,
            'scripts' => [],
        ]
    ],
];

用法

  1. 在配置中定义您的同意组和它们的脚本。
  2. {{ consent_manager }} 标签添加到布局的 head 部分。

这就完成了!🥳 剩下的工作是由你来设计一个漂亮的 cookie 横幅并使用 JavaScript API 修改同意数据。

渲染 cookie 横幅

此插件提供了 {{ consent_manager:groups }} 标签,可以在 Antlers 中循环遍历同意组。

{{ consent_manager:groups }}
    Group ID: {{ id }}
    Consented by default: {{ consented }}
    Required: {{ required }}  
{{ /consent_manager:groups }}

ℹ️ 读取或修改同意,您需要使用 JavaScript API,因为数据仅存储在客户端。

JavaScript API

此插件公开了一个 window.consentManager 对象,用于读取和写入同意数据。