(function(){ var s = document.currentScript; if (!s || !/\/sonda\/js/.test(s.src || '')) { var all = document.getElementsByTagName('script'); for (var i = all.length - 1; i >= 0; i--) { if (all[i].src && all[i].src.indexOf('/sonda/js') > -1) { s = all[i]; break; } } } var SITE = (s && s.getAttribute('data-qo-site')) || 'web'; var CTX = (s && s.getAttribute('data-qo-ctx')) || ''; var PAIS = (s && s.getAttribute('data-qo-pais')) || ''; var UF = (s && s.getAttribute('data-qo-uf')) || ''; var BASE = (s && s.src) ? s.src.replace(/\/sonda\/js.*$/, '') : ''; var HIT = BASE + '/sonda/e'; function uid(){ return Date.now().toString(36) + Math.random().toString(36).slice(2,10); } var SES; try { SES = sessionStorage.getItem('qo_s'); if(!SES){ SES = uid(); sessionStorage.setItem('qo_s', SES); } } catch(e){ SES = uid(); } var PV = uid(), start = Date.now(), lastSent = 0; function q(n){ var m = location.search.match(new RegExp('[?&]'+n+'=([^&]+)')); return m ? decodeURIComponent(m[1]) : ''; } function send(o){ o.s = SITE; o.ses = SES; var body = JSON.stringify(o); try { if (navigator.sendBeacon){ navigator.sendBeacon(HIT, new Blob([body], {type:'text/plain'})); return; } } catch(e){} try { var x = new XMLHttpRequest(); x.open('POST', HIT, true); x.setRequestHeader('Content-Type','text/plain'); x.send(body); } catch(e){} } send({ t:'pageview', pv:PV, path:location.pathname, title:(document.title||'').slice(0,255), ref:document.referrer.slice(0,255), ctx:CTX, pais:PAIS, uf:UF, us:q('utm_source'), um:q('utm_medium'), uc:q('utm_campaign') }); function beat(){ var d = Math.round((Date.now()-start)/1000); if (d > lastSent){ lastSent = d; send({ t:'dur', pv:PV, dur:d }); } } setInterval(function(){ if (document.visibilityState==='visible') beat(); }, 20000); document.addEventListener('visibilitychange', function(){ if (document.visibilityState==='hidden') beat(); }); window.addEventListener('pagehide', beat); window.qoTrack = function(tipo, data){ data = data || {}; data.t = tipo; data.pv = PV; send(data); }; var Q = window._qo || []; for (var i=0;i0){ window.qoTrack('email', {email:v}); } }); } } if (document.readyState !== 'loading') watchEmail(); else document.addEventListener('DOMContentLoaded', watchEmail); // WooCommerce dispara este evento (jQuery) após adicionar ao carrinho if (window.jQuery){ try { window.jQuery(document.body).on('added_to_cart', function(){ window.qoTrack('add_to_cart', {}); }); } catch(e){} } })();