dusanmiha

HTML 5 Video Tracking for Publishers - Nova

Aug 19th, 2020
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     (function(){var _AS_GAID_PROPERTY="UA-156843553-1";var _asCalledEmbedScript=false;var _asEmbedGtagScript=function(){var _asHead=document.getElementsByTagName("head")[0];var _asAddedGtagScript=document.createElement("script");_asAddedGtagScript.type="text/javascript";_asAddedGtagScript.src="https://www.googletagmanager.com/gtag/js";_asAddedGtagScript.defer=true;_asHead.appendChild(_asAddedGtagScript);_asCalledEmbedScript=true;window.dataLayer=window.dataLayer||[];var gtag=
  3.     function(){dataLayer.push(arguments)};window.gtag=gtag;gtag("js",new Date)};var _asCheckForTrackers=setInterval(function(){var _asTrackerLoaded=window.gtag;if(_asTrackerLoaded){clearInterval(_asCheckForTrackers);_asInitiateVideoTracking()}else if(!_asCalledEmbedScript)_asEmbedGtagScript()},200);setTimeout(function(){clearInterval(_asCheckForTrackers)},1E4);var _asInitiateVideoTracking=function(){var _asSendHit=function(){var _asDestintationProperty=_AS_GAID_PROPERTY;var _asTrackerNameSet=false;if(window.dataLayer&&
  4.    window.dataLayer.length>0){var _asConfigSet=window.dataLayer.filter(function(dl){return dl[0]==="config"&&dl[1]===_asDestintationProperty});_asTrackerNameSet=_asConfigSet[0]!==undefined}if(!_asTrackerNameSet)gtag("config",_asDestintationProperty,{"send_page_view":false});return function(_asData){if(_asData.videoTitle==="not set")return;var _asThereIsHitValue=_asData.hitValue;var _asHitObject;if(_asThereIsHitValue)_asHitObject={"event_category":"NTG Video","event_label":_asData.videoTitle,"value":_asData.hitValue,
  5.     "send_to":_asDestintationProperty,"non_interaction":_asData.nonInteraction};else _asHitObject={"event_category":"NTG Video","event_label":_asData.videoTitle,"send_to":_asDestintationProperty,"non_interaction":_asData.nonInteraction};gtag("event",_asData.eventType,_asHitObject)}}();function _asExtendFunctions(_asObj,_asMethods){for(var _asKey in _asMethods)_asObj[_asKey]=_asMethods[_asKey]}var _asVideoObjectAdditions={setMilestones:function(){var _this=this;var checkForMilestones=window.setInterval(function(){if(!isNaN(_this._asData.videoLength)){var _asVidLength=
  6.     _this._asData.videoLength;_this._asData.milestones=_this._asData.milestones.map(function(milestone){return milestone/100*_asVidLength});window.clearInterval(checkForMilestones)}},200,_this)},setVideoTitle:function(){this._asData.videoTitle=this.title||decodeURIComponent(this.currentSrc.split("/")[this.currentSrc.split("/").length-1])},setVideoLength:function(){var _this=this;var checkVidLength=window.setInterval(function(){if(isNaN(_this._asData.videoLength))_this._asData.videoLength=Math.round(_this.duration);
  7.     else window.clearInterval(checkVidLength)},200,_this)},setAutoplay:function(){this._asData.autoplay=this.autoplay},getCurrentTime:function(){return Math.round(this.currentTime)},isVideo:function(){return this&&this.nodeName==="VIDEO"},_vidLoaded:function(){if(this._asData.vidLoaded)return;this._asData.vidLoaded=true;this.setAutoplay();this.setVideoTitle();this._asData.videoLength="not set";this.setVideoLength();this._asData.milestones=[25,50,75];this.setMilestones();this._asData.justMuted=this.muted;
  8.     this._sendHit("player loaded",true);this._asData.justFinished=false},_vidPlay:function(){if(_asDebounceSeek)return;var _this=this;window.setTimeout(function(){if(_asDebounceSeek)return;if(!_this._asData.vidLoaded){_this._vidLoaded();_this._vidPlay()}else{if(_this._asData.justFinished)_this._asData.justFinished=false;var _asPlay=_this._asData.firstPlay?["initial click to play","autoplay"]:"resume";if(_asPlay.length===2){_this._asData.firstPlay=false;_this._asData.autoplay?_this._sendHit(_asPlay[1],
  9.     true):_this._sendHit(_asPlay[0],false)}else _this._sendHit(_asPlay,false)}},2500,_this)},_vidPause:function(){if(_asDebounceSeek)return;var _this=this;window.setTimeout(function(){if(!_asDebounceSeek&&_this.getCurrentTime()!==_this._asData.videoLength)_this._sendHit("pause",false)},2500,_this)},_vidSeek:function(){if(_asDebounceSeek||this._asData.justFinished)return;_asDebounceSeek=true;window.setTimeout(function(){_asDebounceSeek=false},3E3);this._sendHit("seek",false)},_vidComplete:function(){if(this._asData.milestones.length>
  10.     0)for(var i=0;i<this._asData.milestones.length;i++){var _asMilestone=this._asData.milestones[i];var _asCurrentPercent=_asMilestone/this._asData.videoLength*100;if(!Number.isNaN(_asCurrentPercent)&&_asCurrentPercent%25===0&&_asCurrentPercent>0&&_asCurrentPercent<=100){this._asData.hitValue=_asCurrentPercent;this._sendHit(decodeURIComponent(encodeURIComponent("milestone "+_asCurrentPercent+"%")),true)}}this._asData.hitValue=100;this._sendHit("complete",true);this._asData.milestones=[25,50,75];this.setMilestones();
  11.     this._asData.justFinished=true;this._asData.firstPlay=true;this._asData.autoplay=false},_vidMilestones:function(){if(_asDebounceMilestone)return;_asDebounceMilestone=true;setTimeout(function(){_asDebounceMilestone=false},2E3);if(!this._asData.vidLoaded)this._vidPlay();if(this.currentTime<this._asData.milestones[0]||this._asData.milestones.length===0)return;var _asTime=this.currentTime;var _asMilestone;do{_asMilestone=this._asData.milestones.splice(0,1)[0];if(this._asData.firstPlay){this._sendHit("autoplay",
  12.    true);this._asData.firstPlay=false}}while(_asMilestone>_asTime);var _asCurrentPercent=_asMilestone/this._asData.videoLength*100;if(!Number.isNaN(_asCurrentPercent)&&_asCurrentPercent%25===0&&_asCurrentPercent>0&&_asCurrentPercent<=100){this._asData.hitValue=_asCurrentPercent;this._sendHit(decodeURIComponent(encodeURIComponent("milestone "+_asCurrentPercent+"%")),true)}},_vidMuted:function(){if(this.muted||this.volume===0){if(!this._asData.justMuted){this._asData.justMuted=true;this._sendHit("mute",
  13.     false)}}else if(this._asData.justMuted){this._asData.justMuted=false;this._sendHit("unmute",false)}},_vidFullScreen:function(){if(document.fullscreenElement||document.mozFullScreen||document.webkitIsFullScreen||document.msFullscreenElement||document.fullScreen)this._sendHit("full screen",false)},_sendHit:function(ev,ni){this._asData.eventType=ev;this._asData.hitValue=ev.match(/milestone|complete/i)?this._asData.hitValue:null;this._asData.nonInteraction=ni;_asSendHit(this._asData)},setListeners:function(){this.addEventListener("play",
  14.     function(){this._vidPlay()},true);this.addEventListener("pause",function(){this._vidPause()},true);this.addEventListener("seeked",function(){this._vidSeek()},true);this.addEventListener("ended",function(){this._vidComplete()},true);this.addEventListener("timeupdate",function(){this._vidMilestones()},true);this.addEventListener("volumechange",function(){this._vidMuted()},true);this.addEventListener("fullscreenchange",function(){this._vidFullScreen()},true);this.addEventListener("webkitfullscreenchange",
  15.     function(){this._vidFullScreen()},true);this.addEventListener("mozfullscreenchange",function(){this._vidFullScreen()},true);this.addEventListener("msfullscreenchange",function(){this._vidFullScreen()},true)}};function _asProcessVideos(_asVideo){_asVideo._asData={eventType:"not set",videoTitle:"not set",videoPlayer:"html5",videoLength:"not set",milestones:[25,50,75],autoplay:"not set",firstPlay:true,justSeeked:false,justFinished:false,justMuted:false,nonInteraction:null,vidLoaded:false,hitValue:0};
  16.     _asExtendFunctions(_asVideo,_asVideoObjectAdditions);_asVideo._vidLoaded();_asVideo.setListeners()}function _asInfiniteScrollGetVids(){function getdocheight(){var b=document.body,e=document.documentElement;return document.height||Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.offsetHeight,e.offsetHeight),Math.max(b.clientHeight,e.clientHeight))}var _asMaxHeight=getdocheight();window.setInterval(function(){var _asBufferHeight=100;var _asCurrentHeight=Math.max(_asMaxHeight,getdocheight());
  17.     if(_asCurrentHeight>_asMaxHeight+_asBufferHeight){_asMaxHeight=_asCurrentHeight;for(var i=0;i<_asVideos.length;i++)if(!_asVideos[i]._asData)_asProcessVideos(_asVideos[i])}},3E3)}var _asDebounceSeek=false;var _asDebounceMilestone=false;var _asVideos;var _asCheckForVideos=setInterval(function(){_asVideos=document.getElementsByTagName("video");if(_asVideos.length>0){clearInterval(_asCheckForVideos);Array.prototype.map.call(_asVideos,_asProcessVideos)}},500);setTimeout(function(){clearInterval(_asCheckForVideos)},
  18.     1E4);setTimeout(function(){_asInfiniteScrollGetVids()},5E3)}})();
  19. </script>
RAW Paste Data