Free javascript Hosting


lunametrics-youtube-gtm-min.js

Uploaded on May 06 2022 10:27 by sagarh2006

!function(e,a,t){"use strict";function r(){var a=e.getElementsByTagName("iframe"),t=e.getElementsByTagName("embed");n(a),n(t)}function n(e){var a;for(a=0;a<e.length;a++){var t=o(e[a]);if(t){var r=c(e[a]);i(r)}}}function o(e){var a=e.src||"";return a.indexOf("youtube.com/embed/")>-1||a.indexOf("youtube.com/v/")>-1}function c(t){var r=e.createElement("a");r.href=t.src,r.hostname="www.youtube.com",r.protocol=e.location.protocol;var n="/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname,o=a.location.protocol+"%2F%2F"+a.location.hostname+(a.location.port?":"+a.location.port:"");if(-1===r.search.indexOf("enablejsapi")&&(r.search=(r.search.length>0?r.search+"&":"")+"enablejsapi=1"),-1===r.search.indexOf("origin")&&-1===a.location.hostname.indexOf("localhost")&&(r.search=r.search+"&origin="+o),"application/x-shockwave-flash"===t.type){var c=e.createElement("iframe");c.height=t.height,c.width=t.width,n=n.replace("/v/","/embed/"),t.parentNode.parentNode.replaceChild(c,t.parentNode),t=c}return r.pathname=n,t.src!==r.href+r.hash&&(t.src=r.href+r.hash),t}function i(e){e.pauseFlag=!1,new YT.Player(e,{events:{onStateChange:function(a){f(a,e)}}})}function u(e){var a={};if(p.events["Watch to End"]&&(a["Watch to End"]=99*e/100),p.percentageTracking){var t,r=[];if(p.percentageTracking.each&&(r=r.concat(p.percentageTracking.each)),p.percentageTracking.every){var n=parseInt(p.percentageTracking.every,10),o=100/n;for(t=1;o>t;t++)r.push(t*n)}for(t=0;t<r.length;t++){var c=r[t],i=c+"%",u=e*c/100;a[i]=Math.floor(u)}}return a}function s(e,a,t){var r=(e.getDuration(),e.getCurrentTime());e.getPlaybackRate();e[t]=e[t]||{};var n;for(n in a)a[n]<=r&&!e[t][n]&&(e[t][n]=!0,l(t,n))}function f(e,a){var t=e.data,r=e.target,n=r.getVideoUrl(),o=n.match(/[?&]v=([^&#]*)/)[1],c=r.getPlayerState(),i=r.getDuration(),f=u(i),h={1:"Play",2:"Pause"},p=h[t];if(a.playTracker=a.playTracker||{},1!==c||a.timer?(clearInterval(a.timer),a.timer=!1):(clearInterval(a.timer),a.timer=setInterval(function(){s(r,f,a.videoId)},1e3)),1===t&&(a.playTracker[o]=!0,a.videoId=o,a.pauseFlag=!1),!a.playTracker[a.videoId])return!1;if(2===t){if(a.pauseFlag)return!1;a.pauseFlag=!0}d[p]&&l(a.videoId,p)}function l(e,t){var r="https://www.youtube.com/watch?v="+e,n=a.GoogleAnalyticsObject;"undefined"==typeof a[g]||p.forceSyntax?"function"==typeof a[n]&&"function"==typeof a[n].getAll&&2!==p.forceSyntax?(a[n]("mofuseTracker.send","event","YouTube",t,r),a[n]("send","event","YouTube",t,r)):"undefined"!=typeof a._gaq&&1!==v&&a._gaq.push(["_trackEvent","YouTube",t,r]):a[g].push({event:"youTubeTrack",attributes:{videoUrl:r,videoAction:t}})}a.onYouTubeIframeAPIReady=function(){var e=a.onYouTubeIframeAPIReady;return function(){e&&e.apply(this,arguments),navigator.userAgent.match(/MSIE [67]\./gi)||r()}}();var h,p=t||{},v=p.forceSyntax||0,g=p.dataLayerName||"dataLayer",d={Play:!0,Pause:!0,"Watch to End":!0};for(h in p.events)p.events.hasOwnProperty(h)&&(d[h]=p.events[h]);var m=e.createElement("script");m.src="//www.youtube.com/iframe_api";var y=e.getElementsByTagName("script")[0];y.parentNode.insertBefore(m,y)}(document,window,{events:{Play:!0,Pause:!0,"Watch to End":!0},percentageTracking:{every:25,each:[10,90]}});

Back to list