Stream Tracker

StreamTracker

If you are using the NPO player from the player team then the stream tracking is already integrated to the player. Make sure you pass the right information to the player to make the tracking work.

StreamTracker is used to send stream related events like pause, resume, stop, etc.

For the events listed below, the stream position refers to the current “time code” the user is at in the stream. It is always expressed in seconds and can be a decimal number. It can be either an absolute position in the case of a regular stream playing or, in case of a live stream, a relative offset to the “live time”.

Live stream support

The StreamTracker object can be obtained from a PageTracker instance by calling the newStreamTracker method. On top of a StreamContext instance, you will need to provide a value for isLiveStream, indicating whether or not this tracker will be used to track a live stream. If set to true, the stream position values provided to the methods listed below will be considered internally by the SDK as relative offsets from the “live time” instead of absolute positions as described above.

<script lang="text/javascript">
  window.onload = function() {
      ...
      const streamTracker = npotag.newStreamTracker(
          pageTracker,
          {
              stream_length: videoElement.duration,
              stream_id: 'video-stream',
              player_id: 'embedded-video',
              av_type: 'video',
              player_version: '1.0.0',
              sko_player_version: '1.0.0'
          },
          {
              isLive: true,
          }
      );
  }
</script>
const streamTracker = newStreamTracker(
  pageTracker,
  {
    stream_length: videoElement.duration,
    stream_id: 'video-stream',
    player_id: 'embedded-video',
    av_type: 'video',
    player_version: '1.0.0',
    sko_player_version: '1.0.0',
  },
  {
    isLive: true,
  }
);
let streamContext = StreamContext(
  streamLength: video.duration,
  streamID: "streamId",
  avType: StreamContext.AVType.video, // Or StreamContext.AVType.audio
  playerID: "playerId",
  playerVersion: "1.0.0",
  skoPlayerVersion: "1.0.0"
)

// Create a stream tracker instance for either a regular stream or live stream
let streamTracker = pageTracker.newStreamTracker(
  withContext: streamContext,
  isLiveStream: false
)
val streamTracker =  pageTracker.streamTrackerBuilder()
    .withStreamLength(STREAM_LENGTH)
    .withStreamId("testStreamId")
    .withPlayerId("testPlayerId")
    .withAVType("video")
    .withPlayerVersion("testPlayerVersion")
    .withSkoPlayerVersion("testSkoPlayerVersion")
    .withLiveStream(true)
    .build()

time

Keeps track of the streamWaypoint event and if it should be sent. Call this method every “tick” of playback of the player and the SDK determines if waypoints should be sent. Important: The time method call serves to notify the tag of a new position. It does not always send an event. The Tag will throttle events and send them only at the appriopriate interval for each plugin. You should call Time often, at least once per second of streaming!

Parameters:

  • streamPosition: Current position the user is at in the stream (in seconds).
streamTracker.time({ stream_position: 2 });
streamTracker.time({ stream_position: 2 });
public func time(streamPosition: Double)
override fun time(streamPosition: Double)

seek

Sends an event indicating the position from which a user moves to another position in the stream using the seek bar.

Parameters:

  • seekFrom: Original stream position of the seek action. Double, expressed in seconds.
  • streamPosition: New stream position after the user ends the seek action. Double, expressed in seconds.
streamTracker.seek({ stream_position: 90, seek_from: 2 });
streamTracker.seek({ stream_position: 90, seek_from: 2 });
public func seek(from seekFrom: Double, to streamPosition: Double)
override fun seek(from: Double, to: Double)

pause

Sends an event indicating that the user has paused the stream at a given position.

Parameters:

  • streamPosition: Position at which the stream was paused (in seconds).
streamTracker.pause({ stream_position: 90 });
streamTracker.pause({ stream_position: 90 });
public func pause(at streamPosition: Double)
override fun pause(streamPosition: Double) 

resume

Sends an event indicating that the user has resumed a previously pauzed stream at a given position.

Parameters:

  • streamPosition: Position at which the stream was resumed (in seconds).
streamTracker.resume({ stream_position: 90 });
streamTracker.resume({ stream_position: 90 });
public func resume(at streamPosition: Double)
override fun resume(streamPosition: Double) 

complete

Sends an event indicating that the stream has reached completion at a given position.

Parameters:

  • streamPosition: Position at which the stream was completed (in seconds).
streamTracker.complete({ stream_position: 270 });
streamTracker.complete({ stream_position: 270 });
public func complete(at streamPosition: Double)
override fun load(streamPosition: Double) 

buffering

Sends an event indicating that the stream started buffering at a given position. Buffering is when a stream stops playing and is instead loading new content, unlike a pauze, there is no user action that triggers buffering, but most likely a connection that is not fast enough to get enough data to keep playing the stream. After buffering is completed and the video is able to resume, the bufferingComplete should be send.

Parameters:

  • streamPosition: Position at which the stream started buffering (in seconds).
streamTracker.buffering({ stream_position: 100 });
streamTracker.buffering({ stream_position: 100 });
public func buffering(at streamPosition: Double)
override fun buffering(streamPosition: Double)

bufferingComplete

Sends an event indicating that the stream stopped buffering at a given position. Should happen after buffering has been called and enough data is available so that the video can resume playing.

Parameters:

  • streamPosition: Position at which the stream ended buffering (in seconds).
streamTracker.buffering_complete({ stream_position: 100 });
streamTracker.buffering_complete({ stream_position: 100 });
public func bufferingComplete(at streamPosition: Double)
override fun bufferingComplete(streamPosition: Double)

load

Sends an event indicating that the stream started loading at a given position (e.g. 0 when a stream starts from the begining). This is the initial load of the stream, not to be confused with a stream stopping and getting additional data as part of buffering.

Parameters:

  • streamPosition: Position at which the stream started loading (in seconds).
streamTracker.load({ stream_position: 0 });
streamTracker.load({ stream_position: 0 });
public func load(at streamPosition: Double)
override fun load(streamPosition: Double)

loadComplete

Sends an event indicating that the stream is done loading at a given position (e.g. 0 when a stream starts from the begining). Triggered after a stream has become available to play at the end of a load period. Most likely followed by a start event.

Parameters:

  • streamPosition: Position at which the stream was done loading (in seconds).
streamTracker.load_complete({ stream_position: 0 });
streamTracker.load_complete({ stream_position: 0 });
public func loadComplete(at streamPosition: Double)
override fun loadComplete(streamPosition: Double)

start

Sends an event indicating that the stream started playing at a given position (e.g. 0 when a stream starts from the begining). This event indicates that the stream has started playing for the first time. After a pauze, the event should be resume instead of start. Each stream played should have exactly one start on a given page or contentView.

Parameters:

  • streamPosition: Position at which the stream started playing (in seconds).
streamTracker.start({ stream_position: 5 });
streamTracker.start({ stream_position: 5 });
public func start(at streamPosition: Double)
override fun start(streamPosition: Double)

stop

Sends an event indicating that the stream has been stopped at a given position.

Parameters:

  • streamPosition: Position at which the stream was stopped (in seconds).
streamTracker.stop({ stream_position: 212 });
streamTracker.stop({ stream_position: 212 });
public func stop(at streamPosition: Double)
override fun stop(streamPosition: Double)

fullscreen

Sends an event indicating that the user has set the player to fullscreen mode at a given position.

Parameters:

  • streamPosition: Position at which the player was set to fullscreen (in seconds).
streamTracker.fullscreen({ stream_position: 190 });
streamTracker.fullscreen({ stream_position: 190 });
public func fullscreen(at streamPosition: Double)
override fun fullscreen(streamPosition: Double)

windowed

Sends an event indicating that the user has set the player to windowed mode at a given position.

Parameters:

  • streamPosition: Position at which the player was set to windowed (in seconds).
streamTracker.windowed({ stream_position: 205 });
streamTracker.windowed({ stream_position: 205 });
public func windowed(at streamPosition: Double)
override fun windowed(streamPosition: Double)