Content length

This page covers data collection for the Content length variable. See Content length for the corresponding reporting dimension.

The content length variable is the total duration of the content in seconds. It is required for all streaming media implementations and must be set at session start. Content length drives several backend-computed metrics, including progress markers (10/25/50/75/95%) and Average Minute Audience. If content length is not set, or is not greater than zero, those metrics are not produced. For live streams with unknown duration, use 86400 (24 hours).

Property
Value
Context data variable
a.media.length
XDM collection field
xdm.mediaCollection.sessionDetails.length
Audience Manager trait
c_contextdata.a.media.length
Required
Yes
Sent with
Session start, session close
Web SDK

Set length inside xdm.mediaCollection.sessionDetails when calling sendEvent:

code language-javascript
alloy("sendEvent", {
  xdm: {
    eventType: "media.sessionStart",
    mediaCollection: {
      sessionDetails: {
        name: "video-123",
        length: 128,
        contentType: "vod",
        playerName: "HTML5 Player",
        channel: "Sports",
        streamType: "video"
      },
      playhead: 0
    }
  }
});
iOS

Pass the content length in seconds as the length argument to createMediaObject.

code language-swift
let mediaObject = Media.createMediaObjectWith(name: "My Video",
                                                id: "video-123",
                                            length: 128,
                                        streamType: MediaConstants.StreamType.VOD,
                                         mediaType: MediaType.Video)

tracker.trackSessionStart(info: mediaObject, metadata: nil)
Android

Pass the content length in seconds as the length argument to createMediaObject.

code language-kotlin
var mediaInfo = Media.createMediaObject("My Video",
                                        "video-123",
                                        128,
                                        MediaConstants.StreamType.VOD,
                                        Media.MediaType.Video)

tracker.trackSessionStart(mediaInfo, null)
Roku

Set length inside xdm.mediaCollection.sessionDetails when calling createMediaSession:

code language-brightscript
m.aepSdk.createMediaSession({
    "xdm": {
        "eventType": "media.sessionStart",
        "mediaCollection": {
            "sessionDetails": {
                "name": "video-123",
                "friendlyName": "My Video",
                "length": 128,
                "contentType": "vod",
                "playerName": "Roku Player",
                "channel": "Sports",
                "streamType": "video"
            },
            "playhead": 0
        }
    }
})
Media Edge API

Call the sessionStart endpoint with length inside xdm.mediaCollection.sessionDetails:

code language-json
{
  "events": [{
    "xdm": {
      "eventType": "media.sessionStart",
      "mediaCollection": {
        "sessionDetails": {
          "name": "video-123",
          "length": 128,
          "contentType": "vod",
          "playerName": "HTML5 Player",
          "channel": "Sports"
        },
        "playhead": 0
      }
    }
  }]
}

Legacy implementation types (Analytics-only)

Media SDK JS 3.x

Pass the content length in seconds as the third argument to ADB.Media.createMediaObject:

code language-javascript
var mediaInfo = ADB.Media.createMediaObject(
  "My Video",
  "video-123",
  128,                      // length in seconds
  ADB.Media.StreamType.VOD,
  ADB.Media.MediaType.Video
);

tracker.trackSessionStart(mediaInfo, contextData);
Chromecast

Pass the content length in seconds as the third argument to ADBMobile.media.createMediaObject:

code language-javascript
var mediaInfo = ADBMobile.media.createMediaObject(
  "My Video",
  "video-123",
  128,
  ADBMobile.media.StreamType.VOD,
  ADBMobile.media.MediaType.Video
);
ADBMobile.media.trackSessionStart(mediaInfo, null);
Media Collection API

Include media.length in the params object of your sessionStart POST request:

code language-json
{
  "playerTime": { "playhead": 0, "ts": 1699523820000 },
  "eventType": "sessionStart",
  "params": {
    "media.length": 128
  }
}

See the Media Collection API sessions reference for the full request structure.

recommendation-more-help
media-analytics-help