-
Notifications
You must be signed in to change notification settings - Fork 89
/
lunametrics-youtube.gtm.min.js
18 lines (18 loc) · 4.06 KB
/
lunametrics-youtube.gtm.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
!function(a,b,c){"use strict";function d(){"loading"!==a.readyState?e():"addEventListener"in a?p(a,"DOMContentLoaded",e):p(b,"load",e)}function e(){f(q("iframe").concat(q("embed"))),"addEventListener"in a&&a.addEventListener("load",r,!0)}function f(a){var b;for(b=0;b<a.length;b++){if(g(a[b])){k(j(a[b]))}}}function g(a){var b=a.src||"",c=a.getAttribute("data-src")||"";return b.indexOf("youtube.com/embed/")>-1||b.indexOf("youtube.com/v/")>-1||c.indexOf("youtube.com/embed/")>-1||c.indexOf("youtube.com/v/")>-1}function h(a){return a.indexOf("enablejsapi")>-1}function i(a){return a.indexOf("origin")>-1}function j(c){var d=b.location,e=a.createElement("a");e.href=c.getAttribute("data-src")||c.src;var f="/"===e.pathname.charAt(0)?e.pathname:"/"+e.pathname;if(h(e.search)||(e.search=(e.search.length>0?e.search+"&":"")+"enablejsapi=1"),!i(e.search)&&d.hostname.indexOf("localhost")===-1){var g=d.port?":"+d.port:"",j=d.protocol+"%2F%2F"+d.hostname+g;e.search=e.search+"&origin="+j}if("application/x-shockwave-flash"===c.type){var k=a.createElement("iframe");k.height=c.height,k.width=c.width,f=f.replace("/v/","/embed/"),c.parentNode.parentNode.replaceChild(k,c.parentNode),c=k}return e.pathname=f,c.src!==e.href+e.hash&&(c.src=e.href+e.hash),c}function k(a){var b=YT.get(a.id);b||(b=new YT.Player(a,{})),void 0===a.pauseFlag&&(a.pauseFlag=!1,b.addEventListener("onStateChange",function(b){n(b,a)}))}function l(a){var b={};if(v.events["Watch to End"]&&(b["Watch to End"]=Math.min(a-3,Math.floor(.99*a))),v.percentageTracking){var c,d=[];if(v.percentageTracking.each&&(d=d.concat(v.percentageTracking.each)),v.percentageTracking.every){var e=parseInt(v.percentageTracking.every,10),f=100/e;for(c=1;c<f;c++)d.push(c*e)}for(c=0;c<d.length;c++){var g=d[c],h=g+"%",i=a*g/100;b[h]=Math.floor(i)}}return b}function m(a,b,c){var d,e=a.getCurrentTime();a[c]=a[c]||{};for(d in b)b[d]<=e&&!a[c][d]&&(a[c][d]=!0,o(c,d))}function n(a,b){var c=a.data,d=a.target,e=d.getVideoUrl(),f=e.match(/[?&]v=([^&#]*)/)[1],g=d.getPlayerState(),h=Math.floor(d.getDuration()),i=l(h),j={1:"Play",2:"Pause"},k=j[c];if(b.playTracker=b.playTracker||{},1!==g||b.timer?(clearInterval(b.timer),b.timer=!1):(clearInterval(b.timer),b.timer=setInterval(function(){m(d,i,b.videoId)},1e3)),1===c&&(b.playTracker[f]=!0,b.videoId=f,b.pauseFlag=!1),!b.playTracker[b.videoId])return!1;if(2===c){if(b.pauseFlag)return!1;b.pauseFlag=!0}y[k]&&o(b.videoId,k)}function o(a,c){var d="https://www.youtube.com/watch?v="+a,e=b.GoogleAnalyticsObject;void 0===b[x]||v.forceSyntax?"function"==typeof b[e]&&"function"==typeof b[e].getAll&&2!==v.forceSyntax?b[e]("send","event","Videos",c,d):void 0!==b._gaq&&1!==w&&b._gaq.push(["_trackEvent","Videos",c,d]):b[x].push({event:"youTubeTrack",attributes:{videoUrl:d,videoAction:c}})}function p(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,function(b){b.target=b.target||b.srcElement,c.call(a,b)}):void 0!==a["on"+b]&&null!==a["on"+b]||(a["on"+b]=function(b){b.target=b.target||b.srcElement,c.call(a,b)})}function q(b){return[].slice.call(a.getElementsByTagName(b))}function r(a){var b=a.target||a.srcElement,c=g(b);"IFRAME"===b.tagName&&c&&h(b.src)&&i(b.src)&&k(b)}if(!navigator.userAgent.match(/MSIE [67]\./gi)){var s,t,u,v=c||{},w=v.forceSyntax||0,x=v.dataLayerName||"dataLayer",y={Play:!0,Pause:!0,"Watch to End":!0};for(u in v.events)v.events.hasOwnProperty(u)&&(y[u]=v.events[u]);b.YT?d():(t=a.createElement("script"),t.src="//www.youtube.com/iframe_api",s=a.getElementsByTagName("script")[0],s.parentNode.insertBefore(t,s),b.onYouTubeIframeAPIReady=function(a){return function(){a&&a.apply(this,arguments),d()}}(b.onYouTubeIframeAPIReady))}}
(document, window, {
events: {
Play: true,
Pause: true,
"Watch to End": true
},
percentageTracking: {
every: 25,
each: [10, 90]
}
});/*
* v8.1.4
* Created by the Google Analytics consultants at http://www.lunametrics.com
* Written by @SayfSharif and @notdanwilkerson
* Documentation: https://github.com/lunametrics/youtube-google-analytics/
* Licensed under the Creative Commons 4.0 Attribution Public License
*/