Setting Up Ad Spend Connection with Bitrix24 CRM
You're running ads, leads are coming in, but the profitability of each channel is a black box. You spent 500,000 rubles on Yandex.Direct — how much of that came back? Without linking ad spend to your CRM, you won't get the answer. Manually collecting data from three to five ad dashboards and merging it with CRM reports takes up to 10 hours a month and inevitably introduces errors. We solve this with UTM attribution and automatic data import from ad systems. The setup requires working with Yandex, Google, VK APIs, and Bitrix24's REST methods. Our engineers hold 1C-Bitrix certifications and have 7+ years of experience with such integrations. We guarantee data accuracy and transparency for every ruble.
How to Set Up Ad Attribution?
The link "ad → lead → deal → money" is built on UTM tags. Each ad is tagged with UTM parameters that end up in Bitrix24 when a lead is created. After a deal is closed, the revenue from that deal is attributed to the campaign. An automated connection gives 100% accuracy in accounting and requires no manual intervention.
utm_source=yandex&utm_medium=cpc&utm_campaign=brand&utm_term=купить → Lead (UF_CRM_UTM_*) → Deal → Amount + Costs from Yandex Direct API = ROI Manually calculating ROI costs tens of man-hours per month and introduces errors. Automation reduces the time by 12 times and completely eliminates human error.
Structure of Custom Fields
Deals in Bitrix24 need fields to store UTM data:
| Field | Code | Type |
|---|---|---|
| Source | UF_CRM_UTM_SOURCE | string |
| Campaign | UF_CRM_UTM_CAMPAIGN | string |
| Campaign ID | UF_CRM_CAMPAIGN_ID | string |
| Medium | UF_CRM_UTM_MEDIUM | string |
| Keyword | UF_CRM_UTM_TERM | string |
| Ad ID | UF_CRM_AD_ID | string |
Fields are created via crm.userfield.add or in the Bitrix24 interface. When a lead is created from any ad channel (Direct, VK, FB), UTM tags are saved to these fields. When converting a lead to a deal, the fields are copied (configured via Sources in B24 or via REST). Source: Bitrix24 custom fields documentation.
Why Daily Cost Import Is Critical?
Without daily import, you work with outdated data, and ROI is calculated with a delay of up to a week. Our cron script loads the previous day's costs from each ad system into an aggregation table. Automated import is 12 times faster than manual collection and gives you an up-to-date picture every morning.
Example import code from Yandex.Direct
// Yandex.Direct: campaign costs per day public function importDirectCosts(string $date): void { $report = $this->directApi->getReport([ 'ReportType' => 'CAMPAIGN_PERFORMANCE_REPORT', 'DateRangeType' => 'CUSTOM_DATE', 'DateFrom' => $date, 'DateTo' => $date, 'FieldNames' => ['CampaignId', 'CampaignName', 'Cost', 'Clicks', 'Impressions'], ]); foreach ($report as $row) { AdCostTable::add([ 'DATE' => $date, 'SOURCE' => 'yandex', 'CAMPAIGN_ID' => $row['CampaignId'], 'CAMPAIGN' => $row['CampaignName'], 'COST' => $row['Cost'] / 1000000, // Direct returns in microrubles 'CLICKS' => $row['Clicks'], ]); } } Similarly for VK Ads (ads.getStatistics) and Google Ads (Google Ads API, CampaignService). The import works stably, data is always up-to-date.
What Data Is Needed for ROI Calculation?
For accurate calculation, you need three components: costs from ad dashboards, revenue from closed deals in CRM, and correct linking via UTM tags. Comparison of manual vs automated approach:
| Parameter | Manual Collection | Automation |
|---|---|---|
| Time to reconcile data per month | up to 10 hours | 0 hours |
| Attribution accuracy | ±15% due to errors | 100% |
| Update frequency | Once a month | Daily |
| Ability to make operational decisions | No | Yes |
ROI Report in Bitrix24
The final report is built with a query that combines costs and revenue:
SELECT d.UF_CRM_UTM_SOURCE as source, d.UF_CRM_CAMPAIGN_ID as campaign_id, SUM(ac.COST) as ad_spend, COUNT(DISTINCT d.ID) as deals_count, SUM(d.OPPORTUNITY) as revenue, ROUND((SUM(d.OPPORTUNITY) - SUM(ac.COST)) / NULLIF(SUM(ac.COST), 0) * 100, 1) as roi_pct FROM b_crm_deal d LEFT JOIN local_ad_costs ac ON ac.CAMPAIGN_ID = d.UF_CRM_CAMPAIGN_ID AND ac.SOURCE = d.UF_CRM_UTM_SOURCE AND DATE(ac.DATE) = DATE(d.DATE_CREATE) WHERE d.STAGE_ID = 'WON' AND d.DATE_CLOSE BETWEEN :date_from AND :date_to GROUP BY d.UF_CRM_UTM_SOURCE, d.UF_CRM_CAMPAIGN_ID ORDER BY roi_pct DESC The report is displayed in the Bitrix24 administrative section or in an integrated BI tool (Yandex DataLens, Google Looker Studio). Thanks to automation, the ROI of each channel becomes visible in real time.
Common Mistakes When Setting Up Attribution
| Mistake | Consequence | Solution |
|---|---|---|
| Incorrect UTM parameter structure | Leads not tied to campaigns | Implement a unified tag template |
| Missing field for campaign ID | Inability to match costs | Add UF_CRM_CAMPAIGN_ID |
| Importing costs without including VAT | Inflated ROI | Configure correct cost calculation |
| Infrequent data updates | Making wrong decisions | Set up daily cron |
Transferring Costs Back to Yandex.Metrica
To display ROI directly in Metrica, you can upload costs via counter.uploadOfflineConversions (deprecated) or through Data2 API. If you have end-to-end analytics via Metrica, you can connect using "Import cost data" from a CSV file generated by Bitrix.
What Is Included in the Work
- Create custom fields in Bitrix24 deals
- Configure UTM transmission when creating leads (all channels)
- Develop cost importers: Direct, VK Ads, FB/Instagram
- Aggregation table
local_ad_costs - ROI report by campaign with filters for period and channel
- Configure cron schedule for import
- Documentation for deployment and support
- Train managers to work with reports
Work Process
- Analysis: we study your ad dashboards, UTM scheme, and CRM structure.
- Design: we determine custom fields, tables, and import logic.
- Implementation: we write integration code, configure cron, and debug on test data.
- Testing: we verify attribution correctness on real deals.
- Deployment: we deploy to production and hand over documentation.
Estimated Timelines
- Basic setup (Direct + one channel) — 1–2 weeks.
- Multi-channel ROI report with BI dashboard — 3–4 weeks. Cost is calculated individually after an audit.
Request an audit of your ad channels — we'll find attribution losses. Get in touch for a free consultation on setting up end-to-end analytics. Our certified engineers guarantee transparency and post-deployment support.

