Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabek/Amplitude-Brightscript
A Brightscript (Roku) library for submitting analytics to Amplitude
https://github.com/gabek/Amplitude-Brightscript
Last synced: 3 months ago
JSON representation
A Brightscript (Roku) library for submitting analytics to Amplitude
- Host: GitHub
- URL: https://github.com/gabek/Amplitude-Brightscript
- Owner: gabek
- License: mit
- Created: 2015-07-12T00:54:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-17T21:59:34.000Z (over 8 years ago)
- Last Synced: 2024-04-21T06:34:39.717Z (7 months ago)
- Language: Brightscript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Amplitude-Brightscript
======================A [BrightScript](http://sdkdocs.roku.com/display/sdkdoc/BrightScript+Language+Reference) interface to [Amplitude](https://amplitude.zendesk.com/hc/en-us/articles/204771828-HTTP-API) 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](http://sdkdocs.roku.com/display/sdkdoc/roMessagePort) 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](http://sdkdocs.roku.com/display/sdkdoc/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.