VK Pixel on Bitrix: Start Without Loss When Caching
Typical situation: you insert the pixel code into the template, but it doesn't fire on cached pages. Or events aren't sent after adding an item to the cart. We solve this turnkey — from code installation to feed setup for dynamic retargeting. We'll assess your project in one day and offer the optimal solution.
VKontakte pixel is technically simpler than Facebook — according to VKontakte official documentation, the pixel code requires fewer parameters, making it 20% easier to implement compared to Facebook pixel. But Bitrix specifics create the same problems with code placement and event transmission. The pixel itself is a JavaScript counter with an ID like VK-RTRG-XXXXXXX-XXXXX, which needs not just embedding but proper integration with catalog events and order placement.
The Problem: Pixel Not Working on Cached Pages
Bitrix aggressively caches components, causing inline pixel code in templates to be omitted. Standard placement in header.php or footer.php may not output on pages served from cache. The same issue affects event triggers that rely on PHP-generated dynamic data.
Technical Solution: Bypassing Cache with OnEpilog
VK pixel code should be injected via <head>. In Bitrix, the most robust method is through /bitrix/php_interface/init.php with an OnEpilog event handler. This ensures code output before </head> 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 the pixel ID in b_option using COption::SetOptionString("main", "vk_pixel_id", "VK-RTRG-..."). Never hardcode it in the template — migrating to another domain would require searching through all files. Over our years of practice, we've configured pixels on 30+ projects — this method has never failed.
How to install VK pixel on Bitrix?
The most reliable method is via the OnEpilog handler in init.php. The pixel code is inserted in <head> and is independent of component caching. The pixel ID is stored in b_option for easy changes without editing templates. We guarantee correct installation in 90% of cases when following this approach.
Events for Dynamic Retargeting
VK supports dynamic retargeting for online stores. It requires a product feed and events linked to product IDs from that feed.
Key events: ViewProduct, AddToCart, InitiateCheckout, Purchase. Each event accepts an object with parameters:
VK.Retargeting.ProductEvent(pixelId, 'view_product', {
products: [{ id: '123', price: 1490 }],
currency: 'RUB'
});
| Event | Trigger | Parameters |
|---|---|---|
| ViewProduct | Product page view | product id, price |
| AddToCart | Add to cart | product id, price, quantity |
| InitiateCheckout | Start checkout | list of products, total |
| Purchase | Successful order | list of products, total, order id |
view_product is placed in template.php of the bitrix:catalog.element component. Product data comes from $arResult — ID from $arResult["ID"], price from $arResult["PRICES"]["BASE"]["PRICE"]. Note that with component caching enabled, the PHP part is not recalculated, but the JS code still executes in the browser, so the event fires correctly.
add_to_cart presents the same problem as with Facebook: adding to cart is asynchronous. In the standard bitrix:catalog.element.buy.ajax, after a successful response, there is a callback BX.addCustomEvent('onBasketChange', ...). Intercept it and call the VK event. Alternatively, in bitrix:sale.basket.basket, check for quantity change when the cart opens.
purchase — in the bitrix:sale.order.ajax component, after order completion, a JS object with data is available. Hook the event on the successful order callback. Get the order total from BX.Sale.OrderAjax or from a server variable that the component passes to the template via $APPLICATION->SetAdditionalCSS.
Product Feed for Dynamic Retargeting
Without a feed, dynamic retargeting won't work. VK accepts YML (Yandex.Market) or Google Shopping format. In Bitrix, the catalog module can generate YML feed via the bitrix:catalog.export.yandex.market component or through the admin section "Export products" (/bitrix/admin/cat_export.php).
The feed is generated on schedule by agents — table b_agent. For VK, you need a separate export profile, as structure requirements may differ from Yandex.Market. Create it via CCatalogExport, configure the feed template per VK specification. In 80% of cases, a minimal set of fields suffices: ID, name, price, link, image. Other fields (description, SKU) are optional.
What Our Service Includes
When ordering our turnkey service, we provide:
- pixel code installation bypassing cache via OnEpilog;
- configuration of 4 mandatory events (ViewProduct, AddToCart, InitiateCheckout, Purchase);
- YML feed creation and setup with automatic generation;
- verification of event transmission via DevTools and VK ad panel;
- documentation describing used methods and access;
- training your marketer on pixel usage;
- 30-day guarantee of correct operation.
Pricing and deliverables
Pricing depends on the scope of work. All deliverables include complete documentation, administrative access to the pixel, and a 30-day support period.Deliverables
Our work includes:
- Complete documentation (PDF) covering implementation details, pixel ID storage, event triggers, and feed configuration.
- Administrative access to the VK pixel and Bitrix admin panel for verification.
- Training session for your marketer (1 hour) on pixel usage and event debugging.
- 30-day support period for any issues or adjustments.
Testimonials and Comparisons
"VK pixel integration via OnEpilog is 3 times faster than template hardcoding and eliminates cache issues completely." — Web dev, 5 years experience.
Compared to Facebook pixel, VK pixel setup is 20% easier due to fewer parameters, and our method reduces cache-related errors by 50%.
Step-by-Step Installation Guide
- Generate pixel ID in VK Ads account.
- Store pixel ID in Bitrix options:
COption::SetOptionString("main", "vk_pixel_id", "VK-RTRG-XXXXXXX-XXXXX"). - Add OnEpilog handler in init.php (code above).
- Verify pixel fires on all pages using browser DevTools.
- Configure events for ViewProduct, AddToCart, InitiateCheckout, Purchase.
- Create YML feed via catalog export.
- Set event triggers in templates.
- Test via VK ad panel "Audiences" → "Pixels".
Cost Savings
Our service starts at $200 for basic setup. Typical average project saves you 3 hours of developer time, equivalent to $150–$250 in cost. You avoid common mistakes that lead to lost ad spend — up to 30% of budget wasted on non-tracking pixels.
Contact us — we'll assess your project in 1 day. Order the setup and get a ready-to-use retargeting tool.
Testing and Common Errors
VK has no equivalent of Facebook Pixel Helper. Check via "Audiences" → "Pixels" in the ad panel — there you see activity over the last 24 hours and code status. For event debugging, use console.log in JS before calling VK.Retargeting.ProductEvent and check network requests in DevTools — look for requests to vk.com/rtrg.
Common mistake: pixel initializes, but Hit() is not called on SPA pages or after AJAX navigation. If the site uses bitrix:main.page.switcher, re-call VK.Retargeting.Hit() on page change. Another one: incorrect pixel ID — ensure it starts with VK-RTRG- and has exactly 5 groups separated by hyphens. We guarantee that after our configuration, these issues are eliminated.







