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
mediaCollection.sessionDetails.length
Required
Yes
Sent with
Session start, session close

Web SDK

Set length inside mediaCollection.sessionDetails when calling sendEvent:

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

Mobile SDK

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

iOS (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 (Kotlin)

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

tracker.trackSessionStart(mediaInfo, null)

Roku (BrightScript)

Set length inside mediaCollection.sessionDetails when calling createMediaSession:

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 mediaCollection.sessionDetails:

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

Media SDK

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

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);

Media Collection API

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

{
  "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