<?php
declare(strict_types=1);
namespace App\Twig\Components;
use App\Service\Container\ContactInfoProvider;
use Symfony\Component\Security\Core\Security;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent('YandexMetrika')]
class YandexMetrika
{
public function __construct(
private readonly Security $security,
private readonly ContactInfoProvider $contactInfoProvider,
)
{
}
/**
* Получить необходимый для конкретного места ID счетчика Яндекс Метрики
*/
public function getNeededHereCounterId(): string
{
// На публичных страницах один счетчик, на внутренних другой
return !$this->security->getUser()
? (string)$this->contactInfoProvider->getInfo()->getYmPublicCounterId()
: (string)$this->contactInfoProvider->getInfo()->getYmCounterId();
}
}