Tracking Embedded YouTube Videos with Adobe Analytics

Do you have embedded youtube videos using the iFrame player API and you wish to track this within Adobe Analytics using the media module? The solution I will provide is based on JavaScript for tracking video information.


What You Will Need:

1) Variables to be allocated for video tracking purposes:

Variables Analytics Variable Source
Prop70 – Video Name – YouTube API
eVar70 – Video Name – YouTube API
eVar71 – Video Segment Name – Media Module
eVar72 – Video Content Type – Media Module
Event100 – Video Start – Media Module
Event101 – Video 25% – Media Module
Event102 – Video 50% – Media Module
Event103 – Video 75% – Media Module
Event104 – Video Complete – Media Module
Event105 – Video Time Viewed – Media Module
Event106 – Video Segment View – Media Module

2) Processing Rules

To capture the video player name in an eVar, create a processing rule:
• Log into Reports & Analytics, navigate to Admin > Report Suites
• Select the report suite required, navigate to Edit Settings > General > Processing Rules
• Add Rule with the following logic:
o If is set, then overwrite the value of eVar70 with

3) Classification Rule Builder of Video Name
To parse the video name value into its components within the eVar or prop:
• returns a delimited value structure: [Video Player Name]|[Video ID]|[Video Name]
• The Video Name eVar/prop can be classified with: Video Player Name, Video ID, and Video Name.
• Using the Classification Rule Builder tool, create a regular expression-based rule set, such as ^(.+)\|(.+)\|(.+)$ to parse the delimited values into the respective reports.

How To Implement:

1) Place following code in HTML of Web page:

• Add id="player" to iframe tag
• Append &rel=0 to suppress related video end slate to YouTube embed URL
• Append &enablejsapi=1 to YouTube embed URL

2) Update your s_code or appMeasurement code by either doing one of the following:
– Place the player mapping below the s declaration (var s=s_gi(s_account)) within the analytics library.
– Place the player mapping code below right after

/* YouTube Player Mapping ( */
window.onYouTubeIframeAPIReady = function() {
var player = new YT.Player('player', {
events: {
'onStateChange': onPlayerStateChange
function onPlayerStateChange(event) {
if ( == YT.PlayerState.PLAYING) {
var videoPlayer = "YouTube Player";
var videoTitle =;
var videoId =;
var mediaName = videoPlayer+'|'+videoId+'|'+videoTitle;
var mediaLength = Math.floor(;
var mediaOffset = Math.floor(;
if (mediaOffset == 0) {
//console.log('mediaName on Start: ' + mediaName);
//console.log('mediaLength on Start: ' + Math.floor(;
//console.log('mediaOffset on Start: ' + Math.floor(;
mediaOffset = Math.floor(;,mediaLength,videoPlayer);,mediaOffset);
} else {
//console.log('mediaName on Play: ' + mediaName);
//console.log('mediaOffset on Play: ' + Math.floor(;
mediaOffset = Math.floor(;,mediaOffset);
if ( == YT.PlayerState.PAUSED) {
var videoPlayer = "YouTube Player";
var videoTitle =;
var videoId =;
var mediaName = videoPlayer+'|'+videoId+'|'+videoTitle;
//console.log('mediaName on Pause: ' + mediaName);
//console.log('mediaOffset on Pause: ' + Math.floor(;
mediaOffset = Math.floor(;
if ( == YT.PlayerState.BUFFERING) {
var videoPlayer = "YouTube Player";
var videoTitle =;
var videoId =;
var mediaName = videoPlayer+'|'+videoId+'|'+videoTitle;
//console.log('mediaName on Buffering: ' + mediaName);
//console.log('mediaOffset on Buffering: ' + Math.floor(;
mediaOffset = Math.floor(;
if ( == YT.PlayerState.ENDED) {
var videoPlayer = "YouTube Player";
var videoTitle =;
var videoId =;
var mediaName = videoPlayer+'|'+videoId+'|'+videoTitle;
//console.log('mediaName on Ended: ' + mediaName);
//console.log('mediaOffset on Ended: ' + 0);
mediaOffset = 0;

3) Place the iFrame API code directly after the YouTube code above

/* Loads IFrame Player API Code asynchronously */
var tag = document.createElement('script');
tag.src = "";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

4) Place the Media module configuration code below the iFrame API logic

/* Media Module Config */
s.Media.contextDataMapping = {
'':'eVar11,prop11', //Returns following delimited value structure: "YouTube|[Video ID]|[Video Title]"

This will declare the variables to use for media tracking. Please update to reflect your SDR’s variables.

5) Place the media module library before the activity map code (module section). The media module code can be grabbed from the code manager. Please note: This solution doesn’t leverage the video heartbeat measurement that Adobe released so you will need to use the older module vs. the newer one.

That’s it. Once you have this in place you can go about testing to make sure that the data is being recorded by Adobe. From a QA perspective, you will need to:

a) Go to a video page and start the video
b) Use a debugger or packet sniffer to see if eVar11/prop11 are capturing the YouTube|Video ID|Video Title info (as that is what the example above maps this info to)
c) Make sure is capturing event11 for video start (as thats listed in example above)

Posted in Adobe Analytics, Web Analytics