Shoora
10/8/2018 - 5:46 PM

Conversion Tracking Header Script

Conversion Tracking Header Script

<script>
window.tnServices=window.tnServices||{},window.tnServices.each=function(n,e){if(null!=n.length)for(var t=0;t<n.length;t++)e(t,n[t]);else for(var i in n)n.hasOwnProperty(i)&&e(i,n[i])},window.tnServices.getQueryString=function(){return window.location.search.substring(1)},window.tnServices.splitParamsToHash=function(n){for(var e={},t=n.split("&"),i=0;i<t.length;i++){var o=t[i].split("=");e[o[0]]=decodeURIComponent(o[1])}return e},window.tnServices.queryParams=function(){var n=window.tnServices.getQueryString();return window.tnServices.splitParamsToHash(n)}(),window.tnServices.constructUrl=function(n,e){var t="?";return window.tnServices.each(e,function(n,e){t+=encodeURIComponent(n)+"="+encodeURIComponent(e)+"&"}),n+t},window.tnServices.loadImage=function(n,e,t){var i=document.createElement("img");i.src=window.tnServices.constructUrl(n,e),document.body.appendChild(i),i.onload=function(){t()},i.onerror=function(){t()}},window.tnServices.getCookieString=function(){return document.cookie},window.tnServices.getCurrentTime=function(){return(new Date).getTime()},window.tnServices.loadConversion=function(n,e,t){window.tnServices.loadImage("http://pixel.thinknearhub.com/conversions",{t:n,a:e},t)},window.tnServices.getDataName=function(n){return n.parentNode.getAttribute("data-name")||n.getAttribute("data-name")},window.tnServices.redirectTo=function(n){window.location.href=n},window.tnServices.submit=function(n){n.submit()},window.tnServices.alert=function(n){alert(n)},window.tnServices.writeCookie=function(n,e,t){document.cookie=n+"="+e+";expires="+t.toGMTString()+";path=/"},window.tnServices.getCookiesFor=function(n){if(document.cookie){var e=document.cookie,t=e.indexOf(n+"=");if(t>=0){var i=e.indexOf(";",t);-1==i&&(i=e.length),token=e.substring(t,i);var o=token.split("=");if(o.length>1)return o[1]}return null}},window.tnServices.ThirdPartyClickTracking=function(){var n=function(n){var e=document.createEvent("MouseEvents");e.initEvent("click",!0,!0),allowDefaultAction=n.dispatchEvent(e),allowDefaultAction&&n.href&&tnServices.redirectTo(n)},e=function(n){var e=!0,t=setTimeout(function(){e=!1,n()},4e3);tnServices.loadConversion(tnServices.queryParams.token,"third_party_conversion",function(){t&&clearTimeout(t),e&&n()})},t=function(n,t,i){tnServices.each(n,function(n,o){var r=!0,c=o[t];o[t]=function(){return r?(r=!1,e(function(){i(o)}),!1):c?c():void 0}})},i=function(n,t){tnServices.each(n,function(n,i){i.addEventListener(t,function(){e(function(){})})})};return{trackConversion:t,trackConversionAjax:i,clickRedirect:n}}(),window.addEventListener("load",function(){tnServices.queryParams.token&&setTimeout(function(){var n=tnServices.ThirdPartyClickTracking.trackConversion,e=tnServices.ThirdPartyClickTracking.trackConversionAjax;n(document.getElementsByTagName("a"),"onclick",function(n){tnServices.ThirdPartyClickTracking.clickRedirect(n)}),n(document.getElementsByClassName("tn-form-conversion"),"onsubmit",function(n){tnServices.submit(n)}),e(document.getElementsByClassName("tn-form-conversion-ajax"),"submit"),n(document.getElementsByClassName("tn-conversion"),"onclick",function(n){tnServices.ThirdPartyClickTracking.clickRedirect(n)})},100)});
	</script>