From d24088c08de24b6cb5efeecec406e5e9180c0b8b Mon Sep 17 00:00:00 2001 From: "smain@google.com" Date: Fri, 12 Dec 2014 11:31:13 -0800 Subject: [PATCH] add analytics event to track from which page a video was started Change-Id: I9ba1f992c09fb9e18c55bca5bf3892e50f37012a --- tools/droiddoc/templates-sdk/assets/js/docs.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index 7b1faa4664..e3b717503d 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -617,6 +617,9 @@ function startYouTubePlayer(videoId) { function onPlayerReady(event) { event.target.playVideo(); + // track the start playing event so we know from which page the video was selected + ga('send', 'event', 'Videos', 'Start: ' + + youTubePlayer.getVideoUrl().split('?v=')[1], 'on: ' + document.location.href); } function closeVideo() { @@ -633,15 +636,18 @@ function closeVideo() { function onPlayerStateChange(event) { // Video starts, send the video ID if (event.data == YT.PlayerState.PLAYING) { - ga('send', 'event', 'Videos', 'Play', youTubePlayer.getVideoUrl().split('?v=')[1]); + ga('send', 'event', 'Videos', 'Play', + youTubePlayer.getVideoUrl().split('?v=')[1]); } // Video paused, send video ID and video elapsed time if (event.data == YT.PlayerState.PAUSED) { - ga('send', 'event', 'Videos', 'Paused', youTubePlayer.getVideoUrl().split('?v=')[1], youTubePlayer.getCurrentTime()); + ga('send', 'event', 'Videos', 'Paused', + youTubePlayer.getVideoUrl().split('?v=')[1], youTubePlayer.getCurrentTime()); } // Video finished, send video ID and video elapsed time if (event.data == YT.PlayerState.ENDED) { - ga('send', 'event', 'Videos', 'Finished', youTubePlayer.getVideoUrl().split('?v=')[1], youTubePlayer.getCurrentTime()); + ga('send', 'event', 'Videos', 'Finished', + youTubePlayer.getVideoUrl().split('?v=')[1], youTubePlayer.getCurrentTime()); } }