Created
June 18, 2014 20:25
-
-
Save btrav/301f5e218e5b7fb07698 to your computer and use it in GitHub Desktop.
trackPrettyPhotoYouTube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" language="javascript"> | |
var _gaq = _gaq || []; (function (a) { a.fn.ytGaTrack = function () { var g = []; var c; var f; var i; var b = -1; if (typeof (YT) === "undefined") { a.getScript("http://www.youtube.com/player_api") } return this.each(function () { a(this).click(function () { var m = a(this).attr("href"); var n = h(m); d(m); window.setTimeout(function () { var o = k(n); if (o) { c = new YT.Player(o, { events: { onReady: e, onStateChange: l } }) } }, 1500) }) }); function e() { j(c.getPlayerState()) } function l(m) { j(m.data) } function j(n) { var m = g; switch (n) { case 0: if (!m[b][4]) { _gaq.push(["_trackEvent", "YouTube", "Reach 100%", m[b][0]]); m[b][4] = true } window.clearInterval(f); break; case 1: if (!m[b][5]) { _gaq.push(["_trackEvent", "YouTube", "Start", m[b][0]]); m[b][5] = true } window.clearInterval(f); f = window.setInterval(function () { if (!document.getElementById(i)) { j(2) } else { if (typeof (c.getCurrentTime) !== "undefined") { var o = (c.getCurrentTime() / c.getDuration()) * 100; if (!m[b][1] && o > 25) { _gaq.push(["_trackEvent", "YouTube", "Reach 25%", m[b][0]]); m[b][1] = true } else { if (!m[b][2] && o > 50) { _gaq.push(["_trackEvent", "YouTube", "Reach 50%", m[b][0]]); m[b][2] = true } else { if (!m[b][3] && o > 75) { _gaq.push(["_trackEvent", "YouTube", "Reach 75%", m[b][0]]); m[b][3] = true } } } } } }, 100); break; case 2: if (!m[b][6]) { _gaq.push(["_trackEvent", "YouTube", "Stop", m[b][0]]); m[b][6] = true } window.clearInterval(f); break; default: break } } function d(n) { var m = false; for (var o = 0; o < g.length; o++) { if (g[o][0] === n) { m = true; b = o; break } } if (!m) { g.push([n, false, false, false, false, false, false]); b = g.length - 1 } } function k(n) { var m = a("iframe[src*=" + n + "]"); var n; if (m.attr("id")) { n = m.attr("id") } else { n = "yt-ga-" + n; m.attr("id", n) } i = n; return n; return null } function h(o) { var n = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; var m = o.match(n); if (m && m[2].length === 11) { return m[2] } else { } } } })(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment