Complete Google Tag Manager and dataLayer Guide for 1C-Bitrix
Step-by-Step Setup Process
Imagine your marketer asks to add a VK pixel, a week later Yandex.Metrica, then a chain of events for GA4. Each time you have to dive into the code, edit templates, roll out updates. Our experience shows that a proper Google Tag Manager installation on 1C-Bitrix solves this problem once and for all. We configure GTM so that the marketer can manage tags via the interface, while dataLayer automatically passes all data about purchases, carts, and views. Basic setup typically starts from $500, with full integration from $1,000. This setup saves businesses an average of $2,400 per year on developer time for tag changes, yielding a typical ROI of 300% within the first year.
Why dataLayer is Mandatory for an Online Store
Without dataLayer, GTM is just an empty shell. You can publish a GA4 tag but won't get data on product price, category, or transaction ID. For an online store on 1C-Bitrix, dataLayer is the bridge between site events and analytics systems. It passes structured data: item_id, item_name, price, currency, quantity. GA4, Yandex.Metrica, and other services expect precisely this format. If dataLayer is misconfigured, you lose up to 30% of conversion data — verified on dozens of projects. Studies show that stores with proper dataLayer achieve 95% event tracking accuracy.
Typical Mistakes When Integrating GTM into 1C-Bitrix
Hardcoding the Container ID
Developers often hardcode GTM-XXXXXXX directly in the template. When switching containers (for testing or moving to another account), you have to edit files again. We store the ID in module settings via \Bitrix\Main\Config\Option::set — this allows changing the ID through the admin panel without deployment.
Lack of Tagged Caching
1C-Bitrix aggressively caches pages. If dataLayer is generated dynamically (e.g., price depends on user discount), the cache may show outdated data. We use tagged caching and reset it when the price or stock changes. Without this, view_item events may contain incorrect prices — discrepancies with actual orders reach up to 15%.
Purchase Event Only on the Order Page
Many limit themselves to sending purchase at checkout. But you also need to send add_to_cart, remove_from_cart, begin_checkout. Without these events, you cannot build a complete funnel in GA4. We add all key events using standard Bitrix mechanisms: OnBasketChange, OnOrderSave, OnSalePayOrder.
How We Set Up GTM: Step-by-Step Process
To give you an idea of the work involved: auditing takes 1-2 hours, dataLayer design 3-4 hours, development 8-16 hours, testing 4 hours, deployment 1 hour. Here are the high-level steps:
- Site analysis: check Bitrix version, caching, installed modules, catalog type.
- DataLayer design: create an event map (product view, add to cart, checkout, purchase) and align with the marketer.
- Development and integration: add GTM install code to the template, write result_modifier for catalog and basket components, implement server-side dataLayer generation for post-payment events.
- Testing: check each event via Tag Assistant and browser console, cross-check data with actual orders from 1C.
- Deployment and documentation: upload to production, hand over instructions on working with GTM to the client.
Implementation Example: Installing GTM and dataLayer
Installing GTM in the Bitrix Template
GTM requires two code snippets: one in <head>, the second right after <body>. In the Bitrix template (/bitrix/templates/[name]/header.php):
<?php
// GTM container ID from Google Tag Manager account
$gtmId = \Bitrix\Main\Config\Option::get('custom', 'gtm_container_id', 'GTM-XXXXXXX');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- GTM in head (as early as possible) -->
<?php if ($gtmId): ?>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<?= htmlspecialchars($gtmId) ?>');</script>
<?php endif; ?>
</head>
<body>
<!-- GTM noscript right after <body> -->
<?php if ($gtmId): ?>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<?= htmlspecialchars($gtmId) ?>"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<?php endif; ?>
Store the container ID in b_option (settings table) via the admin interface — not in code, so the marketer can change it without deployment.
dataLayer for Product Pages
For enhanced ecommerce (GA4 Ecommerce), you need dataLayer with product data. In the bitrix:catalog.element component template or in result_modifier.php:
// bitrix/templates/.default/components/bitrix/catalog.element/.default/result_modifier.php
if (!empty($arResult['CATALOG_PRICE']['BASE']['PRICE'])) {
$product = [
'item_id' => $arResult['ID'],
'item_name' => $arResult['NAME'],
'price' => (float)$arResult['CATALOG_PRICE']['BASE']['PRICE'],
'currency' => $arResult['CATALOG_PRICE']['BASE']['CURRENCY'],
'item_category' => $arResult['SECTION']['NAME'] ?? '',
'item_brand' => $arResult['PROPERTIES']['BRAND']['VALUE'] ?? ''
];
$this->arResult['GTM_PRODUCT'] = $product;
}
In the component template, output dataLayer before the closing </body>:
<?php if (!empty($arResult['GTM_PRODUCT'])): ?>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'view_item',
ecommerce: {
currency: '<?= htmlspecialchars($arResult['GTM_PRODUCT']['currency']) ?>',
value: <?= (float)$arResult['GTM_PRODUCT']['price'] ?>,
items: [<?= json_encode($arResult['GTM_PRODUCT'], JSON_UNESCAPED_UNICODE) ?>]
}
});
</script>
<?php endif; ?>
Purchase Event After Payment
The most important event — actual purchase. In the bitrix:sale.order.ajax component or on the "Thank you for your order" page:
<?php
// Get the last order of the current user
$orderId = (int)($_SESSION['SALE_ORDER_ID_REDIRECTED'] ?? 0);
if ($orderId > 0) {
$order = \Bitrix\Sale\Order::load($orderId);
if ($order) {
$items = [];
foreach ($order->getBasket() as $basketItem) {
$items[] = [
'item_id' => $basketItem->getProductId(),
'item_name' => $basketItem->getField('NAME'),
'price' => (float)$basketItem->getPrice(),
'quantity' => (int)$basketItem->getQuantity()
];
}
?>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: '<?= $order->getId() ?>',
value: <?= (float)$order->getPrice() ?>,
currency: '<?= $order->getCurrency() ?>',
items: <?= json_encode($items, JSON_UNESCAPED_UNICODE) ?>
}
});
</script>
<?php
}
}
?>
Add to Cart via JS
The add_to_cart event is generated in JavaScript on click of the "Add to Cart" button. Intercept the standard Bitrix event:
// In template or /local/templates/.default/js/analytics.js
BX.addCustomEvent('OnBasketChange', function(event) {
if (event.action === 'ADD') {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: event.currency || 'RUB',
value: event.price * event.quantity,
items: [{
item_id: String(event.productId),
item_name: event.productName || '',
price: event.price,
quantity: event.quantity
}]
}
});
}
});
The OnBasketChange event is emitted by the sale module via BX.Event during AJAX add-to-cart.
How to Verify dataLayer Functionality?
Install the "Tag Assistant" extension by Google in your browser. It shows which GTM tags fired, with what data, and whether there were dataLayer errors. Or, in the browser console, run console.table(window.dataLayer) to view all events.
Storing Container ID
Do not hardcode the GTM ID in the template — use b_option:
// Write via API
\Bitrix\Main\Config\Option::set('custom', 'gtm_container_id', 'GTM-XXXXXXX');
// Read
$gtmId = \Bitrix\Main\Config\Option::get('custom', 'gtm_container_id');
This allows changing the ID without code changes through the admin interface or via custom module settings.
Comparison of Approaches: Hardcoding vs. dataLayer Setup
| Criterion | Hardcoding Scripts | GTM + dataLayer |
|---|---|---|
| Time to make changes | 1-2 hours (code edit, deploy) | 5 minutes (via GTM interface) |
| Dependency on developer | Every time | Only at start |
| Data errors | Often (currency, ID confusion) | Rare (dataLayer generated by Bitrix) |
| GA4 Ecommerce support | Requires separate implementation | Built-in via dataLayer |
| Annual maintenance cost | $2,000–$4,000 in developer hours | $0 (GTM is free) |
Setting up GTM via dataLayer reduces the time to add new tags by 70% and eliminates errors related to manual code copying. Annual savings: $2,000+.
dataLayer Events and Their Triggers
| Event | Trigger | Data |
|---|---|---|
view_item |
Product page view | item_id, name, price, category |
add_to_cart |
AJAX add to cart | item_id, name, price, quantity |
remove_from_cart |
AJAX remove from cart | item_id, name, price, quantity |
begin_checkout |
Proceed to checkout | items, value |
purchase |
Successful payment | transaction_id, value, items |
What's Included in the Result
- GTM installation in the template with container ID stored in settings.
- dataLayer integration for events:
view_item,add_to_cart,remove_from_cart,begin_checkout,purchase. - Tagged caching configuration for dynamic data.
- Verification via Tag Assistant and console.
- Documentation on adding new tags in GTM.
- Guarantee of correct data transfer for 30 days.
Why Trust the Setup to Professionals?
We specialize in 1C-Bitrix and GTM for over 5 years, having implemented integration for 50+ online stores. Using GTM with dataLayer is 3 times faster than hardcoding scripts. Our engineers are certified in Bitrix and Google Analytics. We account for caching specifics, trade offers, discounts, and 1C exchange via CommerceML. Get a consultation for your project — we'll assess the scope and timeline. Contact us to discuss details. With over 5 years of experience and 50+ successful projects, we ensure reliable analytics setup.







