<?php
/******************************************************************************/
//                                                                            //
//                             Smarty plugin                                  //
//                            @package Smarty                                 //
//							 @subpackage plugins                              //
//                        https://life-style.uz/                               //
//                   produced by Life Style, life-style.uz                    //
//                                                                            //
/******************************************************************************/

function smarty_function_yandex_metrika($params, &$smarty)
{
    $assign = fetch_getParam('assign', $params, 'metrika');
    $code   = fetch_getParam('code', $params, '');
    $result = '';

    if ($code != '') {
        $result = '
        <!-- Yandex.Metrika counter -->
        <script>
            (function (d, w, c) { (w[c] = w[c] || []).push(function() {
                    try {
                        w.yaCounter' . $code . ' = new Ya.Metrika({
                            id:' . $code . ',
                            clickmap:true,
                            trackLinks:true,
                            accurateTrackBounce:true,
                            webvisor:true
                        });
                    } catch(e) { }
                });
        
                 var n = d.getElementsByTagName("script")[0],
                    s = d.createElement("script"),
                    f = function () { n.parentNode.insertBefore(s, n); };
                s.type = "text/javascript";
                s.async = true;
                s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
            
                if (w.opera == "[object Opera]") {
                    d.addEventListener("DOMContentLoaded", f, false);
                } else { f(); }
            })(document, window, "yandex_metrika_callbacks");
        </script>
        
        <noscript><div><img src="https://mc.yandex.ru/watch/' . $code . '" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
        <!-- /Yandex.Metrika counter -->
        ';
    }

	return $result;
}


?>