mariojgt/biscotto

Biscotto 是一个 Laravel 扩展包,可以帮助您启用和禁用需要符合 GDPR 规定的 cookies 或脚本。

安装次数: 73

依赖项: 1

建议者: 0

安全性: 0

星级: 2

关注者: 1

分支: 1

开放问题: 0

语言:Blade

类型:laravel

1.1.1 2022-04-25 13:22 UTC

This package is auto-updated.

Last update: 2024-09-06 16:27:13 UTC


README

image info

Biscotto,Laravel 的 GDPR Cookie 管理器

ko-fi

安装

  • composer require mariojgt/biscotto
  • php artisan v:p --force

特性

  • 禁用 Cookie 列表
  • 脚本和 iframes 或具有 src 的任何内容都可以使用此包禁用
  • 所有定义都使用配置变量
  • 轻量级的纯 vanilla JavaScript

如何使用?

注意,在此示例中,您需要首先加载您的 Analytics,而不是使用 src,而是添加 data-src,这将防止您的脚本在下一步后调用 google。现在,在 cookie 包中,可以通过在 biscotto.php 配置文件中更改这些 id 来启用或禁用它们。

示例 1

<x-biscotto::biscotto>
<!-- Global site tag (gtag.js) - Google Analytics -->
 <script async
  id="script_cookie_statstics" // The id that comes from the config file
  data-src="https://#/gtag/js?id=UA-152696431-2"
 ></script>
  <script>
     window.dataLayer = window.dataLayer || [];
     function gtag(){dataLayer.push(arguments);}
     gtag('js', new Date());
     gtag('config', 'UA-152696431-2');
 </script>
</x-biscotto::biscotto>

示例 2

<x-biscotto::biscotto>
</x-biscotto::biscotto>

// Iframe example Note the dara-src and the id they are required
<iframe width="560" height="315" id="script_cookie_functional" data-src="https://www.youtube.com/embed/zckH4xalOns" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

脚本信息

请注意,脚本和 iframes 不需要放在 x-biscotto::biscotto 组件内部,您可以在网站的任何位置添加它们,因为我们可以使用 DOM。如果您有正确的标签,它将找到并启用脚本,同样适用于 iframe 示例,注意 data-src 和 id。

<iframe width="560" height="315" id="script_cookie_statstics" data-src="https://www.youtube.com/embed/zckH4xalOns" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

如何禁用不想要的 cookies

没有方法可以使此过程自动化且有效,但您可以在配置变量中启用调试模式。启用后,它将在您的控制台中显示所有网站 cookies,然后根据您更改的 biscotto.php 配置文件添加您希望禁用的 cookie。如果客户禁用选项,请参阅示例。

    /*
    |--------------------------------------------------------------------------
    | Cookie you wish to remove if the user don't allow them
    |--------------------------------------------------------------------------
    |
    | If you know the cookies name you wish to remove
    | Once the user don't allow, if you don't know the cookie you can setup
    | The varaible test mode to true it will show all the cookie inf you browser
    |
    */
    // Example
    'cookie_functional' => [
		'example','another'
    ],
    'cookie_statstics' => [
        '_ga','_gid','_gat_gtag_UA_124396431_2'
    ],
    'cookie_marketing' => [
		'example','another'
    ],

自定义消息

您还可以在配置文件中自定义 cookie 弹出窗口的消息和链接。

注意

关于如何显示警告、必要的文本以及需要提供哪些选项的立法相当模糊。此包将大大有助于合规,但如果您想确保您的网站完全没问题,您应咨询法律专家。