Tracking Clicks on YouTube video not working
I implemented the tracking of a embedded YouTube Video iFrame as in https://help.optimizely.com/hc/en-us/articles/204338398 .
First problem was that my iframe was not set before $( document ).ready() but I had to call the api outside of onReady. As a result the onReady Event was not fired. I solved it with the following code:
But the next problem is, that the onStageChange event is not fired what so ever and the custom tracking events are not triggered.
Has anyone a experienced that problem or found a solution?
Thanks for reaching out to Optiverse!
Have you done any modifications to the above mentioned code? If not, please also double-check if the iframe settings are set up correctly. https://help.optimizely.com/hc/en-us/articles/204338398#youtube
I'm looking forward to your reply.
EMEA | Amsterdam
I have two different experiments running, targeting different sites and videos. One remained in the original state and is an exact copy of your help article and within the other experiment I made some changes to see if I find a solution. However the video tracking does not work for both of them.
With the original experiment I don't even get the console.log message:
YouTube player \'' +iframe.attr('id') +'\': ready
The problem seems to be, that I am adding the iframe also within the optimizley experiment, which is executed on document.Ready(). So the moment I am loading the youTube API, my iframe is not yet on my page.
Do have any ideas?
If the you are implementing the Youtube video when DOM is ready, you may want to do the following:
2. Click on the "Edit Code" box located on the lower right of the editor.
3. Look for the variation code that applies the Youtube video.
4. Insert a new line after the code.
5. Call the onYouTubeIframeAPIReady function again with the following code:
Let me know if this resolves the problem.