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

		/** @var ResultEntity $resultEntity*/
		private $resultEntity;

		/**@var Form $form */
		private $form;

		/**
		 * FacebookCrmWebFormEventBuilder constructor.
		 *
		 * @param ResultEntity $resultEntity
		 */
		public function __construct(ResultEntity $resultEntity)
		{
			($this->form = new Form())->loadOnlyForm($resultEntity->getFormId());
			$this->resultEntity = $resultEntity;
		}

		/**
		 * @return array
		 */
		public function getUserData() : array
		{
			$userData = [];
			if (!empty($this->form->get()))
			{
				if (empty($userData) && $id = $this->resultEntity->getEntityIdByTypeName(\CCrmOwnerType::ContactName))
				{
					if (!empty($data = $this->getContactUserData($id)))
					{
						$userData[] = $data;
					}
				}

				if (empty($userData) && $id = $this->resultEntity->getEntityIdByTypeName(\CCrmOwnerType::CompanyName))
				{
					if (!empty($data = $this->getCompanyUserData($id)))
					{
						$userData[] = $data;
					}
				}

				if (empty($userData) && $id = $this->resultEntity->getEntityIdByTypeName(\CCrmOwnerType::LeadName))
				{
					if ($lead = $this->getLead($id))
					{
						$userData = array_merge_recursive($userData,$this->getLeadUserData($lead));
					}
				}

				if (empty($userData) && $id = $this->resultEntity->getEntityIdByTypeName(\CCrmOwnerType::DealName))
				{
					if ($deal = $this->getDeal($id))
					{
						$userData = array_merge_recursive($userData,$this->getDealUserData($deal));
					}
				}
			}

			return $userData;
		}

		/**
		 * @param $entity
		 *
		 * @return array|null
		 */
		public function getEventParams($entity): ?array
		{
			return [
				'event_name' => Facebook\Event::EVENT_COMPLETE_REGISTRATION,
				'action_source' => Facebook\Event::ACTION_SOURCE_SYSTEM_GENERATED,
				'user_data' => $entity,
				'event_source_url' => $this->form->getLandingUrl(),
				'custom_data' => [
					'content_name' => $this->form->get()['NAME'],
				],
			];
		}
	};
}