CML
    Preparing search index...

    Class CmcdReporter

    The CMCD reporter.

    Index

    Constructors

    Methods

    • Creates a new request with the CMCD request report data applied. Called by the player before sending the request.

      Type Parameters

      Parameters

      • request: R

        The request to apply the CMCD request report to.

      • Optionaldata: Partial<Cmcd>

        The data to apply to the request. This data only applies to this request report. Persistent data should be updated using update().

      Returns R & HttpRequest & {
          customData: { cmcd: Cmcd } & R["customData"];
          headers: Record<string, string>;
      }

      The request with the CMCD request report applied.

    • Forces the sending of all event reports, regardless of the batch size or interval. Useful for sending outstanding reports when the player is destroyed or a playback session ends.

      Returns void

    • Checks if the request reporting is enabled.

      Returns boolean

      true if the request reporting is enabled, false otherwise.

    • Records an event. Called by the player when an event occurs.

      For state-change events (PLAY_STATE, PLAYBACK_RATE, CONTENT_ID, BACKGROUNDED_MODE, BITRATE_CHANGE), this method:

      1. Persists the dedup field from data (if present) into the reporter's persistent data store — equivalent to a write-through update().
      2. Drops the event entirely if the dedup field has no value after the write-through (never set, or cleared via update({ field: undefined })). State-change events without their required field would violate CTA-5004-B.
      3. Suppresses the event if the field's current value matches the last-emitted value (no state transition).

      For all other event types, the event is always emitted.

      For state-change events, prefer CmcdReporter.update — including for snapshot enrichment via a combined call like update({ sta: 'p', bl: [3000], mtp: [8500] }). Calling recordEvent() for a state-change event after update() has already auto-fired it silently drops the second call's data, because dedup suppresses the second emission.

      Use recordEvent() directly for events whose payload is intrinsic to the event call — CUSTOM_EVENT with cen, ERROR with ec, ad-lifecycle events, MUTE/UNMUTE, PLAYER_EXPAND/PLAYER_COLLAPSE, SKIP. For RESPONSE_RECEIVED, prefer CmcdReporter.recordResponseReceived, which derives the per-response fields automatically.

      Parameters

      • type: CmcdEventType

        The type of event to record.

      • data: Partial<Cmcd> = {}

        Additional data to record with the event. This data only applies to this event report, except for the dedup field of a state-change event, which is also persisted into the reporter's data store.

      Returns void

    • Records a response-received event. Called by the player when a media request response has been fully received.

      This method automatically derives the rr event keys from the

      • url - the original requested URL (before any redirects)
      • rc - the HTTP response status code
      • ts - the request initiation time (from resourceTiming.startTime)
      • ttfb - time to first byte (from resourceTiming.responseStart)
      • ttlb - time to last byte (from resourceTiming.duration)

      Additional keys like ttfbb, cmsdd, cmsds, and smrt can be supplied via the data parameter if the player has access to them.

      Parameters

      • response: HttpResponse<HttpRequest<{ cmcd?: Cmcd }>>

        The HTTP response received.

      • data: Partial<Cmcd> = {}

        Additional CMCD data to include with the event. Values provided here override any auto-derived values.

      Returns void

    • Starts the CMCD reporter. Called by the player when the reporter is enabled.

      Note: This fires an initial time-interval event immediately (synchronously) before the first interval elapses. Ensure CMCD data (sid, cid, etc.) is populated before calling start().

      Returns void

    • Stops the CMCD reporter. Called by the player when the reporter is disabled.

      Parameters

      • flush: boolean = false

        Whether to flush the event targets.

      Returns void

    • Updates the CMCD data.

      Called by the player when data changes. For tracked state fields (sta, pr, cid, bg, br), if the new value differs from the last-reported value (the value most recently emitted on the wire for that field), the corresponding state-change event is automatically fired. Comparing against the last-reported value (rather than the previous persisted value) ensures the first state-change event in a new session always emits, even when the persisted value didn't change across the sid boundary.

      Multi-field updates fire multiple events in the order: staprcidbgbr. The order of keys in the input object does not affect the firing order.

      To attach snapshot context (e.g., bl, mtp, pt, ltc) to a state-change event, ensure those fields are in the reporter's data before the state field changes. Either include them alongside the state field in the same update() call, or persist them via earlier update() calls — auto-fired events emit whatever is currently in the persistent data store. This is also how to keep TIME_INTERVAL reports useful — those events draw from the persistent data store with no caller hook for per-event data, so fields the player wants in periodic reports must be kept fresh here.

      A sid change resets the dedup baseline.

      Parameters

      Returns void