Skip to content

A Brightscript (Roku) library for submitting analytics to Amplitude

License

Notifications You must be signed in to change notification settings

gabek/Amplitude-Brightscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

Amplitude-Brightscript

A BrightScript interface to Amplitude event tracking

If you're in the market to add analytics to your Roku application this might be the solution for you.

Setup

  1. Copy Analytics.brs to your source folder.
  2. Decide how you're going to reference the "user". If they have an actual user ID, or email address, or username and are logged in to a session, then use those. Otherwise User = createObject("roDeviceInfo").GetDeviceUniqueId() is a great way to uniquely identify.
  3. Get access to the message port that's being used in your global event loop.
  4. And in your Session, or somewhere else that's persistant, create an instance of the Analytics object via the following: Analytics = Analytics("UserIdentifier", "AmplitudeAPIKey", YourEventLoopPort)

###Example MessagePort = GetGlobal().MessagePort User = createObject("roDeviceInfo").GetDeviceUniqueId() ApiKey = "ABCD1234"

Analytics = Analytics(User, ApiKey, MessagePort)

'My event loop
while true
    msg = wait(0,MessagePort)
    'You do stuff with events in your app here
    Analytics = GetSession().Analytics
    Analytics.HandleAnalyticsEvents(msg)
end while

Tracking

Utilizing your reference to the Analytics object you initialized above you can make tracking calls using ViewScreen, and AddEvent.

###Screen Views ViewScreen takes a simple string parameter like so: Analytics.ViewScreen("VideoContentGridScreen")

###Events LogEvent takes in a string with the event that took place and an optional roAssociativeArray of details for your event.

details = CreateObject("roAssociativeArray")
details.buttonName = "Back"

Analytics = GetSession().Analytics
Analytics.AddEvent("Button Pressed", details)

Details

All events are queued up and sent as batches to Amplitude. This is why the timer needs to be ping'ed during the event loop. The events are sent every 60 seconds as long as your event loop is still active.

About

A Brightscript (Roku) library for submitting analytics to Amplitude

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published