VitUrzh
2/1/2017 - 4:29 AM

Передача в яндекс метрику уникальный данные о пользователе. Нужно для выявления скликивания в директе.

Передача в яндекс метрику уникальный данные о пользователе. Нужно для выявления скликивания в директе.

<!-- Yandex.Metrika counter -->
  <script type="text/javascript">

		var BrowserDetect = {
			init: function () {
			this.browser = this.searchString(this.dataBrowser) || "--";//An unknown browser
			this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "--";//an unknown version
			this.OS = this.searchString(this.dataOS) || "--";//an unknown OS
			},
			searchString: function (data) {
			for (var i=0;i<data.length;i++) {
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
			if (dataString.indexOf(data[i].subString) != -1)
			return data[i].identity;
			}
			else if (dataProp)
			return data[i].identity;
			}
			},
			searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
			},
			dataBrowser: [
			{string: navigator.userAgent,subString: "Chrome",   identity: "Chrome"},
			{string: navigator.userAgent,subString: "OmniWeb",  identity: "OmniWeb",versionSearch: "OmniWeb/"},
			{string: navigator.userAgent,subString: "Firefox",  identity: "Firefox"},
			{string: navigator.userAgent,subString: "YaBrowser",identity: "YaBrowser"},
			{string: navigator.userAgent,subString: "Mozilla",  identity: "Netscape",versionSearch: "Mozilla"}/* For Older Netscapes (4-) */
			{string: navigator.userAgent,subString: "MSIE",     identity: "Internet Explorer",versionSearch: "MSIE"},
			{string: navigator.userAgent,subString: "Gecko",    identity: "Mozilla",versionSearch: "rv"},
			{string: navigator.vendor,subString: "Apple", identity: "Safari",versionSearch: "Version"},
			{string: navigator.vendor,subString: "iCab",  identity: "iCab"},
			{string: navigator.vendor,subString: "KDE",   identity: "Konqueror"},
			{string: navigator.vendor,subString: "Camino",identity: "Camino"},
			{prop: window.opera,identity: "Opera",versionSearch: "Version"},
			],
			dataOS : [
			{string: navigator.platform,subString:  "Win",   identity: "Windows"},
			{string: navigator.platform,subString:  "Mac",   identity: "Mac"},
			{string: navigator.platform,subString:  "Linux", identity: "Linux"}
			{string: navigator.userAgent,subString: "iPhone",identity: "iPhone/iPod"},
			]
		};
		BrowserDetect.init();

		var br = "-"+BrowserDetect.browser;
		var vr = BrowserDetect.version;
		var os = "-"+BrowserDetect.OS
		var userip = "<? echo $_SERVER['REMOTE_ADDR'];?>";
		var screen = "-"+screen['width']+"x"+screen['height'];

        (function (d, w, c) {
            (w[c] = w[c] || []).push(function() {
                try {
                    w.yaCounterXXXXXXXX = new Ya.Metrika({
                        id:XXXXXXXX,
                        clickmap:true,
                        trackLinks:true,
                        accurateTrackBounce:true,
                        webvisor:true,
                        ut:"noindex",
			                  params:{'ip': userip, 'unic': userip+screen+br+vr+os}
                    });
                } 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 = "https://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/22827298?ut=noindex" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
    <!-- /Yandex.Metrika counter -->