0

Has anyone successfully used GA's Tag Manager's Video trigger options to determine when a Youtube video on a Community page is played?

0

I am now able to track Google Analytics when a user presses play on a Youtube video on a Community page. It isn't the prettiest code, but it is a works & is a start. Not sure why my code isn't pasting as code.

<apex:page showHeader="false" standardStylesheets="false" controller="DisplayTopFiveNewestMembersForPortal" sidebar="false" docType="html-5.0" applyBodyTag="False" applyHtmlTag="False">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-123274077-1', 'auto'); var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubeIframeAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: 'M7lc1UVf-VE', events: { 'onStateChange': onPlayerStateChange } }); } var done = false; function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING && !done) { ga('send', 'event', 'Video', 'Youtube Video Test2', 'test'); alert("Video Playing"); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.