Setting up e-commerce in Yandex.Metrica for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • 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
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Configuring E-Commerce Tracking in Yandex.Metrica for 1C-Bitrix

Without e-commerce data in Yandex.Metrica, analytics for an online store is reduced to counting visits and clicks. Enhanced Ecommerce reveals the complete funnel: from product card views to payment completion, with breakdown by products, brands, and categories. Let's examine the implementation of dataLayer events in Bitrix and debugging methods.

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.

Main events:

  • detail — product card view.
  • add — add to cart.
  • remove — remove from cart.
  • purchase — purchase completion.

Each event contains an ecommerce object with a products array. A product is described by fields: id, name, price, brand, category, quantity, variant.

Implementing 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 to the developer.

Detail event — added to the catalog.element component template. In result_modifier.php or template.php, a product array is formed and pushed into 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 — triggered when clicking the "Add to Cart" button. In Bitrix, adding to cart typically occurs 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, triggered when removing from cart. Intercepted through the same OnBasketChange by analyzing the difference in cart states.

Purchase event — the most critical. 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}
            ]
        }
    }
});

Server-side submission via OnSaleOrderPaid. Relying solely on client-side dataLayer is risky — the user can close the page before the script fires. For guaranteed transaction tracking, use the OnSaleOrderPaid event handler. When payment status changes to "Paid", the server script sends data to Metrica via Measurement Protocol or writes it to a separate queue for subsequent upload via the offline conversions API.

Setting Up Goals

In Yandex.Metrica interface, goals are created as "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
Begin Checkout begin_checkout Checkout page transition
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 enable building composite goals for funnels.

Reports by Products, Brands, Categories

After setup, Metrica shows an E-Commerce section with reports:

  • Products — revenue, purchase count, average purchase price for each product.
  • Brands — aggregation by the brand field from dataLayer.
  • Categories — hierarchical structure built from the category field (separator /).
  • Promo codes and coupons — if you pass the coupon field in actionField.

Report accuracy depends entirely on dataLayer data quality. Inconsistent id values between detail and purchase events will break the funnel.

Debugging

Debugging Enhanced Ecommerce is the most time-consuming stage. Tools:

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

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

Tag Assistant by Yandex — browser extension showing in real-time what data is sent to the counter. Helps identify: missing required fields, incorrect price format (string instead of number), duplicate events.

Common errors:

  • Price passed as string with spaces ("2 500" instead of 2500) — Metrica ignores such values.
  • The purchase event fires on every confirmation page refresh — transactions are duplicated. Solution: check a window.ecommerceSent flag or store the sent order ID in sessionStorage.
  • category contains full breadcrumbs instead of hierarchy via / — category reports break.
  • ecommerce container not connected in counter settings (Settings → E-Commerce → checkbox "Send e-commerce data").