Setting up the VKontakte pixel on 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
    1189
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    813
  • 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
    657
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

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.