定制 kostantinoabate/complihance 二次开发

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

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

kostantinoabate/complihance

Composer 安装命令:

composer require kostantinoabate/complihance

包简介

Laravel package for cookie consent, policies and consent tracking

README 文档

README

Latest Version on Packagist Total Downloads GitHub Tests Action Status GitHub Code Style Action Status License

A Laravel package for cookie consent, policy acceptance, consent persistence, Google Consent Mode, cookie scanning and blocked embedded content.

FULL DOCUMENTATION WILL BE AVAILABLE SOON!

✅ Ready-to-use cookie banner
✅ Consent preferences page
✅ Granular vendor consent
✅ Google Consent Mode support
✅ Consent audit log and retention
✅ Cookie, storage and script scanner

Installation

Install the package via Composer:

composer require kostantinoabate/complihance

Run the install command:

php artisan complihance:install

Run the migrations:

php artisan migrate

Publish editable data files:

php artisan vendor:publish --tag=complihance-data

Setup

Add the Complihance scripts to your main layout, preferably inside the <head>:

@complihanceConsentMode
@complihanceScript

Render the default banner before the closing </body> tag:

@complihanceBanner

Example:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta name="csrf-token" content="{{ csrf_token() }}">

    @complihanceConsentMode
    @complihanceScript
</head>
<body>
    {{-- Your application --}}

    @complihanceBanner
</body>
</html>

Preferences page

To let users update or revoke their consent, render the preferences component in any Blade view:

@complihancePreferences

Cookie policy table

Render a cookie/technology table:

@complihanceCookieTable

Render only one category:

@complihanceCookieTable('analytics')

Configuration

The config file is published to:

config/complihance.php

Main options:

'cookie_name' => 'complihance_consent',

'cookie_lifetime' => 60 * 24 * 365,

'cookie_policy_url' => '/cookie-policy',

'banner' => [
    'enabled' => true,
],

'cookie_configuration_version' => '1.0.0',

'granular_consent' => [
    'enabled' => false,
],

'consent_mode' => [
    'enabled' => true,
],

When your cookie configuration changes, increment:

'cookie_configuration_version' => '1.0.1',

Users will be asked to renew their consent.

Data files

Editable data files can be published with:

php artisan vendor:publish --tag=complihance-data

Published files:

resources/vendor/complihance/categories.json
resources/vendor/complihance/technologies.json
resources/vendor/complihance/texts.json

Consent categories

Default categories are:

  • necessary
  • analytics
  • marketing
  • functional

Example category:

{
    "analytics": {
        "required": false,
        "enabled": true,
        "consent_mode": [
            "analytics_storage"
        ],
        "translations": {
            "en": {
                "label": "Analytics and performance cookies",
                "description": "These cookies allow the collection of information about user behavior."
            }
        }
    }
}

Technologies and vendors

Technologies are configured in technologies.json.

Example:

{
    "_ga": {
        "category": "analytics",
        "vendor": "Google Analytics",
        "pattern": "^_ga($|_)",
        "translations": {
            "en": {
                "name": "_ga",
                "description": "Used to distinguish users.",
                "duration": "2 years"
            }
        }
    }
}

Enable vendor-level consent:

'granular_consent' => [
    'enabled' => true,
],

Google Consent Mode

Google Consent Mode is enabled by default.

'consent_mode' => [
    'enabled' => true,
],

Complihance renders the default consent state through:

@complihanceConsentMode

Consent Mode values are updated automatically when the user saves or changes preferences.

Blocking embedded content

Complihance can prevent embedded content from loading before consent is granted.

Example:

<iframe
    {!! app(\KostantinoAbate\Complihance\Services\Cookies\BlockedContent\BlockedContentAttributes::class)
        ->render(category: 'marketing', src: 'https://www.youtube.com/embed/example') !!}
    width="560"
    height="315"
></iframe>

Or with the Blade directive:

<iframe
    @complihanceBlockedContent('marketing', 'https://www.youtube.com/embed/example', 'youtube')
    width="560"
    height="315"
></iframe>

Frontend API

Complihance exposes a frontend API on window.Complihance.

window.Complihance.hasConsent();
window.Complihance.requiresRenewal();

window.Complihance.canUse('analytics');
window.Complihance.canUseVendor('google_analytics');

window.Complihance.acceptAll();
window.Complihance.rejectAll();
window.Complihance.revoke();

window.Complihance.onConsentChanged((consent) => {
    // Initialize services after consent changes.
});

HTTP API

Default API prefix:

/complihance/api

Available endpoints:

GET    /complihance/api/consent
POST   /complihance/api/consent
PATCH  /complihance/api/consent
DELETE /complihance/api/consent
GET    /complihance/api/consent/status
GET    /complihance/api/configuration

Example payload:

{
    "source": "api",
    "categories": ["necessary", "analytics"],
    "vendors": ["google_analytics"]
}

Artisan commands

Export collected consents:

php artisan complihance:export-consents

Export consents for a date range:

php artisan complihance:export-consents --from=2026-01-01 --to=2026-12-31

Apply retention rules:

php artisan complihance:retention

Preview retention without changing data:

php artisan complihance:retention --dry-run

Scan cookies, storage and scripts:

php artisan complihance:scan-cookies https://example.com

Scan only HTTP Set-Cookie headers:

php artisan complihance:scan-cookies https://example.com --http-header-only

Scan a sitemap:

php artisan complihance:scan-cookies https://example.com/sitemap.xml --sitemap

Export a scan report:

php artisan complihance:scan-cookies https://example.com --report=json

Compare two scans:

php artisan complihance:scan-diff <from-scan-id-or-uuid> <to-scan-id-or-uuid>

Reset local Complihance data:

php artisan complihance:reset --force

Cookie scanner requirements

Browser-based scanning requires Playwright and Chromium:

npm install -D playwright
npx playwright install chromium

In Docker/Linux environments, Chromium system dependencies may also be required.

Alternatively, use the HTTP-only scanner:

php artisan complihance:scan-cookies https://example.com --http-header-only

Testing

Run the test suite:

composer test

License

The MIT License (MIT). See LICENSE.md for more information.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固