UNPKG

@ra5mus/eb-comscore

Version:

Convenience wrapper for comscore functionality

2 lines 8.76 kB
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=e,n.c=t,n.p="",n(0)}([function(e,n,t){!function(e){var n=function(n){var t,r,o,c,i,s="comScore=",a=document,d=a.cookie,l="",f="indexOf",u="substring",m="length",h=2048,p="&ns_",g="&",y=e,v=y.encodeURIComponent||escape;if(d[f](s)+1)for(c=0,o=d.split(";"),i=o[m];i>c;c++)r=o[c][f](s),r+1&&(l=g+unescape(o[c][u](r+s[m])));n+=p+"_t="+ +new Date+p+"c="+(a.characterSet||a.defaultCharset||"")+"&c8="+v(a.title)+l+"&c7="+v(a.URL)+"&c9="+v(a.referrer),n[m]>h&&n[f](g)>0&&(t=n[u](0,h-8).lastIndexOf(g),n=(n[u](0,t)+p+"cut="+v(n[u](t+1)))[u](0,h)),a.images?(r=new Image,y.ns_p||(ns_p=r),r.src=n):a.write("<","p","><",'img src="',n,'" height="1" width="1" alt="*"',"><","/p",">")},t=t||{comscoreString:"",onclickString:"",eventSent:!1,eventsAdded:!1,didScroll:!1,staybeating:!1,scrollListenerTime:150,pulseTime:2e3,flatline:18e4};if("undefined"==typeof t.initializeComscore&&(t.initializeComscore=function(e,n,r,o,c){try{if(t.comscoreString+="c1="+encodeURIComponent("2")+"&",t.comscoreString+="c2="+encodeURIComponent(e)+"&",t.comscoreString+="ns_site="+encodeURIComponent(n)+"&",t.comscoreString+="ns_vsite="+encodeURIComponent(r)+"&",t.comscoreString+="ns_sub_vsite="+encodeURIComponent(o)+"&","undefined"!=typeof c)for(var i in c)""!==c[i]&&(t.comscoreString+=i+"="+encodeURIComponent(c[i])+"&")}catch(s){console.error(s)}}),"undefined"==typeof t.sendComscorePageview&&(t.sendComscorePageview=function(e){try{var n="";if("undefined"!=typeof e)for(var r in e)""!==e[r]&&(n+=r+"="+encodeURIComponent(e[r])+"&");t.sendComscore(n)}catch(o){console.error(o)}}),"undefined"==typeof t.sendComscoreNonPageview&&(t.sendComscoreNonPageview=function(e){try{var n="ns_type=hidden&";if("undefined"!=typeof e)for(var r in e)""!==e[r]&&(n+=r+"="+encodeURIComponent(e[r])+"&");t.sendComscore(n)}catch(o){console.error(o)}}),"undefined"==typeof t.comscoreBaseUrl&&(t.comscoreBaseUrl=function(){return"http"+("s"==document.location.href.charAt(4)?"s://sb":"://b")+".scorecardresearch.com/b?"}),"undefined"==typeof t.sendComscore&&(t.sendComscore=function(e){try{var r=e||"";r+=t.comscoreString;var o=/Firefox[\/\s](\d+)/.test(navigator.userAgent);o?setTimeout(function(){n(t.comscoreBaseUrl()+r)},0):n(t.comscoreBaseUrl()+r),localStorage.setItem("ebComscoreString",r)}catch(c){console.error(c)}}),"undefined"==typeof t.addEvent&&(t.addEvent=function(n,t,r){try{n.addEventListener?n.addEventListener(t,r,!1):n.attachEvent("on"+t,function(){try{return r.call(n,e.event)}catch(t){console.error(t)}})}catch(o){console.error(o)}}),"undefined"==typeof t.getBannerInfo&&(t.getBannerInfo=function(e){try{for(var n="",r=t.banners,o=t.banners.length,c=o;c--;){var i=r[c],s=i.beating===!0?(new Date).getTime()-i.firstSign:i.ebInViewTime;n+=0!==i.ebScrollDepth?"l_scrdep_"+i.campaignId+"="+i.ebScrollDepth+"&":"",n+=0!==s?"l_rdtime_"+i.campaignId+"="+s+"&":"",n+=0!==s||0!==i.ebScrollDepth?"l_bheight_"+i.campaignId+"="+i.bannerheight+"&":""}return n}catch(a){return""}}),"undefined"==typeof t.setCookie&&(t.setCookie=function(e,n,t){console.log(e,n,t);try{var r=new Date;r.setTime(r.getTime()+24*t*60*60*1e3);var o="expires="+r.toUTCString();document.cookie=e+"="+n+"; "+o}catch(c){console.log(c)}},t.getCookie=function(e){try{for(var n=e+"=",t=document.cookie.split(";"),r=0;r<t.length;r++){for(var o=t[r];" "==o.charAt(0);)o=o.substring(1);if(-1!=o.indexOf(n))return o.substring(n.length,o.length)}return""}catch(c){console.log(c)}}),"undefined"==typeof t.finalAssembly&&(t.finalAssembly=function(e,n){try{var r=n||t.onclickString;if(t.eventSent===!1){var o=("beforeunload"===e.type||"pagehide"===e.type||"unload"===e.type)&&""!==r||""!==r;if("undefined"!=typeof t.banners){var c=t.getBannerInfo();""!==c&&(r+=c,r+="ns_type=hidden&",o=!0)}o&&(t.eventSent=!0,r+="l_event="+e.type+"&",t.sendComscore(r))}}catch(i){console.error(i)}}),"undefined"==typeof t.scriller&&(t.scriller=function(e){try{t.didScroll=!0}catch(n){console.error(n)}}),"undefined"==typeof t.listener&&(t.listener=function(){try{t.resetBanners(),t.scrollListener=setInterval(function(){try{"undefined"!=typeof t.banners&&t.didScroll===!0&&(t.didScroll=!1,t.shouldListen())}catch(e){console.error(e)}},t.scrollListenerTime)}catch(e){console.error(e)}},t.shouldListen=function(){try{for(var e=t.banners.length;e--;){var n=t.banners[e],r=n.banner,o=r.getBoundingClientRect().top;o<n.startPos&&o>n.endPos?n.beating===!1&&t.heartBeat(n,"start"):n.beating===!0&&t.heartBeat(n,"stop"),o<t.viewPort&&n.drowned===!1&&t.setScrollDepth(n,o)}}catch(c){console.error(c)}}),"undefined"==typeof t.resetBanners&&(t.resizer=function(){try{t.didResize=!0}catch(e){console.error(e)}},t.resizeListener=setInterval(function(){try{"undefined"!=typeof t.banners?t.didResize===!0&&(t.didResize=!1,t.resetBanners()):clearInterval(t.resizeListener)}catch(e){console.error(e)}},t.scrollListenerTime),t.resetBanners=function(){try{if("undefined"!=typeof t.banners){for(var e=t.banners,n=t.banners.length,r=n;r--;){var o=e[r];o.bannerheight=o.banner.clientHeight,o.whereYouWere=o.banner.getBoundingClientRect().top,o.testForPos=o.whereYouWere<=-o.bannerheight,o.startPos=Math.round(t.viewPort-o.bannerheight/2),o.endPos=Math.round(-(o.bannerheight/2))}t.shouldListen()}}catch(c){console.error(c)}}),"undefined"==typeof t.setScrollDepth&&(t.setScrollDepth=function(e,n){try{var r=t.viewPort-Math.round(n),o=r/e.bannerheight*100;e.testForPos===!1?(o>25&&50>o?depth=25:o>50&&75>o?depth=50:o>75&&100>o?depth=75:o>=100?(depth=100,e.drowned=!0):depth=0,e.ebScrollDepth=depth):e.testForPos=!1}catch(c){console.error(c)}}),"undefined"==typeof t.heartBeat&&(t.heartBeat=function(e,n){try{"start"===n?(e.resurrect===!0&&(e.firstView=e.ebInViewTime),e.firstSign=(new Date).getTime(),pulse=0,t.staybeating&&(e.beat=setInterval(function(){try{e.ebInViewTime=e.ebInViewTime+t.pulseTime,pulse++,2e3*pulse===t.flatline&&clearInterval(e.beat)}catch(n){console.error(n)}},t.pulseTime)),e.beating=!0):"stop"===n&&(t.staybeating&&clearInterval(e.beat),rightNow=(new Date).getTime()-e.firstSign,e.ebInViewTime=e.resurrect?e.firstView+rightNow:rightNow,e.beating=!1,e.resurrect=!0)}catch(r){console.error(r)}}),t.addToComscoreScroll=function(e){try{this.init(e)}catch(n){console.error(n)}},t.addToComscoreScroll.prototype={init:function(n){try{var r=this;t.banners=t.banners||[],t.viewPort=Math.max(document.documentElement.clientHeight,e.innerHeight||0),n.banner=document.getElementById(n.elid),n.scrollDepth=0,n.inViewTime=0,n.ebScrollDepth=0,n.drowned=!1,n.ebInViewTime=0,n.beating=!1,r.obj=n,t.banners.push(n)}catch(o){console.error(o)}}},"undefined"==typeof r)var r=function(e,n,r,o,c,i){try{var s="";if(s+="ns_type=hidden&","undefined"!=typeof r)for(var a in r)""!==r[a]&&(s+=a+"="+encodeURIComponent(r[a])+"&");"undefined"!=typeof c&&""!==c&&(s+=encodeURIComponent(c)),i===!0&&t.setCookie("clickedEkstraHead","true",2),o===!1?(s+="l_event_type="+e.type+"&",t.onclickString=s):o===!0&&(s+="l_event="+e.type+"&",s+="l_inpage=true&",t.sendComscore(s))}catch(d){console.error(d)}};if("undefined"==typeof o)var o=function(e,n,r,o,c){try{var i="",s=document.getElementById(o),a=s.value;i+="ns_type=hidden&",i+="le_type=form&",i+="le_name="+encodeURIComponent(r)+"&",i+="le_label="+encodeURIComponent(a)+"&","undefined"!=typeof c&&""!==c&&(i+="le_pos="+encodeURIComponent(c)+"&"),t.onclickString=i}catch(d){console.error(d)}};"undefined"==typeof t.attachLinkListeners&&(t.attachLinkListeners=function(e){try{var n=document.querySelectorAll("a.trackclick"),o=0;for(o=0;o<n.length;++o){var c=n[o];t.addEvent(c,"click",function(n){console.log("Link clicked: "+c.href),r(n,c,{le_label:c.href},e)}),console.log("attached click handler to "+c)}}catch(i){console.error(i)}}),"undefined"==typeof t.menuTracking&&(t.menuClick=function(e){try{var n=e.target,t=n.getAttribute("data-comscorename"),o=n.innerHTML;r(e,n,{le_name:t,le_label:o},!1)}catch(c){console.error("ebComscore.menuClick ",c)}},t.menuTracking=function(){try{var e=document.getElementById("mainnav"),n=document.getElementById("flyouts"),r=document.getElementById("fnSubWrapper");null!==e&&t.addEvent(e,"click",function(e){t.menuClick(e)}),null!==n&&t.addEvent(n,"click",function(e){t.menuClick(e)}),null!==r&&t.addEvent(r,"click",function(e){t.menuClick(e)})}catch(o){console.error("ebComscore.menuTracking ",o)}}),t.eventsAdded===!1&&(t.addEvent(e,"load",t.listener),t.addEvent(e,"scroll",t.scriller),t.addEvent(e,"resize",t.resizer),t.addEvent(e,"beforeunload",t.finalAssembly),t.addEvent(e,"pagehide",t.finalAssembly),t.addEvent(e,"unload",t.finalAssembly),t.eventsAdded=!0),e.ebComscore=t}(window)}]); //# sourceMappingURL=eb-comscore.js.map