42 lines
1.7 KiB
PHP
42 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* ============================================
|
|
* AegisOne Engineering — Счётчики аналитики
|
|
* ============================================
|
|
*
|
|
* Подключается в <head> всех страниц: выводит JS-счётчики.
|
|
* Подключается в inc/analytics-body.php после <body>: выводит <noscript>.
|
|
*
|
|
* Яндекс.Метрика: YANDEX_METRIKA_ID (только цифры)
|
|
* Google Analytics: GOOGLE_ANALYTICS_ID (G-XXXXXXXXXX)
|
|
*/
|
|
|
|
$ymId = defined('YANDEX_METRIKA_ID') ? YANDEX_METRIKA_ID : '';
|
|
$gaId = defined('GOOGLE_ANALYTICS_ID') ? GOOGLE_ANALYTICS_ID : '';
|
|
?>
|
|
|
|
<?php if ($ymId !== ''): ?>
|
|
<!-- Yandex.Metrika counter -->
|
|
<script type="text/javascript">
|
|
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
|
m[i].l=1*new Date();
|
|
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
|
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
|
|
})(window, document,'script','https://mc.yandex.ru/metrika/tag.js?id=<?= $ymId ?>', 'ym');
|
|
ym(<?= $ymId ?>, 'init', {ssr:true, webvisor:true, trackHash:true, clickmap:true, ecommerce:"dataLayer", accurateTrackBounce:true, trackLinks:true});
|
|
</script>
|
|
<!-- /Yandex.Metrika counter -->
|
|
<?php endif; ?>
|
|
|
|
<?php if ($gaId !== ''): ?>
|
|
<!-- Google Analytics -->
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= $gaId ?>"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
gtag('config', '<?= $gaId ?>');
|
|
</script>
|
|
<!-- /Google Analytics -->
|
|
<?php endif; ?>
|