Created
November 6, 2017 11:34
-
-
Save gatespace/2905f3145477103fe8da9e9877820cca to your computer and use it in GitHub Desktop.
サイト内の動画をGoogleアナリティクスで計測したい(WordPressの場合のおまけ付き) ref: http://qiita.com/gatespace/items/dee511d0155336e49dc8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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