If you need to use iframe to display youtube video on your website, tracking starts and pauses via analytics can be easily done.
The main trick is to add enablejsapi=1 into url.
E.g.
<iframe width=”560″ id=”somevideo” height=”315″ src=”https://www.youtube.com/embed/aCpGA7OrwyI?autoplay=1&enablejsapi=1″></iframe></pre>
becomes
<iframe width=”560″ id=”somevideo” height=”315″ src=”https://www.youtube.com/embed/aCpGA7OrwyI?autoplay=1&enablejsapi=1“></iframe></pre>
Now you can easily use the API. Feel free to use following example
<iframe width="560" id="somevideo" height="315" src="https://www.youtube.com/embed/aCpGA7OrwyI?autoplay=1&enablejsapi=1"></iframe></pre> <script> var player; function onYouTubeIframeAPIReady() { player = new YT.Player( 'somevideo', { events: { 'onStateChange': function(state){ if(state.data){ if(state.data == YT.PlayerState.PAUSED){ // paused ga('send', 'event', 'somevideo', 'paused', creativecoffeebreak.getCurrentTime()); } else if(state.data == YT.PlayerState.PLAYING){ if(!playedAlready){ playedAlready = true; ga('send', 'event', 'somevideo', 'start', creativecoffeebreak.getCurrentTime()); } } else if(state.data == YT.PlayerState.ENDED){ ga('send', 'event', 'somevideo', 'finished', creativecoffeebreak.getCurrentTime()); } } } } }); } </script> <script src="https://www.youtube.com/iframe_api"></script>
Please note that the YT.PlayerState.ENDED doesn’t work in almost any browser.
Also, the “PAUSED” event is triggered when fast forwarding as well.
You need to load iframe_api javascript, otherwise the YT object won’t exist.
Webmentions
kamagra canada échantillon gratuit
achat kamagra francaise
koupit kamagra bez lékařského předpisu
kamagra porovnat cenu cvs
itraconazole overnight
how to buy itraconazole price in us
buy cheap fildena buy online no prescription
buy cheap fildena usa pharmacy
online order gabapentin purchase online canada
get gabapentin cheap canadian pharmacy
where to buy dutasteride no prescription no fees
generique dutasteride
buying avodart cheap prices
online order avodart uk over the counter
ordering staxyn uk buy over counter
order staxyn without rx online
discount online xifaxan
buy xifaxan cheap europe
is generic rifaximin from canada
how to order rifaximin usa sales
enclomiphene no doctors consult
cheap enclomiphene buy mastercard
buying androxal generic dosage
cheap androxal australia purchase