forked from sanderheilbron/vimeo.ga.js
-
Notifications
You must be signed in to change notification settings - Fork 8
/
vimeo.ga.min.js
1 lines (1 loc) · 2.12 KB
/
vimeo.ga.min.js
1
$(function(){if($("iframe").length){var e=$("iframe"),t=e.attr("src").split("?")[0],n=e.data("progress"),r=e.data("seek"),i=0;if(window.addEventListener){window.addEventListener("message",s,false)}else{window.attachEvent("onmessage",s,false)}function s(e){if(e.origin!=="http://player.vimeo.com"){return}if(typeof _gaq!="undefined"){i=1}else if(typeof window.ga!="undefined"){i=2}if(i==0){return}var n=JSON.parse(e.data);switch(n.event){case"ready":u();break;case"playProgress":f(n.data);break;case"seek":if(r&&!videoSeeking){if(i==1){_gaq.push(["_trackEvent","Vimeo","Skipped video forward or backward",t,undefined,true])}else if(i==2){ga("send","event","Vimeo","Skipped video forward or backward",t)}videoSeeking=true}break;case"play":if(!videoPlayed){if(i==1){_gaq.push(["_trackEvent","Vimeo","Started video",t,undefined,true])}else if(i==2){ga("send","event","Vimeo","Started video",t)}videoPlayed=true}break;case"pause":a();break;case"finish":if(!videoCompleted){if(i==1){_gaq.push(["_trackEvent","Vimeo","Completed video",t,undefined,true])}else if(i==2){ga("send","event","Vimeo","Completed video",t)}videoCompleted=true}break}}function o(n,r){var i={method:n};if(r){i.value=r}e[0].contentWindow.postMessage(JSON.stringify(i),t)}function u(){o("addEventListener","play");o("addEventListener","seek");o("addEventListener","pause");o("addEventListener","finish");o("addEventListener","playProgress");progress25=false;progress50=false;progress75=false;videoPlayed=false;videoPaused=false;videoSeeking=false;videoCompleted=false}function a(){if(timePercentComplete<99&&!videoPaused){if(i==1){_gaq.push(["_trackEvent","Vimeo","Paused video",t,undefined,true])}else if(i==2){ga("send","event","Vimeo","Paused video",t)}videoPaused=true}}function f(e){timePercentComplete=Math.round(e.percent*100);if(!n){return}var r;if(timePercentComplete>24&&!progress25){r="Played video: 25%";progress25=true}if(timePercentComplete>49&&!progress50){r="Played video: 50%";progress50=true}if(timePercentComplete>74&&!progress75){r="Played video: 75%";progress75=true}if(r){if(i==1){_gaq.push(["_trackEvent","Vimeo",r,t,undefined,true])}else if(i==2){ga("send","event","Vimeo",r,t)}}}}})