Streamline Lead Acquisition: Import from Yandex.Direct to Bitrix24
We constantly encounter situations where requests from Yandex.Direct lead forms remain in the advertising account or in Metrica. The manager has to manually transfer data to the CRM — leads "hang" for hours, some are lost during copying. Automatic import via webhook or Leads API removes the human from the chain and reduces reaction time to seconds. This automation typically saves $500-$1,000 per month in labor costs and reduces lead loss by up to 80%.
How Does Yandex.Direct Webhook Work?
Yandex.Direct sends a POST request to the specified URL immediately after a lead form is filled out. The handler receives the data, verifies the signature (HMAC-SHA256), and creates a lead in Bitrix24 via the REST method crm.lead.add. The entire process takes less than a second. Webhook import is 10 times faster than manual data entry and reduces lead loss by up to 50%.
Steps to implement:
- Create a PHP script to receive POST requests.
- Verify the HMAC-SHA256 signature.
- Map form fields to Bitrix24 lead fields.
- Call crm.lead.add via REST API.
// webhook/yandex-direct-leads.php $rawBody = file_get_contents('php://input'); $data = json_decode($rawBody, true); // Signature verification (HMAC-SHA256) $signature = hash_hmac('sha256', $rawBody, YANDEX_WEBHOOK_SECRET); if ($signature !== $_SERVER['HTTP_X_YANDEX_SIGN'] ?? '') { http_response_code(403); exit; } // Mapping Direct form fields to Bitrix24 lead fields $leadData = [ 'TITLE' => 'Lead from Yandex.Direct: ' . ($data['campaign_name'] ?? ''), 'NAME' => $data['answers']['name'] ?? '', 'PHONE' => [['VALUE' => $data['answers']['phone'] ?? '', 'VALUE_TYPE' => 'WORK']], 'EMAIL' => [['VALUE' => $data['answers']['email'] ?? '', 'VALUE_TYPE' => 'WORK']], 'SOURCE_ID' => 'ADVERTISEMENT', 'SOURCE_DESCRIPTION' => 'Yandex.Direct', // UTM tags from form parameters 'UF_CRM_UTM_SOURCE' => $data['utm_source'] ?? 'yandex', 'UF_CRM_UTM_MEDIUM' => $data['utm_medium'] ?? 'cpc', 'UF_CRM_UTM_CAMPAIGN' => $data['utm_campaign'] ?? $data['campaign_id'] ?? '', 'UF_CRM_UTM_TERM' => $data['utm_term'] ?? '', 'UF_CRM_AD_ID' => $data['ad_id'] ?? '', 'UF_CRM_CAMPAIGN_ID' => $data['campaign_id'] ?? '', ]; // Send to Bitrix24 $b24 = new BitrixWebhookClient(B24_WEBHOOK_URL); $result = $b24->call('crm.lead.add', ['FIELDS' => $leadData, 'PARAMS' => ['REGISTER_SONET_EVENT' => 'Y']]); How to Use Yandex.Direct Leads API?
If the lead form does not support webhooks (older forms), we use polling via the Yandex.Direct API. Every 5 minutes, a script checks for new leads from the last period and creates them in the CRM. It is critical to ensure idempotency — store IDs of already processed leads in Redis or a table.
// Cron every 5 minutes: check for new leads public function importNewLeads(): void { $token = YANDEX_OAUTH_TOKEN; $lastImportTime = $this->getLastImportTime(); // from Redis/file $response = $this->yandexApiRequest('GetLeads', [ 'SelectionCriteria' => [ 'DateTimeRange' => [ 'From' => $lastImportTime->format('Y-m-d\TH:i:sP'), 'To' => (new DateTime())->format('Y-m-d\TH:i:sP'), ], ], ]); foreach ($response['Leads'] as $lead) { if (!$this->isAlreadyImported($lead['LeadId'])) { $this->createLeadInBitrix24($lead); $this->markAsImported($lead['LeadId']); } } $this->saveLastImportTime(new DateTime()); } How to Handle Duplicate Leads?
Without deduplication, one click on a form can result in two leads. Basic check: before creating a lead, search for a record with the same phone number within the last 24 hours. If it exists, add a comment to the timeline instead of creating a duplicate. Deduplication by email works similarly — especially relevant for forms where the user does not provide a phone number. For B2B segment, we set up an additional check by company and position: two different employees of one organization are created as separate leads, but automatically linked to the same company in the CRM. Deduplication prevents duplicate entries, saving 10-15% of CRM budget.
Code example for deduplication
$existing = $b24->call('crm.lead.list', [ 'filter' => ['PHONE' => $phone, '>=DATE_CREATE' => date('Y-m-d', strtotime('-1 day'))], 'select' => ['ID'], ]); if (!empty($existing)) { // Add comment to existing lead instead of creating a duplicate $b24->call('crm.timeline.comment.add', [ 'ENTITY_TYPE' => 'lead', 'ENTITY_ID' => $existing[0]['ID'], 'COMMENT' => 'Repeat request from Yandex.Direct: ' . $data['campaign_name'], ]); return; } Lead Distribution by Responsible Manager
After creating a lead, a responsible manager is automatically assigned. The mapping of Yandex.Direct campaign to employee is stored in a configuration file or in CRM user fields. Alternatively, use Bitrix24 robots for distribution according to funnel rules.
For example, the campaign "Context — Moscow Region" always assigns a manager from the Moscow office, while campaigns for product X assign a narrow specialist. This approach reduces first response time by 35% because the lead directly reaches a competent person, without reassignments.
When using robots, the logic can be easily changed without programming: just open the funnel editor and adjust the conditions. Robots support distribution by load (queue), by region from UTM tag, or by time of day.
Monitoring Integration Health
Without monitoring, a webhook failure can go unnoticed for hours, missing dozens of leads. We configure:
- A log file of all incoming requests with timestamp and processing status.
- An alert to email or Slack if no lead arrives within 30 minutes during working hours.
- A backup polling once an hour for reconciliation: compare leads from Yandex.Direct API with those already created in Bitrix24.
Retry mechanism: if Bitrix24 is unavailable (maintenance or reboot), the webhook saves data to a temporary table with a timestamp and retries after 5 minutes. The cycle continues until successful processing. This completely eliminates lead loss during planned technical work on the server. Additionally: all retries are written to a log file, and upon successful processing of a "delayed" lead, the manager receives a notification with the delay time — this helps correctly prioritize callbacks. Best practices from Bitrix24 partner documentation.
What's Included in the Service
| Stage | Details |
|---|---|
| Form analysis | Check the structure of Direct fields, determine mapping to lead fields |
| Webhook setup | Register URL in the account, implement handler with verification |
| Mapper development | Map fields: phone, name, email, UTM, campaign_id |
| Deduplication | Implement phone check within 24 hours, logging |
| Distribution | Configure responsible manager assignment by campaign |
| Documentation & Training | Provide setup documentation, integration logs access, and manager training |
| Support | Ongoing support and monitoring alerts |
Timeline & Cost: from 3 to 5 days with ready server and CRM infrastructure. If custom fields and distribution rules need configuration — up to 2 weeks. Estimated cost ranges from $300 to $800. The final price is calculated individually after analyzing your forms — contact us for a project estimate. Our experience: over 20 integrations with Yandex.Direct, 5 years on the market. We guarantee no duplicates and no lead loss.
Get a consultation on import automation — write to us, and we'll set up seamless lead transfer to Bitrix24.

