VKontakte Pixel Setup on 1C-Bitrix
VKontakte pixel is technically simpler than Facebook, but Bitrix specifics create the same issues with code placement and event transmission. The pixel itself is a JavaScript counter with ID like VK-RTRG-XXXXXXX-XXXXX, which needs not just insertion on site, but proper integration with catalog events and order processing.
Basic Setup Without Cache Loss
VK pixel code connects via <head>. The most reliable method in Bitrix is via /bitrix/php_interface/init.php file with OnEpilog event handler. This guarantees code output before </head> closure regardless of component caching:
AddEventHandler("main", "OnEpilog", function() {
$vkPixelId = COption::GetOptionString("main", "vk_pixel_id", "");
if (!$vkPixelId) return;
?>
<script type="text/javascript">
!function(){var t=document.createElement("script");...}();
VK.Retargeting.Init("<?= htmlspecialchars($vkPixelId) ?>");
VK.Retargeting.Hit();
</script>
<?php
});
Store pixel ID in b_option via COption::SetOptionString("main", "vk_pixel_id", "VK-RTRG-..."). Don't hardcode in template — moving to another domain means searching all files.
Events for Dynamic Retargeting
VKontakte supports dynamic retargeting for online stores. Requires product feed and events linked to product IDs from that feed.
Key events: ViewProduct, AddToCart, InitiateCheckout, Purchase. Each event accepts object with parameters:
VK.Retargeting.ProductEvent(pixelId, 'view_product', {
products: [{ id: '123', price: 1490 }],
currency: 'RUB'
});
view_product is placed in template.php of bitrix:catalog.element component. Get product data from $arResult — ID from $arResult["ID"], price from $arResult["PRICES"]["BASE"]["PRICE"]. Note that with component caching enabled, PHP part isn't recalculated, but JS code still executes in browser, so event fires correctly.
add_to_cart — same issue as Facebook: cart addition is async. In standard bitrix:catalog.element.buy.ajax after successful response there's callback BX.addCustomEvent('onBasketChange', ...). Intercept it and call VK event. Alternatively — in bitrix:sale.basket.basket when opening cart check quantity change.
purchase — in bitrix:sale.order.ajax component after order completion, JS object with data is available. Hook event to successful checkout callback. Get order amount from BX.Sale.OrderAjax or server variable component passes to template via $APPLICATION->SetAdditionalCSS.
Setting Up Feed for Dynamic Retargeting
Without feed, dynamic retargeting doesn't work. VKontakte accepts feed in YML (Yandex.Market) or Google Shopping format. In Bitrix, catalog module can generate YML feed via bitrix:catalog.export.yandex.market component or admin section "Export Products" (/bitrix/admin/cat_export.php).
Feed generates on schedule via agents — b_agent table. For VK you need separate export profile since requirements may differ from Yandex.Market. Create via CCatalogExport, adjust feed template to VK specs.
Checking Events
VKontakte has no Facebook Pixel Helper equivalent. Check via "Audiences" → "Pixels" in ad cabinet — see activity last 24 hours and code status. For event debugging use console.log in JS before VK.Retargeting.ProductEvent call and check network requests in DevTools — look for requests to vk.com/rtrg.
Common mistake: pixel initializes but Hit() doesn't call on SPA pages or after AJAX navigation. If site uses bitrix:main.page.switcher, need to re-call VK.Retargeting.Hit() on page change.







