Below are examples of using the YouTube, Vimeo, and Wistia JavaScript Libraries in conjunction with Kissmetrics to record certain video events.
Events Recorded
Played Video
Paused Video
Finished Video
Properties Recorded
Played Video Name
Paused Video Name
Finished Video Name
Vimeo
Vimeo’s Embed Code
Add the embed code to add the Vimeo video in an iFrame. Add api=1 as a query string to the URL of the iframe.
Load their JavaScript mini-library, called Froogaloop.
This is what your full embed code might look like:
Add KM Tracking
Now below this, let’s interact with their JS to set up the events:
Wistia
Wistia’s Embed Code
If you expand the “Embed Type” box, you can expand the Advanced Options and switch to using the Wistia API rather than the iFrame method. Copy/paste this into your page.
Add KM Tracking
Now below this, let’s add our tracking calls.
The last line loadKMTrackableVideo(wistiaEmbed, "Sample Wistia Video"); is the piece you need to modify:
wistiaEmbed refers to the wistiaEmbed object. This does not have to change unless you are embedding several Wistia videos on the same page.
“Sample Wistia Video” refers to the name of the video. This will be appended to the event that is logged in KM.
Wistia Embed Shepherd
Wistia has also provided access to a JavaScript library they call the “Embed Shepherd”. This helps simplify getting pointers to all embedded Wistia videos.
YouTube
YouTube’s Embed Code
First, you’ll need to embed your YouTube video using their iFrame API (which has the best compatibility with mobile devices). The code looks like this (remember to change out the videoId with the video you want to embed:
Add KM Tracking
Once that’s done, you can add this block below the embed code.