PHP code example of netipar / laravel-consent

1. Go to this page and download the library: Download netipar/laravel-consent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

netipar / laravel-consent example snippets


// HandleInertiaRequests::share()
'consent' => fn () => \NETipar\Consent\Facades\Consent::clientConfig(),

'analytics' => [
    'a', '_ga_*', '_gid', '_gat_*', '_dc_gtm_*'],
],
'marketing' => [
    'cl_au', '_gcl_aw', '_gcl_*', '_gac_*'],
],

use NETipar\Consent\Facades\Consent;

$consentId = Consent::consentId();       // the id cookie of the current request, or null
$events = Consent::history($consentId);  // Collection<int, ConsentLog>, oldest first

use Illuminate\Support\Facades\Schedule;
use NETipar\Consent\Models\ConsentLog;

Schedule::command('model:prune', ['--model' => [ConsentLog::class]])->daily();

'analytics' => [
    '      [
            'name' => '_ga',
            'provider' => 'Google Analytics',
            'purpose' => ['en' => 'Distinguishes visitors', 'hu' => 'Látogatók megkülönböztetése'],
            'lifetime' => 'P2Y',
        ],
        '_ga_*',   // purged on revocation, not listed
    ],
],

use NETipar\Consent\Facades\Consent;

Consent::allows('analytics');   // bool — false until a valid decision exists; ;         // bool — a decision for the current config version exists
Consent::decision();            // ConsentDecision { granted, version }
Consent::categories();          // list<Category> — key, 

'google' => [
    'tags' => [
        ['id' => 'G-XXXXXXX', 'category' => 'analytics'],
        ['id' => 'AW-XXXXXXXXX', 'category' => 'marketing'],
    ],
    // 'signals', 'ads_data_redaction', 'url_passthrough': see the configuration reference
],

use NETipar\Consent\Facades\Consent;
use NETipar\OfficeLeads\Facades\OfficeLeads;

OfficeLeads::resolveAttributionConsentUsing(fn ($request) => Consent::allows('marketing', $request));

$this->withHeader('Cookie', '__cookie_consent=necessary%2Cmarketing; __cookie_consent_v=1')
    ->get('/')
    ->assertSee('marketing-only widget');
dotenv
CONSENT_LOG_ENABLED=true
bash
php artisan vendor:publish --tag=consent-lang   # → lang/vendor/consent/{locale}/consent.php