HTML5 Video Plugin

NOTE: THIS DEMO HASN’T BEEN UPGRADED TO GTAG.JS YET. SO, IT’S NOT WORKING RIGHT NOW. I HOPE TO GET IT UPGRADED SOON 😉

A WordPress plugin for tracking HTML5 Video Events in Google Analytics

With support for tracking logged-in user IDs

This plugin is the WordPress version of the GTM version I posted earlier.

To see the video play events in real time:

  1. Open Omnibug in your dev console.
  2. Open your GA Realtime > Events report in a separate window.

If you’re logged in, you’ll see the user ID and custom dimension index printed to the console.

Connect with me on my main site to ask me for a temporary login 😉

GA4HTML5VID Plugin Usage

Before You Start

Make sure you’ve already enabled user ID tracking in Google Analytics and on your WordPress site.

You can add user ID tracking to WordPress by using a plugin such as MonsterInsights (Pro version) or by manually inserting gtag.js code.

Install

  1. Download the zip file from GitHub.
  2. Log in to your WordPress site as an admin.
  3. Navigate to Plugins > Add New.
  4. Click Upload Plugin.
  5. Select the zip file downloaded in step 1.
  6. Click Install Now.
  7. Click Activate.

Next: Write your filter hook for your user ID custom dimension index.

PHP Filter Hook

Add a call to the cme_user_id_custom_dimension_index filter hook to your child theme’s functions.php file. Change the custom dimension index to match the user ID custom dimension index in your Google Analytics property.

add_filter( 'cme_user_id_custom_dimension_index', function($custom_dimension_index) {
	return '5'; // Change this to match your CD index number that's set in GA.
} );

Now, Go Have Fun!

That’s it. Now, Google Analytics will track your YouTube video events. If a logged-in user plays your YouTube videos, their user ID is recorded along with each video event.


Screen Captures

HTML5 Video Tracking
Realtime Report
HTML 5 Video Tracking
Custom Report

Wrapping Up

Download or fork your copy on GitHub.

See a live demo of the caught my eye GA4YT plugin that tracks YouTube video events by user ID.

Credits

The JavaScript code for the GA4HTML5VID plugin was originally based on Julius Fedorovicius’ article, HTML5 Video Tracking Recipe for Google Tag Manager posted on Analytics Mania.