Skip to content
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/mux-analytics.brs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ function muxAnalytics() as Object
m._videoSourceDuration = Invalid
m._videoCurrentCdn = Invalid
m._viewPrerollPlayedCount = Invalid
m._totalAdWatchTime = Invalid
m._adWatchTime = Invalid
m._cumulativePlayingTime = Invalid
m._lastAdResumeTime = Invalid

m._lastSourceWidth = Invalid
m._lastSourceHeight = Invalid
Expand Down Expand Up @@ -926,8 +930,17 @@ function muxAnalytics() as Object
end sub

prototype._rafEventhandler = sub(eventType, ctx, adMetadata)
date = m._getDateTime()
now = 0# + date.AsSeconds() * 1000.0# + date.GetMilliseconds()

if m._adWatchTime = Invalid
m._adWatchTime = 0
end if

m._Flag_isPaused = (eventType = "Pause")
if eventType = "PodStart"
m._adWatchTime = 0
m._lastAdResumeTime = now
m._advertProperties = m._getAdvertProperties(adMetadata)
m._addEventToQueue(m._createEvent("adbreakstart"))
' In the case that this is SSAI, we need to signal an adplay and adplaying event
Expand All @@ -936,6 +949,11 @@ function muxAnalytics() as Object
m._addEventToQueue(m._createEvent("adplaying"))
end if
else if eventType = "PodComplete"
if m._lastAdResumeTime <> Invalid
m._adWatchTime += now - m._lastAdResumeTime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to be at all extra safe here and make sure we're not decrementing ad watch time here?

m._lastAdResumeTime = Invalid
end if
m._totalAdWatchTime += m._adWatchTime
m._addEventToQueue(m._createEvent("adbreakend"))
m._Flag_FailedAdsErrorSet = false
' In the case that this is SSAI, we need to signal a play and playing event
Expand All @@ -947,6 +965,10 @@ function muxAnalytics() as Object
else if eventType = "Impression"
m._addEventToQueue(m._createEvent("adimpression"))
else if eventType = "Pause"
if m._lastAdResumeTime <> Invalid
m._adWatchTime += now - m._lastAdResumeTime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make sure that this is not a negative value, and if it is, just throw it out? something like max(0, now - m._lastAdResumeTime)?

m._lastAdResumeTime = Invalid
end if
m._addEventToQueue(m._createEvent("adpause"))
else if eventType = "Start"
if m._viewTimeToFirstFrame = Invalid
Expand All @@ -968,6 +990,7 @@ function muxAnalytics() as Object
m._addEventToQueue(m._createEvent("adplay"))
m._addEventToQueue(m._createEvent("adplaying"))
else if eventType = "Resume"
m._lastAdResumeTime = now
m._advertProperties = m._getAdvertProperties(ctx)
m._addEventToQueue(m._createEvent("adplay"))
m._addEventToQueue(m._createEvent("adplaying"))
Expand Down Expand Up @@ -997,12 +1020,24 @@ function muxAnalytics() as Object
else if eventType = "ThirdQuartile"
m._addEventToQueue(m._createEvent("adthirdquartile"))
else if eventType = "Skip"
if m._lastAdResumeTime <> Invalid
m._adWatchTime += now - m._lastAdResumeTime
m._lastAdResumeTime = Invalid
end if
m._totalAdWatchTime += m._adWatchTime
m._addEventToQueue(m._createEvent("adskipped"))
m._addEventToQueue(m._createEvent("adended"))
end if
end sub

prototype._renderStitchedStreamRafEventHandler = sub(eventType, ctx, adMetadata)
date = m._getDateTime()
now = 0# + date.AsSeconds() * 1000.0# + date.GetMilliseconds()

if m._adWatchTime = Invalid
m._adWatchTime = 0
end if

if eventType = "AdStateChange"
state = ctx.state
m._advertProperties = m._getAdvertProperties(adMetadata)
Expand All @@ -1011,6 +1046,8 @@ function muxAnalytics() as Object
' our ad break here if we're not already in one
if not m._Flag_rssInAdBreak
m._Flag_rssInAdBreak = true
m._adWatchTime = 0
m._lastAdResumeTime = now
m._addEventToQueue(m._createEvent("adbreakstart"))
end if

Expand All @@ -1021,18 +1058,25 @@ function muxAnalytics() as Object
' in the playing state, if we either resuming, we need adplay first
if m._Flag_isPaused
m._Flag_isPaused = false
m._lastAdResumeTime = now
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessary - it will always be set again on line 1065

m._addEventToQueue(m._createEvent("adplay"))
end if
' and always emit adplaying
m._addEventToQueue(m._createEvent("adplaying"))
else if state = "paused"
if m._lastAdResumeTime <> Invalid
m._adWatchTime += now - m._lastAdResumeTime
m._lastAdResumeTime = Invalid
end if
m._Flag_isPaused = true
m._addEventToQueue(m._createEvent("adpause"))
end if
else if eventType = "PodStart"
' Need to handle PodStart for non-pre-rolls
if not m._Flag_rssInAdBreak
m._Flag_rssInAdBreak = true
m._adWatchTime = 0
m._lastAdResumeTime = now
if not m._Flag_isPaused
m._Flag_isPaused = true
m._addEventToQueue(m._createEvent("pause"))
Expand All @@ -1049,10 +1093,16 @@ function muxAnalytics() as Object
' event to know that a new ad was played
if m._Flag_rssAdEnded
m._Flag_rssAdEnded = false
m._lastAdResumeTime = now
m._addEventToQueue(m._createEvent("adplay"))
m._addEventToQueue(m._createEvent("adplaying"))
end if
else if eventType = "PodComplete"
if m._lastAdResumeTime <> Invalid
m._adWatchTime += now - m._lastAdResumeTime
m._lastAdResumeTime = Invalid
end if
m._totalAdWatchTime += m._adWatchTime
m._Flag_rssInAdBreak = false
m._Flag_isPaused = true
m._addEventToQueue(m._createEvent("adbreakend"))
Expand Down Expand Up @@ -1139,6 +1189,7 @@ function muxAnalytics() as Object
if m._contentPlaybackTime = Invalid then return

m._viewWatchTime = m._viewTimeToFirstFrame + m._viewRebufferDuration + m._contentPlaybackTime
m._cumulativePlayingTime = m._viewWatchTime + m._totalAdWatchTime
end sub

prototype._setBufferingMetrics = sub()
Expand Down Expand Up @@ -1275,6 +1326,9 @@ function muxAnalytics() as Object
end if
m._viewId = m._generateGUID()
m._viewWatchTime = 0
m._adWatchTime = 0
m._totalAdWatchTime = 0
m._cumulativePlayingTime = 0
m._contentPlaybackTime = 0
m._viewRebufferCount = 0
m._viewRebufferDuration = 0
Expand Down Expand Up @@ -1329,6 +1383,10 @@ function muxAnalytics() as Object
m._playerTimeToFirstFrame = Invalid
m._contentPlaybackTime = Invalid
m._viewWatchTime = Invalid
m._adWatchTime = Invalid
m._lastAdResumeTime = Invalid
m._totalAdWatchTime = Invalid
m._cumulativePlayingTime = Invalid
m._viewRebufferCount = Invalid
m._viewRebufferDuration = Invalid
m._viewRebufferFrequency! = Invalid
Expand Down Expand Up @@ -1689,6 +1747,12 @@ function muxAnalytics() as Object
if m._viewRequestCount <> Invalid
props.view_request_count = m._viewRequestCount
end if
if m._cumulativePlayingTime <> Invalid AND m._cumulativePlayingTime > 0
props.view_playing_time_ms_cumulative = m._cumulativePlayingTime
end if
if m._totalAdWatchTime <> Invalid AND m._totalAdWatchTime > 0
props.ad_playing_time_active_ms_cumulative = m._totalAdWatchTime
end if
if m._configProperties <> Invalid AND m._configProperties.player_init_time <> Invalid
playerInitTime = Invalid
if Type(m._configProperties.player_init_time) = "roString"
Expand Down Expand Up @@ -2037,6 +2101,7 @@ function muxAnalytics() as Object
"asset": "as",
"autoplay": "au",
"average": "av",
"active": "ac",
"bitrate": "bi",
"brand": "bn",
"break": "br",
Expand All @@ -2063,6 +2128,7 @@ function muxAnalytics() as Object
"current": "cu",
"connection": "cx",
"context": "cz",
"cumulative": "cv",
"downscaling": "dg",
"domain": "dm",
"cdn": "dn",
Expand Down Expand Up @@ -2124,6 +2190,7 @@ function muxAnalytics() as Object
"manufacturer": "mn",
"model": "mo",
"mux": "mx",
"ms": "ms",
"newest": "ne",
"name": "nm",
"number": "no",
Expand Down