/** * tilda-stat отвечает за замер статистики, сколько пользователей было на странице, * сколько процентов страницы были просмотрено (посредством скролла). Определяет время * нахождения на странице. * * В tilda-stat подключается скрипт для отправки логов ошибок. * Подключается скрипт с перформансом, который отправляет метрики скорости открытия сайта. */ (function () { // if (w['tilda_stat_callbacks'] && w['tilda_stat_callbacks'].length > 0) { // } var allRec = document.getElementById('allrecords'); function t_stat__generateUniqID() { var random = Math.floor(Math.random() * 899999) + 100000; return new Date().getTime() + '.' + random; } function t_stat__getCookie(name) { var clearName = name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1'); var regexp = new RegExp('(?:^|; )' + clearName + '=([^;]*)'); var matches = document.cookie.match(regexp); if (matches) { return decodeURIComponent(matches[1]); } } /** * * @param {string} name mean cookie name * @param {string} value * @param {object} options * @returns {undefined} update Cookie via key document.cookie */ function t_stat__setCookie(name, value, options) { var expires = options.expires; if (!expires) return false; if (typeof expires === 'number') { var expiryDate = new Date().getTime() + expires * 1000; expires = new Date(expiryDate); if (expires.toUTCString) { options.expires = expires.toUTCString(); } } value = encodeURIComponent(value); var updatedCookie = name + '=' + value; for (var key in options) { updatedCookie += '; ' + key; if (options[key] !== true) { updatedCookie += '=' + options[key]; } } document.cookie = updatedCookie; } function t_stat__objAssign(obj1, obj2) { for (var key in obj2) { obj1[key] = obj2[key]; } return obj1; } function t_stat__onVisibilityWindowChange(callback) { var visible = true; if (!callback) { throw new Error('no callback given'); } function focused() { if (!visible) { callback((visible = true)); } } function unfocused() { if (visible) { callback((visible = false)); } } // try { // Standards: if ('hidden' in document) { document.addEventListener('visibilitychange', function () { (document.hidden ? unfocused : focused)(); }); } if ('mozHidden' in document) { document.addEventListener('mozvisibilitychange', function () { (document.mozHidden ? unfocused : focused)(); }); } if ('webkitHidden' in document) { document.addEventListener('webkitvisibilitychange', function () { (document.webkitHidden ? unfocused : focused)(); }); } if ('msHidden' in document) { document.addEventListener('msvisibilitychange', function () { (document.msHidden ? unfocused : focused)(); }); } // IE 9 and lower: if ('onfocusin' in document) { document.onfocusin = focused; document.onfocusout = unfocused; } // All others: window.onpageshow = window.onfocus = focused; window.onpagehide = window.onblur = unfocused; // } } function t_stat__trackScrollEvent() { var topPosition = window.pageYOffset; var windowHeight = window.innerHeight; var documentHeight = Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight ); var headerHeight = 0; var footerHeight = 0; isWindowActive = true; var headerBlock = document.getElementById('t-header'); var footerBlock = document.getElementById('t-footer'); var tildaCopy = document.getElementById('tildacopy'); if (headerBlock) { headerHeight = headerBlock.offsetHeight; } if (footerBlock) { footerHeight = footerBlock.offsetHeight; } if (tildaCopy) { footerHeight += tildaCopy.offsetHeight; } var userScreenPositon = Math.floor( ((topPosition - headerHeight + windowHeight) * 100) / (documentHeight - headerHeight - footerHeight) ); if (userScreenPositon < 10) return; var breakpoints = [10, 25, 50, 75, 90]; for (var i = 0; i < breakpoints.length; i++) { var currentPoint = breakpoints[i]; var lastPointIndex = breakpoints.length - 1; if (i === 0 && userScreenPositon >= currentPoint && !isSendScrollEvent['p' + currentPoint]) { statParams.page = '/tilda/scroll/' + currentPoint + '/'; window.tildastat('pageview'); isSendScrollEvent['p' + currentPoint] = true; } else if (userScreenPositon >= currentPoint - 1) { if (isSendScrollEvent['p' + currentPoint] === 0) { statParams.page = '/tilda/scroll/' + currentPoint + '/'; window.tildastat('pageview'); isSendScrollEvent['p' + currentPoint] = setTimeout(function () { clearTimeout(isSendScrollEvent['p' + currentPoint]); isSendScrollEvent['p' + currentPoint] = -1; }, 5000); break; } else if ( ((i !== lastPointIndex && userScreenPositon < breakpoints[i + 1]) || i === lastPointIndex) && isSendScrollEvent['p' + currentPoint] === -1 ) { isSendScrollEvent['p' + currentPoint] = 0; break; } } } } function t_stat__getPageURL() { var hostName = window.location.hostname.indexOf('www.') === 0 ? window.location.hostname.slice(4) : window.location.hostname; if (hostName.lastIndexOf('.') === hostName.length - 1) { hostName = hostName.slice(0, -1); } return hostName + window.location.pathname; } function t_stat__makeHash(str) { var range = Array(str.length); for (var i = 0; i < str.length; i++) { range[i] = i; } return Array.prototype.map .call(range, function (i) { return str.charCodeAt(i).toString(16); }) .join(''); } /* function hashCode(str) { var hash = 0, i, chr; if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { chr = str.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; }; */ function t_stat__getFingerPrint() { var str = (navigator.cookieEnabled ? 'cT' : 'cF') + '|' + (navigator.deviceMemory ? 'dm' + navigator.deviceMemory : 'dm') + '|' + (navigator.hardwareConcurrency ? 'hc' + navigator.hardwareConcurrency : 'hc') + '|' + (navigator.languages ? 'l' + navigator.languages.join(',') : 'l') + '|'; if (!navigator.platform && !navigator.appName) { str += (navigator.userAgent ? 'ua' + navigator.userAgent : 'ua') + '|'; } else { str += (navigator.platform ? 'p' + navigator.platform : 'p') + '|' + (navigator.vendor ? 'v' + navigator.vendor : 'v') + '|' + (navigator.appCodeName ? 'a' + navigator.appCodeName : 'a') + '|' + (navigator.appName ? 'n' + navigator.appName : 'n') + '|'; } if (navigator.plugins) { var ii, ll, plug = ''; ll = navigator.plugins.length > 20 ? 20 : navigator.plugins.length; for (ii = 0; ii < ll; ii++) { if (navigator.plugins[ii] && navigator.plugins[ii].filename) { plug += navigator.plugins[ii].filename; } else if (navigator.plugins[ii] && navigator.plugins[ii].name) { plug += navigator.plugins[ii].name; } } str += 'pl' + plug + '|'; } str += 'pr' + window.devicePixelRatio + '|'; str += 'w' + (screen && screen.width ? screen.width : window.innerWidth) + 'h' + (screen && screen.height ? screen.height : window.innerHeight) + '|'; str += 'cD' + (screen.colorDepth ? screen.colorDepth : '') + '|'; str += 'tO' + new Date().getTimezoneOffset() + '|'; str += 'mT' + (typeof navigator.maxTouchPoints !== 'undefined' ? navigator.maxTouchPoints : typeof navigator.msMaxTouchPoints !== 'undefined' ? navigator.msMaxTouchPoints : '') + '|'; str = t_stat__makeHash(str); //str = hashCode(str); //console.log(str); return str; } function t_stat__getUIDandSID() { //GET UID AND SID userid = t_stat__getCookie('tildauid'); sessionid = t_stat__getCookie('tildasid'); if (isCookieDisabled) { if (!userid) userid = 'simple'; if (!sessionid) sessionid = 'simple'; } else { if (!userid) { userid = t_stat__generateUniqID(); } if (!sessionid) { sessionid = t_stat__generateUniqID(); } } } function t_stat__setUIDandSID() { //PROLONGATE COOKIE EXPIRATION if (!isCookieDisabled) { var expiriesDate = 60 * 60 * 24 * 90; //90 days in seconds t_stat__setCookie('tildauid', userid, { expires: expiriesDate, path: '/' }); t_stat__setCookie('tildasid', sessionid, { expires: 1800, path: '/' }); } } function create(opts) { //CHECK BOTS if (statParams.user_agent > '' && statParams.user_agent.indexOf('bot') != -1) { return false; } if (window.location.protocol != 'http:' && window.location.protocol != 'https:') { console.log('TildaStat: cannot work on local page'); return false; } //GET UID AND SID t_stat__getUIDandSID(); t_stat__setUIDandSID(); statParams.page = t_stat__getPageURL(); statParams.referrer = document.referrer || ''; statParams.userid = userid; statParams.sessionid = sessionid; statParams.user_agent = window.navigator.userAgent; statParams.user_language = window.navigator.userLanguage || window.navigator.language; if (allRec) { statParams.projectid = allRec.getAttribute('data-tilda-project-id') || '0'; statParams.pageid = allRec.getAttribute('data-tilda-page-id') || '0'; statParams.pagealias = allRec.getAttribute('data-tilda-page-alias') || ''; statParams.formskey = allRec.getAttribute('data-tilda-formskey') || ''; } statParams.params = {}; var tmp; //UTM try { tmp = decodeURIComponent(window.location.search); } catch (e) { tmp = window.location.search; } if (tmp > '?') { statParams.pagequery = tmp.substring(1).toLowerCase(); if (~statParams.pagequery.indexOf('utm_')) { var arPair; var arParams = statParams.pagequery.split('&'); Array.prototype.forEach.call(arParams, function (param) { arPair = param.split('='); if (arPair.length > 1) { if ( arPair[0] === 'utm_referrer' && (!statParams.referrer || ~statParams.referrer.indexOf('ohio8.v')) ) { statParams.referrer = arPair[1]; } else { statParams.params[arPair[0]] = arPair[1]; } } else { statParams.params[arPair[0]] = ''; } }); } } //IS MOBILE var isMobile = false; if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { isMobile = true; } statParams.ismobile = isMobile; //KEY (CODE) if (document.getElementById('tildastatscript')) { statParams.tildastatcode = document.getElementById('tildastatscript').key; } //SCROLL STAT if (isScrollTrack) { try { t_stat__onVisibilityWindowChange(function (visible) { isWindowActive = !!visible; }); document.body.addEventListener( 'mousewheel', t_throttle(function () { isWindowActive = true; }, 1000) ); document.body.addEventListener( 'mousemove', t_throttle(function () { isWindowActive = true; }, 1000) ); document.body.addEventListener( 'keypress', t_throttle(function () { isWindowActive = true; }, 1000) ); document.body.addEventListener( 'click', t_throttle(function () { isWindowActive = true; }, 1000) ); } catch (e) { /* */ } } //FINGERPRINT statParams.fingerprint = t_stat__getFingerPrint(); //FLAG inited isInited = true; } function t_stat__pageView(opts) { var staturl = 'https://stat.tildaapi.' + t_stat__getRootZone() + '/event/'; if (!isCookieDisabled) { //RECREATE COOKIE var sessid = t_stat__getCookie('tildasid') || ''; if (sessid != statParams.sessionid) { t_stat__setCookie('tildasid', statParams.sessionid, { expires: 1800, path: '/' }); } } //get previous url if (statParams.referrer === '') { statParams.referrer = t_stat__getCookie('previousUrl') || ''; } statParams.tildautm = t_stat__getCookie('TILDAUTM') || ''; if (!statParams.page) { console.log('TildaStat: page empty'); statParams.page = t_stat__getPageURL(); if (window.location.hash && window.location.hash.indexOf('#!') === 0) { statParams.page += window.location.hash; } } //for events like /tilda/readtime/ adding domain if (statParams.page.substring(0, 1) === '/') { statParams.page = window.location.hostname + statParams.page; } var encodingStat = t_stat__endcodeObj(statParams); var currentPage = t_stat__getPageURL(); if (allRec && (statParams.page === currentPage || statParams.page === currentPage + window.location.hash)) { var postUid = allRec.getAttribute('data-tilda-post-uid'); var productUid = allRec.getAttribute('data-product-uid'); if (!postUid && !productUid) { // каталог 1.2 с фолбэком на 1.1; пустой data-product-uid пропускаем var productSnippet = document.querySelector( '.t-catalog__product-snippet[data-product-uid]:not([data-product-uid=""]),' + '.t-store__product-snippet[data-product-uid]:not([data-product-uid=""])' ); productUid = productSnippet && productSnippet.getAttribute('data-product-uid'); } if (postUid) { encodingStat += '&postuid=' + encodeURIComponent(postUid); } else if (productUid) { encodingStat += '&productuid=' + encodeURIComponent(productUid); } } var xhr = new XMLHttpRequest(); xhr.open('POST', staturl, true); xhr.withCredentials = false; // xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xhr.onerror = function (data) { console.error('TildaStat: fail pageview '); console.error(data); }; xhr.timeout = 3000; xhr.send(encodingStat); if ( statParams.page && statParams.page.indexOf('tilda/scroll') === -1 && statParams.page.indexOf('tilda/readtime') === -1 && statParams.page.indexOf('tilda/click') === -1 && statParams.page.indexOf('tilda/cookieenabled') === -1 ) { statParams.referrer = statParams.page; if (!isCookieDisabled) { t_stat__setCookie('previousUrl', statParams.page, { path: '/', expires: 1800 }); } } statParams.page = ''; //??? window.tildastatload = true; } window.tildastat = function (event, opts) { if (!event) { return false; } if (event !== 'create' && !isInited) { setTimeout(function () { window.tildastat(event, opts); }, 1000); return false; } if (opts) { t_stat__objAssign(statParams, opts); } switch (event) { case 'create': create(opts); break; case 'pageview': t_stat__pageView(opts); break; case 'readtime': if (isScrollTrack) { if (isWindowActive) { statParams.page = '/tilda/readtime/'; isWindowActive = false; t_stat__pageView(opts); } setTimeout(function () { window.tildastat('readtime'); }, 15000); } break; case 'scroll': if (isScrollTrack && typeof t_throttle === 'function') { // try { window.addEventListener( 'scroll', t_throttle(function () { t_stat__trackScrollEvent(); }, 1000) ); // } } break; case 'cookieenabled': isCookieDisabled = false; t_stat__getUIDandSID(); t_stat__setUIDandSID(); statParams.userid = userid; statParams.sessionid = sessionid; statParams.page = '/tilda/cookieenabled/'; t_stat__pageView(opts); break; case 'fingerprint': return t_stat__getFingerPrint(); default: break; } }; //analog of jQuery.param() method function t_stat__endcodeObj(obj) { var str = ''; for (var key in obj) { if (str != '' && typeof obj[key] !== 'object') { str += '&'; } if (typeof obj[key] === 'object') { if (Object.keys(obj[key]).length) { for (var k in obj[key]) { str += '&' + key + '[' + k + ']' + '=' + encodeURIComponent(obj[key][k]); } } } else { str += key + '=' + encodeURIComponent(obj[key]); } } return str; } var statParams = {}; var isSendScrollEvent = { p10: 0, p25: 0, p50: 0, p75: 0, p90: 0 }; // var dStartReadTime = new Date(); var isWindowActive = true; var isCookieDisabled = window['tildastatcookie'] === 'no'; if (!window['tildastatcookie']) { if (allRec) { isCookieDisabled = allRec.getAttribute('data-tilda-cookie') === 'no'; } } if (window['tildastatcookiegdpr'] === 'yes' && isCookieDisabled === false) { isCookieDisabled = true; var cookiesConsent = t_stat__getCookie('t_cookiesConsentGiven'); if (cookiesConsent === true) { var cookiesCategories = t_stat__getCookie('t_cookiesCategories'); if (typeof cookiesCategories === 'string' && cookiesCategories.indexOf('analytics') > -1) { isCookieDisabled = false; } } } //console.log(isCookieDisabled); var isScrollTrack = window['tildastatscroll'] === 'yes'; if (typeof window['tildastatscroll'] == 'undefined') { if (allRec) { isScrollTrack = allRec.getAttribute('data-tilda-stat-scroll') === 'yes'; } } var userid = ''; var sessionid = ''; var isInited = false; window.tildastat('create'); setTimeout(function () { window.tildastat('pageview'); window.tildastat('readtime'); window.tildastat('scroll'); }, 500); //load script to handle errors var errorScriptID = setInterval(function () { if ( (typeof window.t_jserrors === 'object' && window.t_jserrors.length > 0) || (typeof window.t_cdnerrors === 'object' && window.t_cdnerrors.length > 0) || (typeof window.t_ajaxerrors === 'object' && window.t_ajaxerrors.length > 0) ) { if (typeof t_errors__sendJSErrors !== 'function') { var s = document.createElement('script'); s.src = 'https://static.tildacdn.' + t_stat__getRootZone() + '/js/tilda-errors-1.0.min.js'; s.async = true; document.body.appendChild(s); clearInterval(errorScriptID); } } }, 2000); // check is export project var icon = document.querySelector("link[rel*='shortcut icon']"); var links = document.querySelectorAll("link[href*='tilda.ws/project']").length; if (!links) links = document.querySelectorAll("link[href*='ws.tildacdn.com/project']").length; var iconHref = icon ? icon.getAttribute('href') : ''; var tildaScripts = document.querySelector("script[src*='js/tilda-scripts']"); var isExported = tildaScripts ? tildaScripts.src.indexOf('tildacdn') === -1 : false; if (!isExported) { isExported = icon && iconHref.indexOf('static.tildacdn.' + t_stat__getRootZone()) !== -1 && iconHref.indexOf('tilda.') !== -1 && iconHref.indexOf('/tildafavicon.ico') !== -1 && !document.querySelector('table#allrecords') && !(window.location.hostname.indexOf('.tilda.ws') !== -1) && !links; } // append performance script to the page, which measure page speed params, like // FP - first paint // FCP - first contentful paint // LCP - largest contentful paint // DOMloaded if (typeof navigator.sendBeacon !== 'undefined' && !/Bot/i.test(navigator.userAgent) && !isExported) { var randomValue = Math.floor(Math.random() * 5); if (randomValue === 1) { t_stat__onLoad(function () { var performanceScript = document.createElement('script'); performanceScript.async = true; performanceScript.type = 'text/javascript'; performanceScript.src = 'https://static.tildacdn.' + t_stat__getRootZone() + '/js/tilda-performance-1.0.min.js'; document.body.insertAdjacentElement('beforeend', performanceScript); }); } } function t_stat__onLoad(callback) { document.readyState === 'complete' ? callback() : window.addEventListener('load', callback); } function t_stat__getRootZone() { const allrecords = document.getElementById('allrecords'); const rootZone = allrecords && allrecords.getAttribute('data-tilda-root-zone'); return rootZone || 'com'; } })();