Google Analytics

I am trying to do event logging through Google Analytics to track both how many times the channel is opened but also the plays on each video. I think some of the code like the domain and page path are irrelevant below since I’m doing an event and not a page view. However… I am not seeing this being logged in my Google Analytics account. And, yes, I realize this is a synchronous call… I just wanted to make sure it was getting done so didn’t make it async at this point.

You see anything wrong with this??


Sub Analytics_LogEvent(category, action, label)

	google_account = "XXXXXXXX"

	url = "http://www.google-analytics.com/__utm.gif?"
	url = url + "utmac=" + google_account			' Google account
	url = url + "&utmhn=roku.milesplit.com"			' Domain
	url = url + "&utmje=0" 					' Not Java Enabled
	url = url + "&utmp=/roku"				' Page Path
	url = url + "&utmt=event"				' Event or Page
	url = url + "&utmwv=1"					' Tracking version
	url = url + "&utme=5("
	url = url + category
	url = url + "*"
	url = url + action
	url = url + "*"
	url = url + label
	url = url + ")(1)"

	xfer = CreateObject("roURLTransfer")
	xfer.SetURL(url)
	response = xfer.GetToString()

End Sub

Is it possible that some of the parameters need to be URLEncoded, like the ( and ) brackets?

My suggestion for troubleshooting is to put ?xfer.geturl() after xfer.seturl() and make sure it looks like you expect it to, then copy the url from your console and try it in a web browser.

  • Joel

You might want to add print statements just before the function exits to display the url and response, then try typing the same url into a web browser to see if it is working:


print "url=" + url
print "response=" + response

Also, it may be unrelated to your problem, but it might be a good idea to escape the parameters in the url query string in case they contain any weird characters:


ut = CreateObject ("roUrlTransfer")    ' Create a roUrlTransfer object
'
'
url = url + ut.Escape (category)       ' ... etc. Escape each of your query parameters

And like RokuJoel said above, escape the parameters containing “(”. And I think the asterisks may need to be escaped too, e.g:


url = url + "&utme=5" + ut.Escape ("(")
'
'
url = url + ut.Escape ("*")
'
url = url + ut.Escape (")(1)")

milesplit - Did you manage to get it working? Can you please share the complete code?

We are planning to implement google analytics for both Roku as well as Web player. On the web we use jw player a plugin for google analytics is available.

Will it be possible to combine the information?

-Sunny

I would also really appreciate a look at your final implementation. We have struggled with this for a while.