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
brandfield from dataLayer. -
Categories — hierarchical structure built from the
categoryfield (separator/). -
Promo codes and coupons — if you pass the
couponfield inactionField.
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 of2500) — Metrica ignores such values. - The
purchaseevent fires on every confirmation page refresh — transactions are duplicated. Solution: check awindow.ecommerceSentflag or store the sent order ID insessionStorage. -
categorycontains full breadcrumbs instead of hierarchy via/— category reports break. - ecommerce container not connected in counter settings (Settings → E-Commerce → checkbox "Send e-commerce data").







