How to Track JW Player Videos in Google Analytics

how-to-track-jw-1Although JW Player comes with built-in analytics, you can only receive in-depth data with a comprehensive service like Google Analytics. It is possible to integrate Google Analytics with all versions of JW Player 8, including the free version. Once everything is set up, you will be able to track and measure all API events.

Setting Up Google Analytics

You need to configure analytics.js script and player on a web page before JW Player is able to track events. Use the following code within the page head, replacing UA-XXXXXX-X for your Google Analytics account number:


ga('create', 'UA-XXXXXXXX-X', ‘auto');
ga('send', 'pageview');

Once you have added this code, enable Google Analytics in your JW Player Dashboard. Under “Players” on the left sidebar, head to “Manage” and choose the player for which you want to enable integration.

Setting Up API Events

The default categories for event actions are video plays, video completes, buffer events, idle events, pause events, resume events, and seek events. However, you can monitor additional events using API calls. For instance, you can implement measurement of the following:

  • When an error occurs — onError()
  • When a user opens a video fullscreen — onFullscreen()
  • The user’s selected video quality — onQualityLevels() + getCurrentQuality()
  • The user’s volume level — onVolume() + getVolume()
  • Sections views are skipping to — onSeek() + getPosition()

Track Using Google Tag Manager

Using Google Tag Manager is an alternative to the standard event tracking model from Google Analytics. It requires using agnostic dataLayer pushes. You will need to use the following object as a video tracking data model:

"event": “video",
"player_id": {{VIDEO_ID}},
"interaction": {{VIDEO_ACTION}},
"video_url": {{VIDEO_URL}},
"duration": {{VIDEO_DURATION}},
"width": {{PLAYER_WIDTH}},
"height": {{PLAYER_HEIGHT}},
"resolutions": {{AVAILABLE_VIDEO_QUALITIES}}, // an array
"volume": {{PLAYER_VOLUME}},
"player_type": {{PLAYER_TYPE}} // html5 or flash

To begin, create a variable to inform you if JW Player is available on the current page. This will make sure that your tracking code is just on a page with a video. Set the variable type as “JavaScript Variable” and name it “jwplayer.”

To configure the trigger to fire a tracking tag, use the same variable as above with a second condition to trigger tracking after the DOMReady event. Set it as a custom event to fire on gtm.dom. Under “Fire this trigger when all these conditions are true,” set “IsJWPlayerAvailable” then “does not equal” and then “undefined.” After you finish this configuration, you will receive the full code to copy and all this is set up, all video interactions information will be pushed to the dataLayer and you will be able to send events to Google Analytics.

Sending Events

To send events to Google Analytics, you need to initiate a send event. For instance, if you have a single player on a page, you can check for the errors using this code:

jwplayer().on('error', function(event) {ga('send', 'event', 'JW Player Events', 'Errors', event.message);

Finding Playback Events

In your Google Analytics account, head to either “Behavior” and then “Events” or to “Real-Time” and then “Events.” You will find all the playback events under “JW Player Video.” When you click on a category, you will be able to view all the event actions of that type captured by the player. You will also see the event label, which is the URL of the video file by default.

If you are using JW Player, it is worthwhile integrating it with Google Analytics for all the additional information you will receive about users. Plus, it is simple to set up and you can start acting on the data immediately.

If you like my articles,