相信大家都會把youtube的影片放到自己的網站上,可是你們是否有想過你們自己的網站上的影片到底有多少人點播放或者是有多少人看到一半按暫停還是把影片全部看完呢?
以下我就來介紹一下如何利用google analytics追蹤分析你的影片
要分析影片不外乎都是要在你的網頁上裝上代碼,只要複製以下的代碼,把紅色的地方改成你們自己的就可以了,不困難.
<div id="player"> </div>
<script type="text/javascript">// <![CDATA[
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement(‘script’);
tag.src = “https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName(‘script’)[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player(‘player’, {
height: ‘360‘, 你的影片高度,請自己設定
width: ‘640‘, 你的影片寬度, 請自己設定
videoId: ‘DFyt-9hetm4‘, 你的youtube影片的id
events: {
‘onReady’: onPlayerReady,
‘onStateChange’: onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
// Uncomment the event to have video start automatically.
function onPlayerReady(event) {
// event.target.playVideo();
}
// 5. The API calls this function when the player’s state changes.
// The function indicates that when playing a video,
// the player should send to Google Analytics.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
ga(‘send’, ‘event’, ‘TD-200SC video‘, ‘play’, ‘Promo from Main Page’);
}
if (event.data == YT.PlayerState.ENDED) {
ga(‘send’, ‘event’, ‘TD-200SC video‘, ‘compleced’, ‘Promo from Main Page’);
}
if (event.data == YT.PlayerState.PAUSED) {
ga(‘send’, ‘event’, ‘TD-200SC video‘, ‘paused’, ‘Promo from Main Page’);
}
}
// ]]></script>
裝好之後,請至google analytics的事件裡,只要有人點擊撥放或者是暫停還是影片全部看完,數據就會產生了.如以下圖檔