JW Player video tracking in Google Tag Manager
New in 2.0.0. Google Tag Manager for WordPress reports how your visitors watch the JW Player videos on your site. Starting, pausing, seeking, buffering and finishing become data layer events that you can use as triggers in Google Tag Manager.
This page describes GTM4WP 2.0.0 and newer. JW Player tracking did not exist in the legacy 1.x versions of the plugin.
The option is experimental and carries an Experimental badge in the plugin settings. It depends on how your site sets JW Player up, which the plugin cannot check for you, so read the requirements below before you switch it on.
Turning JW Player tracking on
Open the plugin settings, go to the Media events section, expand the Media players group and check JW Player video events. The option is switched off by default.
What your site has to provide
JW Player is one of the players the plugin does not load for you. It is a licensed product that sites set up in their own way, through the JW Player WordPress plugin, a hosted script from your JW Player account or a self hosted copy, so GTM4WP does not guess. It only hooks the JW Player library your site has already loaded.
Two conditions have to hold for a player to be tracked.
- Your site loads JW Player itself. If the library is missing, nothing is measured and nothing breaks.
- Each player container carries an
idattribute. JW Player normally sets one up during its own setup, but a container without anidis skipped, because the plugin has no way to ask JW Player for that particular player.
The tracker finds players by looking for the classes JW Player puts on its container while it builds the player. A player created later, for example in a popup or a section loaded by AJAX, needs the Track dynamically inserted players option in the Advanced group as well.
The ready event means something different here
For most players gtm4wp.mediaPlayerReady means the player told the plugin it was ready. For JW Player it means the plugin found an already working player and attached itself to it.
The reason is timing. By the time the tracker runs, JW Player has usually finished setting up and its own ready event has already come and gone, so waiting for it would mean waiting forever. The plugin pushes the ready event when it wires the player instead. In practice it lands at much the same moment, but it is a claim about the plugin rather than about the player.
Playback states
The gtm4wp.mediaPlayerStateChange event fires with these values in the mediaPlayerState variable:
| mediaPlayerState | Fires when |
|---|---|
play | Playback starts. |
pause | The visitor pauses the video. |
ended | The video plays to completion. |
seeked | The visitor jumps to another position. |
buffering | The player starts buffering. |
Player events
The gtm4wp.mediaPlayerEvent event carries the name of the event in the mediaPlayerEvent variable and the accompanying value in mediaPlayerEventParam.
| mediaPlayerEvent | mediaPlayerEventParam |
|---|---|
playbackRateChanged | The new playback rate. |
error | The error message reported by JW Player. |
Note the capital letters in playbackRateChanged. It follows the JW Player naming rather than the lower case style the other players use, and a trigger condition that matches on the value is case sensitive.
This is also the only player whose error event carries a readable message rather than a numeric code.
What mediaData holds for a JW Player video
| Variable | Contents |
|---|---|
mediaData.id | The media ID of the current item. If the item has none, the address of the video file, and failing that the id of the container element. |
mediaData.author | Always empty. JW Player exposes no uploader. |
mediaData.title | The title of the current item, or empty when the item has no title set. |
mediaData.url | The address of the video file, or empty when the item has none. |
mediaData.duration | The length of the current item in seconds. |
The mediaType variable is jwplayer in every event.
How much of this is filled in depends on how your videos are configured in JW Player. An item set up with a title reports it; one that only has a file address reports an empty title and falls back to the file address as its ID. If your reports come out thin, the fix is usually in your JW Player setup rather than in the plugin.
Playlists
A JW Player instance can hold a playlist. The plugin reads the current item every time it pushes an event, so a playlist that advances to the next video reports that video from then on rather than staying on the first one. Progress milestones are counted per item.
Google Tag Manager built-in Video variables
Every JW Player media event also populates the built-in Video variables of Google Tag Manager, with Video Provider set to jwplayer. The section on built-in Video variables explains how to enable and use them. Video Visible is measured on the player container.
Building a trigger in Google Tag Manager
To fire a tag when a visitor starts a JW Player video:
- Create a Data Layer Variable named
mediaPlayerState. - Create a Custom Event trigger whose event name is
gtm4wp.mediaPlayerStateChange. - Add the condition
mediaPlayerStateequalsplayto the trigger. - Attach the trigger to your tag. To identify the video, create a second Data Layer Variable named
mediaData.title, ormediaData.idif your items have no titles.
Limitations
- Your site has to load JW Player itself. The plugin adds no JW Player script.
- A player container without an
idattribute is skipped. - The ready event reports that the plugin wired the player, not that JW Player reported itself ready.
mediaData.authoris always empty, and the title and the URL are only as complete as your JW Player configuration makes them.playbackRateChangedis spelled with capital letters, unlike the equivalent event on the other players.- There is no 100 percent milestone. Measure a full watch with the
endedstate, as described under playback percentage milestones.
Related pages
The overview of media player tracking describes the events, data layer variables and playback milestones that every player shares. See also Wistia, the other player that binds to a runtime your site already loads, and HTML5 video and audio for files you host yourself.

