Skip to content

Instantly share code, notes, and snippets.

@gatespace
Created November 6, 2017 11:34
Show Gist options
  • Save gatespace/2905f3145477103fe8da9e9877820cca to your computer and use it in GitHub Desktop.
Save gatespace/2905f3145477103fe8da9e9877820cca to your computer and use it in GitHub Desktop.
サイト内の動画をGoogleアナリティクスで計測したい(WordPressの場合のおまけ付き) ref: http://qiita.com/gatespace/items/dee511d0155336e49dc8
// video ga
var video = $('video');
var video_url = '';
if( video.length > 0 ){
var isPlay = false;
video.on('play playing',function(){
if( isPlay === false ) {
video_url = $(this).attr( 'src' );
// Googleアナリティクス analytics.js の場合
if ( typeof ga === 'function' ) {
ga( 'send', {
hitType: 'event',
eventCategory: 'Videos',
eventAction: 'play',
eventLabel: video_url
});
}
isPlay = true;
}
});
video.on('ended',function(){
if( isPlay === true ) {
isPlay = false;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment