Skip to content

Instantly share code, notes, and snippets.

@tjFogarty
Last active December 13, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjFogarty/4990993 to your computer and use it in GitHub Desktop.
Save tjFogarty/4990993 to your computer and use it in GitHub Desktop.
Vimeo tracking object, assuming you're using https://github.com/vimeo/player-api/tree/master/javascript
//simply use Vimeo.init(); to find the videos and bind the events
var Vimeo = {
// we can add more events when we need to, e.g. onPause
events: {
// when videos are ready, we can attach our events
ready: function( player_id ) {
$f(player_id).addEvent( 'play', Vimeo.events.onPlay );
},
//when the play button is clicked
onPlay: function( player_id ) {
//clean up the string for track event by removing the hyphens
var trackEvString = player_id.replace( /-/g, ' ' );
//track event (GA)
if(_gaq) _gaq.push(['_trackEvent', 'Video', 'play', trackEvString]);
}
},
// collects the videos on the page and binds events
init: function() {
var i = 0,
videos = $( '.vimeo-video' ),
length = videos.length,
player = null;
for ( i; i < length; i++ ) {
player = videos[i];
$f( player ).addEvent( 'ready', Vimeo.events.ready );
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment