• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/sender/utm.php
  • Класс: Bitrix\Crm\Integration\Sender\Utm
  • Вызов: Utm::getStatByUtmSources
static function getStatByUtmSources(array $utmSources, Main\Type\Date $from, Main\Type\Date $to)
{
	$row = Sender\Internals\Model\Posting\RecipientTable::query()
		->addSelect(new Main\ORM\Fields\ExpressionField(
			'CNT_READ',
			'COUNT(%s)',
			['IS_READ']
		))
		->addSelect(new Main\ORM\Fields\ExpressionField(
			'CNT_CLICK',
			'SUM(CASE WHEN %s = "Y" THEN 1 ELSE 0 END)',
			['IS_CLICK']
		))
		->where('POSTING.LETTER.MESSAGE.UTM.CODE', 'utm_source')
		->whereIn('POSTING.LETTER.MESSAGE.UTM.VALUE', $utmSources)
		->where('STATUS', Sender\Internals\Model\Posting\RecipientTable::SEND_RESULT_SUCCESS)
		->where('DATE_SENT', '>=', $from)
		->where('DATE_SENT', '<=', $to)
		->where('IS_READ', 'Y')
		->fetch()
	;

	return [
		'read' => $row['CNT_READ'] ?? 0,
		'click' => $row['CNT_CLICK'] ?? 0,
	];
}