• Resolved jtm12

    (@jtm12)


    I am learning Google Tag Manager with the intention of tracking media use on my site. Unfortunately, I am struggling to find anything to hook onto for a trigger when someone plays a video added through the All in One Video Gallery plugin.

    The GTM preview window shows nothing happening when I click a video.

    Is this by design? Yes is a perfectly good answer.

    I don’t see Google Analytics listed as a premium feature for the plugin.

    I appreciate the video “views” that you show in the admin window, but I’d like to see them by day. I probably account for many clicks. I’d like to filter out those, too.

    Could you give me a little more information on whether I will be able to use Google Tag Manager to track video plays?

    Thank you.

    • This topic was modified 2 years, 11 months ago by jtm12. Reason: I left off a question mark. I'm an editor. Can't just leave that after I've seen it
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Sorry, our current version doesn’t support the “Google Tag Manager”. But, this is already on our TODO lists. So, I promise that we will have this very soon. Please be patient.

    I understand that you are ready write code to achieve this but struggling to find the relevant hooks. If yes, kindly add the following code to the bottom of your theme’s functions.php file and edit the “aiovg_custom_iframe_player_scripts” function with your custom code.

    function aiovg_custom_iframe_player_scripts( $settings ) {
    	if ( ! isset( $_GET['pid'] ) ) {
    		return true;
    	}
    
    	$video_post_id = (int) $_GET['pid'];
    	?>
    	<script type="text/javascript">
    		'use strict';	
    
    		var video_post_id = <?php echo $video_post_id; ?>;
    
    		function onPlayerInitialized( player ) {
    			// play
    			player.on( 'play', function() {
    				// ADD YOUR CUSTOM CODE HERE
    			});
    
    			// timeupdate
    			player.on( 'timeupdate', function() {
    				// ADD YOUR CUSTOM CODE HERE
    			});
    
    			// ended
    			player.on( 'ended', function() {
    				// ADD YOUR CUSTOM CODE HERE
    			});
    		}			
    	</script>
    	<?php		
    }
    add_action( 'aiovg_player_footer', 'aiovg_custom_iframe_player_scripts' );
    
    function aiovg_custom_player_page_url( $url, $post_id, $atts ) {		
    	if ( is_singular( 'aiovg_videos' ) ) {
    		$url = add_query_arg( 'pid', get_the_ID(), $url );
    	}
    	
    	return $url;	
    }
    add_filter( 'aiovg_player_page_url', 'aiovg_custom_player_page_url', 10, 3 );

    Hope this helped you!

    Thread Starter jtm12

    (@jtm12)

    Thank you for your quick reply.

    I am thrilled to hear this is on your to do list.

    And thank you for the code.

    If I get something working, I’ll let you know.

    Thread Starter jtm12

    (@jtm12)

    I have learned a lot about Google Tag Manager since I posted my original question. The big challenge with this plugin will be that clicks on an iframe are not transmitted to GTM automatically. No click is recorded in the GTM dashboard.

    One solution for those with access to the iframe code itself is to install separate GTM snippets into the iframe and have those send info to the page where the iframe is embedded. I’m still fumbling around trying to figure out how to do that, even if not the proper way to start with.

    If I paste the GTM snippets into the player-iframe.php head and body, they don’t show up in the source code when I look at a page with the video player embedded in an iframe.

    Since you said this functionality was on your to do list, I thought sharing this iframe issue would save you some time as you got started.

    Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Kindly go to “Video Gallery => Settings” from your WordPress Admin Dashboard, select the “Player Type” as “JavaScript”, save the changes and check now. This should add the player without iframe and solve your issue.

    I have also taken a note of your suggestion for our future development. Thanks for bringing this to us 🙂

    Thread Starter jtm12

    (@jtm12)

    That’s a great solution. I will play with it this week.

    Thanks so much.

    Thread Starter jtm12

    (@jtm12)

    I’m not sure how much to post on what I’ve learned in GTM the past two weeks. Please delete this if it is too much information.

    Changing the player type to JavaScript from an iframe in the settings worked perfectly. Thank you for that instruction.

    A problem still exists with embedded YouTube videos, which continue to use an iframe.

    On a desktop with the YouTube videos, I believe users see a thumbnail type image uploaded to the video with your plugin, if a photo has been uploaded,
    and the play button generated by the plugin, so those are clickable, and GTM can access those and record the YouTube video click.

    On mobile, my testing suggests that the YouTube video itself shows, and I haven’t found a clickable element there, yet.

    Based on my work so far, I believe that setting up a tag in Google Tag Manager to capture clicks on videos displayed through your plugin requires three parts (and this is working on my website):

    –Custom JavaScript under “Variables” to grab the right element(s).

    –A trigger listening for a click on .vjs-big-play-button (the player button), .poster (the image background), or video-js#aiovg-player-1 (the clickable element on mobile).

    –A tag that sends the element(s) grabbed in Step 1 to Google Analytics as an event.

    I’m in the process of developing my JavaScript skills now, so I went with separating my Custom JavaScript entries into three functions rather than trying to do this with one.

    User Defined Variables are at the bottom of the Variables section in GTM. I used the Custom JavaScript option, not the JavaScript Variable option.

    The different Custom JavaScript functions address the fact that different video elements load from the plugin depending on whether the user is on a desktop or mobile device and looking at an uploaded video or embedded video.

    The first Custom JavaScript entry grabs the SRC in videos that I have uploaded. Those are named with something I recognize, so the SRC is relevant and understandable.

    function() {
    var getVideoSrc = document.querySelector(‘.vjs-big-play-button’).parentNode.childNodes[0].src
    return getVideoSrc;
    }

    I named this entry Get Player SRC.

    The second Custom JavaScript entry grabs my uploaded image (using the plugin) of the YouTube videos I have embedded because the YouTube URLs (random numbers and letters) do not identify the video for me. A video title would be better.

    function() {
    var posterName = document.getElementById(‘aiovg-player-1’).getAttribute(‘poster’);
    return posterName;
    }

    I named this second entry Get YouTube Video Image.

    The third Custom JavaScript entry gets the SRC on a mobile device of a video I uploaded to the site. The div structure on mobile devices appears to be different, so moving up and down the DOM takes less steps.

    function() {
    var mobilePlayerSRC = document.getElementById(‘aiovg-player-1’).childNodes[0].getAttribute(‘SRC’);
    return mobilePlayerSRC;
    }

    I named the third entry Get Mobile Video Player SRC.

    Again, the YouTube videos on mobile have nothing for GTM to record as a click because everything is in the iframe, as far as I can tell. I have no solution yet for capturing those clicks.

    Once those user-defined Custom Variables are set up, it’s time to make the trigger.

    Under Triggers, create a new trigger.

    I selected Click All Elements in the top area, and then Some Clicks in the middle area. For my filter, I chose Click Element and Matches CSS selector, and then I entered in the field the following:

    button.vjs-big-play-button, div.vjs-poster, video-js#aiovg-player-1

    The commas signify “or.”

    I named the trigger Video Button Trigger.

    For the Tag, which sends the info to Google Analytics, I chose the following. I selected Google Analytics: Universal Analytics for the Tag Type and Event for Track Type.

    I entered Event Video Button Click in the category (you can type anything).

    I chose my three potential variables in the Action section, and that looks like this (I added the pipes between them, but I might take them out):

    {{Get Desktop Video Player SRC}} | {{Get YouTube Video Image}} | {{Get Mobile Video Player SRC}}

    And I used for the Label section the page path. That’s selectable and looks like this: {{Page Path}}

    I left Noninteraction Hit as false. I want Google to record a hit.

    I entered my GA account under Google Analytics settings.

    And in the Triggers area, I selected my Video Button Trigger.

    I called the tag Send to GA Video Clicks, and I saved it.

    I am quite sure this is not the most elegant way to do this, but it’s a start.

    Also, in GTM’s Variables section, there are many video variables (duration, title, length, percent, provider) that I have not figured out how to use … yet. I have them activated. The data is not being recorded. Those may hold a better solution.

    I hope this helps someone.

    Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Thanks for sharing us your knowledge about GTM and this is really going to help us when we integrate the feature to our plugin 🙂

    Regarding YouTube on mobiles,

    Yes, our previous versions used the native YouTube player on mobiles. But, this is solved in our last release. So, I guess you should be using our OLD version. Please try upgrading to our latest version and let me know if still you find any issues.

    Thread Starter jtm12

    (@jtm12)

    Last post, I promise.

    So it turns out that GTM has a built-in YouTube trigger for embedded YouTube videos.

    It’s very easy to set up, relatively speaking (GTM can be a bit overwhelming at first), and the following tutorial explains it so well with images that I won’t recreate those instructions here:

    https://marketlytics.com/analytics-faq/track-youtube-videos-google-tag-manager/

    I have no affiliation with that website.

    I did update your plugin on my website to the latest version and made sure these instructions work on the latest version. They do.

    I tried the instructions on a website where I just have a YouTube video embedded with no plugin. Works there, too.

    And all those GTM built-in video variables (video URL, video title, video duration, etc.) that I mentioned earlier work if you set up YouTube tracking using the instructions in that link.

    However, that’s the only type of video that the variables work with (so far). I don’t have them working with a video uploaded through WordPress.

    Thank you for letting me code out loud through all this. It pushed me to keep going.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Using Google Tag Manager with All in One Video Gallery’ is closed to new replies.