Setting up Yandex.Webvisor 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
    1212
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815
  • 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
    565
  • 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
    980

Yandex.Webvisor Setup on 1C-Bitrix

Webvisor doesn't work on HTTPS site with incorrect CSP headers — session recording via Yandex iframe, browser blocks it if Content-Security-Policy doesn't allow frame-ancestors. Second common cause: Metrica tag inserted via Google Tag Manager, GTM loads asynchronously, webvisor initializes after user made first actions — session start lost.

Correct Metrica Tag Placement

Yandex requires tag as high as possible in <head>. In Bitrix, standard way — insert via OnBeforeProlog event in init.php or directly in prologue file /bitrix/templates/TEMPLATE/header.php.

In /bitrix/php_interface/init.php:

AddEventHandler('main', 'OnBeforeProlog', function() {
    ob_start();
    ?>
    <!-- Yandex.Metrica -->
    <script>
       (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
       var z = m[i],d=e.createElement(t),n=e.getElementsByTagName(t)[0];
       d.async=1;d.src=r;d.id='metrika-';
       n.parentNode.insertBefore(d,n);
       z(i,'init', { id: XXXXXXXX, webvisor: true, clickmap: true, trackLinks: true });
       })(window, document, 'script', 'https://cdn.jsdelivr.net/npm/yandex-metrika@latest/metrika.js', 'ym');
    </script>
    <!-- /Yandex.Metrica -->
    <?php
    $html = ob_get_clean();
    $GLOBALS['APPLICATION']->AddHeadString($html, true);
});

Or via standard bitrix:metrika component — available in fileman module, install from Marketplace.

Content-Security-Policy and Webvisor iframe

Webvisor records screen via <iframe> on webvisor.com domain. If server (nginx or via PHP headers) has strict CSP, recording won't start — console error Refused to frame ... because an ancestor violates the following Content Security Policy directive.

Minimum directive set for Webvisor:

Content-Security-Policy:
  frame-src 'self' https://webvisor.com;
  script-src 'self' 'unsafe-inline' https://mc.yandex.ru https://cdn.jsdelivr.net;
  img-src 'self' data: https://mc.yandex.ru;

In Bitrix headers can be set in /bitrix/.htaccess or in init.php via header() — but only before first HTML output. If using ob_start() in prologue, not a problem.

Webvisor on SPA/AJAX Pages

Most modern Bitrix templates use AJAX navigation (BX.ajax, bitrix:main.ajaxlinks component). On page transition without reload Webvisor doesn't record URL change — whole visit looks like one page in recording.

Solution: call ym(XXXXXXXX, 'hit', window.location.href) after every AJAX transition. In Bitrix there's BX.addCustomEvent('onAjaxSuccess', ...) event — hook into it:

BX.addCustomEvent('onAjaxSuccess', function(event) {
    if (typeof ym !== 'undefined') {
        ym(XXXXXXXX, 'hit', window.location.href);
    }
});

Without this Webvisor data incorrect: all catalog transitions recorded as single visit on entry page.

Verifying Recording Correctness

After setup — check "Webvisor" section "Monitoring." If sessions recording but video black — mixed content problem (HTTP resources on HTTPS site). If sessions not appearing at all — check Network tab DevTools for requests to mc.yandex.ru/watch/: status 200 means counter works but data not processed yet (up to 20 minutes delay for new sessions).