{"id":4706,"date":"2017-11-07T04:17:43","date_gmt":"2017-11-07T04:17:43","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4706"},"modified":"2017-11-07T04:17:43","modified_gmt":"2017-11-07T04:17:43","slug":"track-html5-video-views-with-google-analytics","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/track-html5-video-views-with-google-analytics\/","title":{"rendered":"Track HTML5 Video Views with Google Analytics"},"content":{"rendered":"<div class=\"bigInt\">Is there a simple solution to track viewers engagement, if you have published HTML 5 video on the web? Yes. You can use combination of Google Analytics and very few lines of coding to see detailed video engagement analytics. You can track total number of viewers for your video, number of viewers who has just watched minimum percentage of video you have mentioned, number of viewers who has completed watching the video and many such analytics could be found using\u00a0<a href=\"https:\/\/www.9lessons.info\/2016\/03\/google-analytics-custom-dashboards-websites.html\" target=\"_blank\" rel=\"noopener\">Google Analytics<\/a>. Let\u2019s see how far you are utilizing Google Analytics for such great analysis of your posted content on the web. Have a look at the demo..!<\/div>\n<p><span class=\"post-body entry-content\">\u00a0<\/span><\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/lh3.googleusercontent.com\/-acG0bAOx8Jk\/Vxu96YD6-hI\/AAAAAAAANzw\/ubQcIIXTKvU77_b_1-y9CJAmPJEKYlNSACCo\/s650\/html5video.png\" alt=\"Track HTML5 Video Views with Google Analytics \" \/><\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<a name=\"more\"><\/a><br \/>\n<a id=\"downloadScript\" href=\"http:\/\/downloads.9lessons.info\/SocialProjectKey.zip\">Download Script<\/a>\u00a0\u00a0\u00a0\u00a0<a href=\"http:\/\/demos.9lessons.info\/videoGA\/index.php\"><img src=\"https:\/\/lh6.ggpht.com\/_N9kpbq3FL74\/Sd31o5XF8hI\/AAAAAAAABg0\/104nWJR7wro\/live.png\" alt=\"\" align=\"absMiddle\" border=\"0\" \/>\u00a0Live Demo<\/a><\/p>\n<p><b>HTML &amp; JavaScript Code<\/b><br \/>\n<\/span><\/p>\n<div class=\"code\">&lt;script src=&#8221;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/2.2.0\/jquery.min.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\n$(document).ready(<b>function<\/b>(){<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;<br \/>\n});<br \/>\n&lt;\/script&gt;<br \/>\n\/\/HTML Code<br \/>\n&lt;video id=&#8221;<b>video<\/b>&#8221; \u00a0width=&#8221;100%&#8221; \u00a0controls&gt;<br \/>\n&lt;source src=&#8221;video.mp4&#8243; type=&#8221;video\/mp4&#8243;&gt;<br \/>\n&lt;\/video&gt;<\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<b>Google Analytics<\/b><br \/>\nCreate a free\u00a0<a href=\"https:\/\/www.google.com\/analytics\/\" target=\"_blank\" rel=\"noopener\">Google Analytics<\/a>\u00a0account, add a property for your website. Here just modify UA-YOUR-GA-ID value.<br \/>\n<\/span><\/p>\n<div class=\"code\">&lt;script&gt;<br \/>\n(<b>function<\/b>(i,s,o,g,r,a,m){i[&#8216;GoogleAnalyticsObject&#8217;]=r;i[r]=i[r]||<b>function<\/b>(){<br \/>\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new\u00a0Date();a=s.createElement(o),<br \/>\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)<br \/>\n})(window,document,&#8217;script&#8217;,&#8217;\/\/www.google-analytics.com\/analytics.js&#8217;,&#8217;ga&#8217;);<br \/>\n<b>ga<\/b>(&#8216;create&#8217;, &#8216;UA-YOUR-GA-ID&#8217;, &#8216;auto&#8217;);<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;pageview&#8217;);<br \/>\n&lt;\/script&gt;<\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<b>Jquery Bind Timeupdate<\/b><br \/>\nContains jquery code. $(&#8220;#video&#8221;).bind(&#8220;timeupdate&#8221;, function(){} &#8211; here\u00a0<i>video<\/i>\u00a0is the ID name of the video tag, this will bind with video timeline. This will call Google Analytics function once it crossed 66%, you can modify percentage value.<br \/>\n<\/span><\/p>\n<div class=\"code\">var\u00a0i=0;<br \/>\n$(&#8220;#video&#8221;).bind(&#8220;timeupdate&#8221;,\u00a0<b>function<\/b>()<br \/>\n{<br \/>\nvar\u00a0currentTime =\u00a0this.currentTime;<br \/>\nif(currentTime &gt;\u00a00.66*(this.duration))<br \/>\n{<br \/>\nif(i&lt;1)<br \/>\n{<br \/>\n\/* Watched 66% *\/<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;event&#8217;, &#8216;Videos&#8217;, &#8216;Watched&#8217;,&#8217;Video Title&#8217;);<br \/>\n}<br \/>\ni=i+1; \/\/Reset for duplicates<br \/>\n}<br \/>\n});<\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<b>Jquery Bind Ended<\/b><br \/>\nThis works like previous function, using this you will find out how many people actually finished the video.<br \/>\n<\/span><\/p>\n<div class=\"code\">var\u00a0j=0;<br \/>\n$(&#8220;#video&#8221;).bind(&#8220;ended&#8221;,\u00a0<b>function<\/b>()<br \/>\n{<br \/>\nif(j&lt;1)<br \/>\n{<br \/>\n\/* Finished *\/<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;event&#8217;, &#8216;Videos&#8217;, &#8216;Finished&#8217;,&#8217;Video Title&#8217;);<br \/>\n}<br \/>\nj=j+1;\u00a0\/\/Reset for duplicates<br \/>\n});<\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<b>Google Analytics Widget Filter<\/b><br \/>\n<\/span><\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/lh3.googleusercontent.com\/-Z5ZcPe2tNLk\/Vx_SbLnT8uI\/AAAAAAAAN0M\/WqBThw1xxicyyYc6mNbijeJPh7twelqUwCCo\/s850\/GA.png\" alt=\"Google Analytics Video Filter\" \/><\/div>\n<p><span class=\"post-body entry-content\"><br \/>\n<b>Result<\/b><br \/>\n<\/span><\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/lh3.googleusercontent.com\/-9TB8m2jhnjo\/Vx_TiwtbELI\/AAAAAAAAN0o\/YtZugRyCNgssdvK7sMpGTgpLr-ohAjTOACCo\/s850\/videoResult.png\" alt=\"Google Analytics Video Filter\" \/><\/div>\n<p><span class=\"post-body entry-content\"><\/p>\n<p><b>Final Code<\/b><br \/>\n<\/span><\/p>\n<div class=\"code\">&lt;script src=&#8221;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/2.2.0\/jquery.min.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\n$(document).ready(<b>function<\/b>(){<br \/>\nvar\u00a0i=0;<br \/>\nvar\u00a0j=0;<\/p>\n<p>\/* Video Watched *\/<br \/>\n$(&#8220;#video&#8221;).bind(&#8220;timeupdate&#8221;,\u00a0<b>function<\/b>()<br \/>\n{<br \/>\nvar\u00a0currentTime =\u00a0this.currentTime;<br \/>\nif(currentTime &gt;\u00a00.66*(this.duration))<br \/>\n{<br \/>\nif(i&lt;1)<br \/>\n{<br \/>\n\/* Watched 66% *\/<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;event&#8217;, &#8216;Videos&#8217;, &#8216;Watched&#8217;,&#8217;Video Title&#8217;);<br \/>\n}<br \/>\ni=i+1;\u00a0\/\/Reset for duplicates<br \/>\n}<br \/>\n});<\/p>\n<p>\/* Video Finished, Thanks *\/<br \/>\n$(&#8220;#video&#8221;).bind(&#8220;ended&#8221;,\u00a0<b>function<\/b>()<br \/>\n{<br \/>\nif(j&lt;1)<br \/>\n{<br \/>\n\/* Finished *\/<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;event&#8217;, &#8216;Videos&#8217;, &#8216;Finished&#8217;,&#8217;Video Title&#8217;);<br \/>\n}<br \/>\nj=j+1;\u00a0\/\/Reset for duplicates<br \/>\n});<\/p>\n<p>});<br \/>\n&lt;\/script&gt;<br \/>\n\/\/HTML Code<br \/>\n&lt;video id=&#8221;video&#8221; \u00a0width=&#8221;100%&#8221; \u00a0controls&gt;<br \/>\n&lt;source src=&#8221;video.mp4&#8243; type=&#8221;video\/mp4&#8243;&gt;<br \/>\n&lt;\/video&gt;<br \/>\n\/\/Google Analytics Code<br \/>\n&lt;script&gt;<br \/>\n(<b>function<\/b>(i,s,o,g,r,a,m){i[&#8216;GoogleAnalyticsObject&#8217;]=r;i[r]=i[r]||<b>function<\/b>(){<br \/>\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new\u00a0Date();a=s.createElement(o),<br \/>\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)<br \/>\n})(window,document,&#8217;script&#8217;,&#8217;\/\/www.google-analytics.com\/analytics.js&#8217;,&#8217;ga&#8217;);<br \/>\n<b>ga<\/b>(&#8216;create&#8217;, &#8216;UA-YOUR-GA-ID&#8217;, &#8216;auto&#8217;);<br \/>\n<b>ga<\/b>(&#8216;send&#8217;, &#8216;pageview&#8217;);<br \/>\n&lt;\/script&gt;<\/div>\n<div id=\"survey\">\n<div id=\"surveyBlock\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Is there a simple solution to track viewers engagement, if you have published HTML 5 video on the web? Yes. You can use combination of Google Analytics and very few lines of coding to see detailed video engagement analytics. You can track total number of viewers for your video, number of viewers who has just [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4707,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[22],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4706"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4706"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4707"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}