I’m trying to setup GA Event Tracking on my site for an IFRAME Vimeo Video embed. However, I can’t figure out where/how the tracking object should be placed in my IFRAME code.
Here’s my IFRAME embed code:
<iframe src="http://player.vimeo.com/video/51447433" width="500"
height="281"frameborder="0" webkitAllowFullScreen
mozallowfullscreen allowFullScreen></iframe>
Here’s what I think the GA Event Tracking code should look like:
<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Title']);">Play</a>
Where does this go in my embed code? Can somebody show me how this should look/work?
You need to use the player API because you can’t inject code inside an iframe on a third party domain like that.
Based on the docs provided for the player API t should look something like this.
Working Example
The code above can be simplified a by using the Vimeo Mogaloop api that abstracts the Message Passing API for you, at the cost of loading the Javascript with the library.
Plugins Ready to use
Note that the above code will only work as an example and if you have multiple videos on a page it can be harder to get it right. Alternatively you can also use the GAS (I’m the main developer there) library that has a plugin for tracking Vimeo Video.
Warning about compatibility
Note the Warning about compatibility, I guess if you insert the player using the flash method you can get a wider range of browsers supported but kill the player completely for iOS devices: