Tracking Plays of Embedded YouTube Videos

As part of an experiment, you may want to test different embedded YouTube videos to find out which one converts better. You can create a goal that will track whether a video is played, or even a goal that tracks if the video finished playing. YouTube provides the YouTube Player API through which you can trigger a conversion on the above-mentioned events.

This can be achieved a couple of different ways, and we provide one example, but it depends on your specific scenario and what your original page contains. Please see YouTube references at the bottom of this article for further information.

The YouTube code requires an ID to identify the iframe where the video is. If there is no iframe already, then it requires a div with an ID; YouTube will replace the div with the iframe and video player.

If your original page already has an iframe with an embedded video, but no ID, you can add an ID with the Code Editor. Similarly, if it has no iframe but a div where you want to place the embedded video, you must add an ID to the div, and you can do that with the Code Editor.

Normally the Original is not modified with the Code Editor but in this case you may need to do so to add the ID as this is essential to track clicks on the original as well as the variations.

You can add the YouTube code on the Global Experience JS where it will apply to the original and all the variations, or else add the code individually to the Original and each variation's Custom JS, instead of the Global Experience JS.

As mentioned previously, you could also put this code in Custom JavaScript but in that case you would have to duplicate it in the Original and each Variation, so it is better to add it only once, to the Global Experience JS.