• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/ads/pixel/conversioneventtriggers/leadtrigger.php
  • Класс: Bitrix\Crm\Ads\Pixel\ConversionEventTriggers\LeadTrigger
  • Вызов: LeadTrigger::getConversionEventBuilder
protected function getConversionEventBuilder(): CrmConversionEventBuilderInterface
{
	return new class($this->leadId) extends AbstractFacebookBuilder implements CrmConversionEventBuilderInterface {

		/**@var  array|null */
		protected $lead;

		/**
		 * FacebookCrmLeadEventBuilder constructor.
		 *
		 * @param int $dealId
		 */
		public function __construct(int $dealId)
		{
			$this->lead = $this->getLead($dealId);
		}

		protected function resolveEventName(): string
		{
			$entityName = $this->getEntityName();
			$stageName = Factory
				::createTarget(CCrmOwnerType::Lead)
				->getStatusInfos()[$this->lead['STATUS_ID']]['NAME'];

			return $entityName.'. '.$stageName;
		}

		protected function getEntityName(): string
		{
			if (array_key_exists($key = CCrmOwnerType::Lead,
				$typeDescriptions = CCrmOwnerType::GetAllDescriptions()))
			{
				return $typeDescriptions[$key];
			}

			return '';
		}

		/**
		 * @param $entity
		 *
		 * @return array|null
		 */
		public function getEventParams($entity): ?array
		{
			return [
				'event_name' => $this->resolveEventName(),
				'action_source' => Facebook\Event::ACTION_SOURCE_SYSTEM_GENERATED,
				'user_data' => $entity,
				'custom_data' => [
					'value' => (float)($this->lead['OPPORTUNITY'] ?? 0),
					'currency' => $this->lead['CURRENCY_ID'],
				],
			];
		}

		/**
		 * @return array
		 */
		public function getUserData(): array
		{
			return $this->getLeadUserData($this->lead);
		}
	};
}