Make custom object globally available on the app

Hi Roku lovers,

i’m trying to put a global object full of functions and attributes that allows the app to report videoplayer events and app events to Google Analytics, the app uses SceneGraph 
i’ve tried put the object into ‘m.global’ on ‘main.brs’ file, but the scope is not global, it only works on that file.
i’ve tried to create a notification port and listen to it, but when setting ‘m.port’ on player.ObserveField(“position”,“m.port”) in another file, the ‘m.port’ property is invalid, again a scope problem.

The custom object has the following structure:


function GA() as Object
return{  
          init : function (init_args) as Void
          //init code
         end function

         func_1 : function()

         end function
       'and many other functions to report events
      }

there is one method that will receive all the notifications “handleScenegraphEvent”, notification in form of messages of node.ObserveField

i’ve tried putting the object into ‘m’ as follows in ‘main.brs’:

gareporter = GA()
gareporter.init("UAID123456","RokuEvent[size=100]")[/size]
m.reporter ={}
m.reporter = gareporter

and

m.addField("reporter","asocarray",true)
gareporter = GA()
gareporter.init("UAID123456","FusionRoku")
m.reporter = gareporter

while working on the same file the property ‘m.reporter’ is accesible, but when the code is coming from another file, the property is null.

i hope the question is clear enough to give me some hints.

Thanks for your help

To access the “global Noid” from main, you have to call roSGScreen.getGlobalNode(). For consistency, it’s advisable in main() you manually assign that to m.global and continue using that m.global, as in other threads:

m.global = screen.getGlobalNode()

But guess what… even then you can’t do what you want, because RSG Nodes do not support function type[/url:1jq54gt9]! Methods will be stripped, silently but deadly. Because… the SceneGraph Maker, blessings be upon him.

Hey, thanks for the quick reply, i just find out that problem with function type, my second option is setting a global port to all fields i want to observe, can i use “m.global = screen.getGlobalNode” to pass the port all over the app?

“cescamilla” wrote:
Hey, thanks for the quick reply, i just find out that problem with function type, my second option is setting a global port to all fields i want to observe, can i use “m.global = screen.getGlobalNode” to pass the port all over the app?
You mean, do roSgNode fields support roMessagePort (or more generally, Object) type? No, they do not!
A list of what is supported is here a very particular set of skills.

then it seems like a dead end for what i want to do :disappointed_face:

If you want to do what you say you want to do: report video player events to Google Analytics, then define a Task Node to do the reporting. Include the Task Node in your scene that contains the Video Node, then whenever you have an event to log, set the event details in an interface field defined on the Task Node; in the Task Node, use roUrlTransfer to send the request to Google Analytics.

Thanks, will read about it and try it.

@Veeta

Thanks for the reply, i’m playing with the code, but i have a question:

i see the reporting methods are used in ‘main.brs’, are they available too in the scenes where the video is played?

right now this test is failing:

GoogleAnalyticsTestSuite: initializeSingleTIDroString - Fail

i’m checking the code

also the app starts and go back to home screen in Roku

Roku 4 - software version 7.5.0

telnet console shows no error messages

just this:

------ Compiling dev ‘roku-gamp’ ------
------ Running dev ‘roku-gamp’ main ------
Enabling tracking analytics

ohh i see, that’s the full app cycle, i’m able to see requests been made, but not reflected in Google Analytics Dashboard, i’ll worry about that later, for now i’ll check how to integrate that functionality with the existing app.

Thanks a lot!

Thanks for the failing test note. That was a preemptive test for a corner case which is unlikely to happen. I opened a github issue to track it https://github.com/veeta-tv/roku-gamp/issues/13.

Make sure you put your tracking id in https://github.com/veeta-tv/roku-gamp/blob/master/roku-gamp/components/GampTask.xml. The SceneGraph thread instance of the GAMP library is unique from the main brightscript thread instance, so it needs the initialization set there as well.