Integrating Yandex.Metrica Enhanced Ecommerce with 1C-Bitrix

Integrating Yandex.Metrica Enhanced Ecommerce with 1C-Bitrix We often encounter a situation where an online store owner on 1C-Bitrix assumes that simply installing a Metrica counter is enough—and sales data already appears in reports. In reality, without Enhanced Ecommerce event transmission, ana

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1415
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    995
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    733
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    863
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    772
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    1134

Integrating Yandex.Metrica Enhanced Ecommerce with 1C-Bitrix

We often encounter a situation where an online store owner on 1C-Bitrix assumes that simply installing a Metrica counter is enough—and sales data already appears in reports. In reality, without Enhanced Ecommerce event transmission, analytics are limited to counting visits and clicks. Our task is to set up a full funnel: from product view to payment, with breakdowns by product, brand, and category. Enhanced Ecommerce is 3 times more accurate than the standard goal-based scheme because it transmits detailed data for each product. Let's look at implementing dataLayer events, debugging, and guaranteed server-side transaction sending.

How Enhanced Ecommerce Works

Yandex.Metrica receives transaction data through the dataLayer object—a JavaScript array into which the page pushes events. The Metrica counter reads events of a specific structure and sends them to Yandex servers. The main events: detail (product view), add (add to cart), remove (remove from cart), purchase (completed purchase). Each event contains an ecommerce object with a products array. A product is described by fields: id, name, price, brand, category, quantity, variant.

How to Implement dataLayer in 1C-Bitrix?

There is no built-in Enhanced Ecommerce integration in Bitrix—the sale module only sends the basic counter code. Implementation falls on the developer.

detail event — added to the catalog.element component template. In result_modifier.php or template.php, form the product array and push it to dataLayer:

window.dataLayer = window.dataLayer || []; window.dataLayer.push({ "ecommerce": { "detail": { "products": [{ "id": "SKU-1234", "name": "Product Name", "price": 2500, "brand": "Brand", "category": "Section/Subsection" }] } } }); 

add event — fires when the "Add to Cart" button is clicked. In Bitrix, adding to cart typically goes via an AJAX request to sale.basket.basket. You need to intercept the successful response and push the event. The most reliable way is to subscribe to the custom JS event BX.onCustomEvent('OnBasketChange') or wrap the standard handler.

remove event — similar to add, fires when an item is removed from the cart. It is intercepted via the same OnBasketChange with analysis of the cart state difference.

purchase event — the most critical. It is formed on the "Thank you for your order" page (sale.order.ajax → confirmation template). Order data is taken from \Bitrix\Sale\Order::load($orderId):

window.dataLayer.push({ "ecommerce": { "purchase": { "actionField": { "id": "ORDER-5678", "revenue": 7500, "shipping": 300 }, "products": [ {"id": "SKU-1234", "name": "Product 1", "price": 2500, "quantity": 3} ] } } }); 

Why Server-Side Sending via OnSaleOrderPaid Is Critical?

Relying solely on the client-side dataLayer is risky—the user may close the page before the script fires. For guaranteed transaction tracking, the OnSaleOrderPaid event handler is used. When the payment status changes to "Paid", a server-side script sends data to Metrica via the Measurement Protocol or writes them to a separate queue for subsequent upload via the offline conversions API. This approach eliminates data loss and prevents duplicate transactions. On one project for a large electronics retailer, we reduced transaction loss from 30% to under 2% after implementing server-side sending.

Technical Requirements for Server-Side Sending - PHP 8.1+ with cURL support - Bitrix version 21+ (uses D7) - Access to Yandex.Metrica counter settings (counter number and OAuth token) - OnSaleOrderPaid event handler in a custom module or in init.php

Setting Up Goals

In the Yandex.Metrica interface, create goals of the "JavaScript event" type to track specific actions:

Goal Identifier Trigger
Product view product_detail Product page load
Add to cart add_to_cart "Add to Cart" click
Checkout start begin_checkout Go to checkout page
Order completion purchase_complete Confirmation page

Goals are sent via ym(COUNTER_ID, 'reachGoal', 'add_to_cart') in parallel with dataLayer events. They complement ecommerce data and allow building composite goals for funnels.

Aspect Client-side dataLayer Server-side sending
Reliability Medium (depends on browser) High (guaranteed)
Latency Instant 1–5 minutes (offline conversions)
Duplication Possible on page refresh Eliminated via flag check
Product data Full Only ID and quantity

What's Included in Ecommerce Setup

We have been working with Bitrix for over 10 years and have completed more than 150 projects. The standard package includes:

  • Audit of current dataLayer structure and counter
  • Development of detail, add, remove, purchase events
  • Integration of server-side sending via OnSaleOrderPaid
  • Creation of goals and funnels in Yandex.Metrica
  • Testing on test and production environments
  • Training your manager on report usage
  • Documentation of implemented events

Debugging

Debugging Enhanced Ecommerce is the most labor-intensive phase. Tools:

Browser console — after each action, check the contents of window.dataLayer. The command JSON.stringify(dataLayer, null, 2) shows all accumulated events.

Yandex.Metrica → Visit Parameters — in the report "Content → Visit Parameters" you can see which ecommerce events Metrica recorded. Data appears with a 5-10 minute delay.

Tag Assistant by Yandex — a browser extension that shows in real time what data is being sent to the counter. It helps detect: missing required fields, incorrect price format (string instead of number), duplicate events.

Common errors:

  • Price transmitted as a string with spaces ("2 500" instead of 2500) – Metrica ignores such values.
  • purchase event fires on every refresh of the confirmation page – duplicates transactions. Solution: check the window.ecommerceSent flag or store the sent order ID in sessionStorage.
  • category contains full breadcrumbs instead of hierarchy via / – breaks the category report.
  • Ecommerce container not enabled in counter settings (Settings → Ecommerce → checkbox "Send ecommerce data").

Do you want to set up full sales analytics? Contact us — we will assess your project within one day. Get a consultation on Enhanced Ecommerce integration.