PHP code example of albertborsos / yii2-gdpr-cookie-consent

1. Go to this page and download the library: Download albertborsos/yii2-gdpr-cookie-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/ */

    

albertborsos / yii2-gdpr-cookie-consent example snippets



return [
    // ...
    'components' => [
        // ...
        'cookieConsent' => [
            'class' => \albertborsos\cookieconsent\Component::class,
            'urlSettings' => ['/site/cookie-settings'],
            'urlPrivacyPolicy' => ['/site/privacy-policy'],
            'documents' => [
                ['name' => 'Privacy Policy', 'url' => ['/docs/privacy-policy.pdf']],
            ],
            'disabledCategories' => [
                \albertborsos\cookieconsent\helpers\CookieHelper::CATEGORY_BEHAVIOR,
            ],
        ],
        // ...
        'i18n' => [
            // ...
            'translations' => [
                'cookieconsent/*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@vendor/albertborsos/yii2-gdpr-cookie-consent/src/messages',
                ],
            ],
            // ...
        ],
    ],
    // ...
];


/** @var \albertborsos\cookieconsent\Component $component */
$component = Yii::$app->cookieConsent;
$component->registerWidget([
    'policyLink' => ['/default/cookie-settings'],
    'policyLinkText' => \yii\helpers\Html::tag('i', null, ['class' => 'fa fa-cog']) . ' Beállítások',
    'pluginOptions' => [
        'expiryDays' => 365,
        'hasTransition' => false,
        'revokeBtn' => '<div class="cc-revoke {{classes}}">Cookie Policy</div>',
    ],
]);




namespace app\controllers;

class SiteController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            'cookie-settings' => \albertborsos\cookieconsent\actions\CookieSettingsAction::class,
            'privacy-policy' => \albertborsos\cookieconsent\actions\PrivacyPolicyAction::class,
        ];
    }
}




use \albertborsos\cookieconsent\helpers\CookieHelper;
use \albertborsos\cookieconsent\Component;

if(CookieHelper::isAllowedType(CookieHelper::TYPE_GOOGLE_ANALYTICS)){
    // register GA script
}

if(CookieHelper::isAllowedCategory(CookieHelper::CATEGORY_BEHAVIOR)){
    // register hotjar script
}