uarlive
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2014
03:39 PM
Google Universal Analytics
I am having trouble with logging events using the Measurement Protocol for Universal Google Analytics. Below is the function in question. I know spaces have to be urlencoded but I cant seem to get xfer.Escape or xfer.urlencode to work on the payload. Any help in the right direction is appreciated. Thanks.
in the video brs file I am calling
the episode.title has spaces in it.
Function UA_trackEvent(EventCat as String , EventAct as String , EventLab as String , EventVal as String) as Void
payload = "v=1"
payload = payload + "&uid=" + m.UATracker.userID
payload = payload + "&cid=" + m.UATracker.clientID
payload = payload + "&tid=" + m.UATracker.AccountID
payload = payload + "&dimension1=" + m.UATracker.model
'payload = payload + "&dimension2=" + m.UATracker.DisplayName
payload = payload + "&sr=" + m.UATracker.display
payload = payload + "&sd=" + m.UATracker.ratio
payload = payload + "&dr=" + config().trafSource
'payload = payload + "&an=" + m.UATracker.appName
'payload = payload + "&av=" + m.UATracker.appVersion
payload = payload + "&t=" + "event"
If Len(EventCat) > 0
payload = payload + "&ec=" + EventCat <-- problem area
end if
If Len(EventAct) > 0
payload = payload + "&ea=" + EventAct
end if
If Len(EventLab) > 0
payload = payload + "&el=" + EventLab <-- problem area
end if
If Len(EventVal) > 0
payload = payload + "&ev=" + EventVal
end if
xfer = CreateObject("roURLTransfer")
xfer.Addheader("x-roku-reserved-dev-id","")
xfer.SetURL(m.UATracker.endpoint + "?" + payload + "&z=" + GetRandomInt(10))
response = xfer.GetToString()
End Function
in the video brs file I am calling
UA_trackEvent("Video Plays", "play", episode.title, "")
the episode.title has spaces in it.
3 REPLIES 3


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2014
04:01 PM
Re: Google Universal Analytics
"uarlive" wrote:
I cant seem to get xfer.Escape or xfer.urlencode to work on the payload.
If you're escaping the whole payload, you're going to end up encoding characters that are part of the structure of the URL and shouldn't be encoded (?, &, =). Be sure you are only escaping the parameter values.
uarlive
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2014
04:43 PM
Re: Google Universal Analytics
Thanks.
I tried this as well.
It returned this error.
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...MHenu/pkg:/source/GAStats.brs(95)
095: payload = payload + "&ec=" + (xfer.Escape(EventCat))
Backtrace:
Function ua_trackevent(eventcat As , eventact As , eventlab As , eventval As ) As
file/line: /tmp/plugin/JGAA...MHenu/pkg:/source/GAStats.brs(95)
Function main() As
file/line: /tmp/plugin/JGAAAADMHenu/pkg:/source/appMain.brs(12)
I tried this as well.
payload = payload + "&t=" + "event"
If Len(EventCat) > 0
payload = payload + "&ec=" + xfer.Escape(EventCat)
end if
If Len(EventAct) > 0
payload = payload + "&ea=" + xfer.Escape(EventAct)
end if
If Len(EventLab) > 0
payload = payload + "&el=" + xfer.Escape(EventLab)
end if
If Len(EventVal) > 0
payload = payload + "&ev=" + EventVal
end if
It returned this error.
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...MHenu/pkg:/source/GAStats.brs(95)
095: payload = payload + "&ec=" + (xfer.Escape(EventCat))
Backtrace:
Function ua_trackevent(eventcat As , eventact As , eventlab As , eventval As ) As
file/line: /tmp/plugin/JGAA...MHenu/pkg:/source/GAStats.brs(95)
Function main() As
file/line: /tmp/plugin/JGAAAADMHenu/pkg:/source/appMain.brs(12)
uarlive
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2014
04:47 PM
Re: Google Universal Analytics
I figured it out.
xfer = CreateObject("roURLTransfer")
Was moved to the top of the function. I was calling it prematurely. Thanks for the help.
xfer = CreateObject("roURLTransfer")
Was moved to the top of the function. I was calling it prematurely. Thanks for the help.