Abandoned Cart Retargeting Setup for 1C-Bitrix
Abandoned cart retargeting means showing ads for a specific product to a user who added it to their cart but did not complete the purchase. In Yandex.Direct — via Yandex Audiences or Goals; in Google Ads — via Audience Manager. On a Bitrix site, events and identifiers must be correctly passed to the advertising systems.
Client-Side Events for Ad Pixels
Yandex.Metrica ecommerce — the foundation for retargeting in Yandex.Direct:
// When adding to cart
BX.addCustomEvent('onBasketItemAdded', function(data) {
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'currencyCode': 'RUB',
'add': {
'products': [{
'id': String(data.productId),
'name': data.productName,
'price': data.price,
'quantity': data.quantity,
'category': data.sectionName,
}]
}
}
});
// For Metrica
ym(METRIKA_ID, 'reachGoal', 'add_to_cart', {
product_id: data.productId,
price: data.price,
});
});
Facebook Pixel / Meta Pixel (for international traffic):
BX.addCustomEvent('onBasketItemAdded', function(data) {
fbq('track', 'AddToCart', {
content_ids: [String(data.productId)],
content_type: 'product',
value: data.price * data.quantity,
currency: 'RUB',
});
});
Google Ads Remarketing Tag:
BX.addCustomEvent('onBasketItemAdded', function(data) {
gtag('event', 'add_to_cart', {
items: [{
id: String(data.productId),
google_business_vertical: 'retail',
}],
});
});
Retrieving Bitrix Data for Events
In the catalog.element component template, product data is available via $arResult. Pass it to JS variables in result_modifier.php or in template.php:
// In result_modifier.php of the catalog.element component
global $APPLICATION;
$APPLICATION->AddHeadScript('');
// Or directly in template.php
$productData = [
'id' => $arResult['ID'],
'name' => $arResult['NAME'],
'price' => $arResult['CATALOG_PRICE_1'] ?? 0,
'category' => $arResult['SECTION']['NAME'] ?? '',
'sku' => $arResult['PROPERTIES']['ARTICLE']['VALUE'] ?? '',
];
<!-- In template.php -->
<script>
window.currentProduct = <?= json_encode($productData, JSON_UNESCAPED_UNICODE) ?>;
</script>
Then use window.currentProduct in the "Add to Cart" button JavaScript for the events.
Dynamic Retargeting: Product Feed
To show the exact product that is in the cart (rather than simply remarketing to all visitors), advertising systems require a product feed.
Yandex.Business / Direct — feed in YML format:
// /local/api/yml-feed.php
require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('catalog');
header('Content-Type: application/xml; charset=utf-8');
$date = date('Y-m-d H:i');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<yml_catalog date=\"{$date}\">\n<shop>\n";
echo "<name>Store Name</name>\n";
echo "<company>Company LLC</company>\n";
echo "<url>" . SITE_SERVER_NAME . "</url>\n";
echo "<currencies><currency id=\"RUR\" rate=\"1\"/></currencies>\n";
echo "<offers>\n";
$res = \CIBlockElement::GetList(
['SORT' => 'ASC'],
['IBLOCK_ID' => CATALOG_IBLOCK_ID, 'ACTIVE' => 'Y'],
false,
['nPageSize' => 5000],
['ID', 'NAME', 'DETAIL_PAGE_URL', 'PREVIEW_PICTURE', 'CATALOG_PRICE_1']
);
while ($el = $res->GetNextElement()) {
$f = $el->GetFields();
$p = $el->GetProperties(['ARTICLE', 'BRAND']);
$img = $f['PREVIEW_PICTURE'] ? \CFile::GetPath($f['PREVIEW_PICTURE']) : '';
$url = SITE_SERVER_NAME . $f['DETAIL_PAGE_URL'];
$price = $f['CATALOG_PRICE_1'] ?? 0;
if (!$price) continue;
echo "<offer id=\"{$f['ID']}\" available=\"true\">\n";
echo " <url>" . htmlspecialchars($url) . "</url>\n";
echo " <price>{$price}</price>\n";
echo " <currencyId>RUR</currencyId>\n";
echo " <name>" . htmlspecialchars($f['NAME']) . "</name>\n";
if ($img) echo " <picture>" . htmlspecialchars(SITE_SERVER_NAME . $img) . "</picture>\n";
echo "</offer>\n";
}
echo "</offers>\n</shop>\n</yml_catalog>";
Cache the feed — do not generate it on every request. Cache for 4–8 hours using CPHPCache or an agent that saves the file.
Google Merchant Center — feed in Google Product format:
The structure is similar, but the format is a Google Spreadsheet CSV or XML with the Google namespace. Key fields: id, title, description, link, image_link, price, availability, google_product_category.
Audience Segmentation in Yandex.Metrica
Create segments in Metrica for retargeting:
-
"Added to cart, did not purchase" — reached the
add_to_cartgoal, did not reachorder_completein the last 30 days -
"Browsed category X" — visited URLs matching
/catalog/electronics/, did not purchase
These segments are exported to Yandex Audiences and used in Direct for impression targeting.
Setting Up Campaigns in Yandex.Direct
In Direct, select the "Dynamic Ads" or "Smart Banners" campaign type. Connect the YML feed, configure the audience as the "added to cart" segment. The bid for this audience is typically 1.5–2x higher than for cold traffic — the user is already familiar with the product.
Timelines: pixel and event setup — 1 day. YML feed development — 1–2 days. Audience and campaign setup in advertising systems — 1–2 days.







