Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dcrandall
Visitor

Analytics, how do I know when a window is closed, elegantly?

Letting analytics know a new screen has opened is pretty trivial.

Letting analytics know a screen has gone out of scope and closed, or been closed with the .Close() function, is not very easy to do, elegantly.

Right now I have a pretty depthy (gets to like 6-8 screens) application using the screen stack model.

What I need is some way to let analytics know "oh, they closed that window, tell analytics that I'm seeing the window 'underneath' again"

Currently I do, by maintaining a separate stack/last.  Before a screen gets closed, I call a 'notify analytics of a close' which will re show the screen underneath to analytics.

There has to be a better way.  Ideas?
0 Kudos
7 REPLIES 7
EnTerr
Roku Guru

Re: Analytics, how do I know when a window is closed, elegantly?

"dcrandall" wrote:
What I need is some way to let analytics know "oh, they closed that window, tell analytics that I'm seeing the window 'underneath' again"

What do you mean in "they closed that window"? Who is "they" and how did "they closed" a window?
0 Kudos
dcrandall
Visitor

Re: Analytics, how do I know when a window is closed, elegantly?

Excuse me, 'screens'.  Say I'm following this model:

https://sdkdocs.roku.com/display/sdkdoc ... th+Screens

Sub ShowPosterScreen()
    port = CreateObject("roMessagePort")
    poster = CreateObject("roPosterScreen")
    poster.SetMessagePort(port)
    ' Set up screen
 
    poster.show()
    While True
        message = Wait(0, port)
        If message.isScreenClosed()
            Exit While
        else if message.isListItemSelected()
            ShowSpringboardScreen( < get content details using > message.getIndex())
        end if
    End While
End Sub
 
Sub ShowSpringboardScreen()
    port = CreateObject("roMessagePort")
    springBoard = CreateObject("roSpringboardScreen")
    springBoard.SetMessagePort(port)
    ' Set up screen...
 
    springBoard.Show()
    While True
        message = wait(0, port)
        If message.isScreenClosed() Then
            Exit While
        Else If message.isButtonPressed() Then
            ' Process menu items...
        End If
    End While
    ' Returning destroys the 'springBoard' variable, which closes the
    ' springboard screen, and reveals the poster screen again.
End Sub




The second springboard in "ShowSpringboardScreen" exits, the screen goes out of scope...   is there any way to know that screen isn't being displayed anymore?
0 Kudos
RokuMarkn
Visitor

Re: Analytics, how do I know when a window is closed, elegantly?

When the springboard closes, the call to ShowSpringboardScreen returns.  Just put your analytic call right after the call to ShowSpringboardScreen.

--Mark
0 Kudos
dcrandall
Visitor

Re: Analytics, how do I know when a window is closed, elegantly?

That works, but I was more hoping to have something a little more foolproof and non-invasive from a user standpoint.   If I were, say, writing a library. 
0 Kudos
EnTerr
Roku Guru

Re: Analytics, how do I know when a window is closed, elegantly?

Oh, i thought you were using the hobgoblinography, it would have been more elaborate there.
But with "SDK classic"? I don't see an issue there, since your code *has* to be in-sync with what's on screen anyway. I.e. the message loops have to be entered and exited to match what's on screen (baring a more elaborate DIY framework). And in that case you can decide to either handle this in the `if ....isScreenClosed()` of the subscreen - or in the parent, when ShowBlahDeBlah() returns - either way. 
"dcrandall" wrote:
That works, but I was more hoping to have something a little more foolproof and non-invasive from a user standpoint.   If I were, say, writing a library. 

I don't understand - who is the "user" in this case? What's getting invaded and who's getting fooled 🙂 but seriously i don't get the sentiment
0 Kudos
dcrandall
Visitor

Re: Analytics, how do I know when a window is closed, elegantly?

basically having something that sorta said, "throw this on your screens like salt" and BOOM, you have analytics of user behavior.   

Like, I want one call 'analyze.this()' and badda-bing-badda-boom, you know how they're navigating.  You know that they saw a poster screen and saw the movie "Breakin' 2: electric boogaloo" and ejected out of the app.

But...having a begin/end isn't bad.

But you do have to know, "ok, we're back viewing navigating this screen" and re-call analytics to say, "hey, they're back here again!"

So....

Sub ShowPosterScreen()
    port = CreateObject("roMessagePort")
    poster = CreateObject("roPosterScreen")
    poster.SetMessagePort(port)
    ' Set up screen
 
    poster.show()
    While True
   call_analytics("Showing poster screen!")
        message = Wait(0, port)
        If message.isScreenClosed()
            Exit While
        else if message.isListItemSelected()
            ShowSpringboardScreen( < get content details using > message.getIndex())
        end if
    End While
End Sub
 
Sub ShowSpringboardScreen()
    port = CreateObject("roMessagePort")
    springBoard = CreateObject("roSpringboardScreen")
    springBoard.SetMessagePort(port)
    ' Set up screen...
 
    springBoard.Show()
    While True
call_analytics("Showing springboard screen")
        message = wait(0, port)
        If message.isScreenClosed() Then
            Exit While
        Else If message.isButtonPressed() Then
            ' Process menu items...
        End If
    End While
    ' Returning destroys the 'springBoard' variable, which closes the
    ' springboard screen, and reveals the poster screen again.
End Sub


It actually...  not that bad.   Man, I tried to make something simple and it ended-up complicated.
0 Kudos
EnTerr
Roku Guru

Re: Analytics, how do I know when a window is closed, elegantly?

"dcrandall" wrote:
It actually...  not that bad.   Man, I tried to make something simple and it ended-up complicated.

Ah, i know that symptom 🙂 -
You try to generalize it and it becomes way too complicated.
In this case you can look at your code and notice the common pattern of while-loop message pump, analytics, exit - so potentially can extract it - but then will have to inject the custom code into that framework...

If you really, really want to simplify it - maybe could be done but it may cost 10x the effort, so cost/benefit?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.