Now updated to 2.0 this version includes:
*NEW* Event tracking now supported
Better use of the global this (m) for tracking variables
Added debug and pretend mode
Download and instructions here:
http://bloggingwordpress.com/2012/04/google-analytics-for-roku-developers/-----------------------------------------------------------------------------------
OLD v1.1 Below - I strongly suggest using the updated v2.0 code aboveI've updated this to version 1.1 - It now is easier to setup, I've added language support as requested by jeremyk and it now includes television mode and resolution in the reporting. You can get it the updated version 1.1 here -
http://bloggingwordpress.com/2012/04/google-analytics-for-roku-developers/-----------------------------------------------------------------------------------
OLD v1.0 Code Below - I strongly suggest using the updated v2.0 code aboveThought I'd share my code for how I'm tracking stuff in my channel with Google Analytics. Just wrote this today, it does work, but I haven't done any extensive testing with it. Simple enough to use though, just give it what you'd like to show up under Page in GA, it also supports a User Defined Variable if you want to set that, or leave it empty "". Call it using analyticsPageView("Whatever You'd Like To Register As Page","User Defined Variable")
Replace the ** Google Account ** variable with your own and ** Domain ** too.
REM ****************************************
REM ** Tracking Code for Google Analytics **
REM ****************************************
Function analyticsPageView(var_URI As String, var_uservar As String)
timestamp = CreateObject("roDateTime")
xfer = CreateObject("roURLTransfer")
var_utmac = "XX-XXXXXXXX-X" '** Google Account **
var_utmhn = "roku.whatever.com" '** Domain **
var_utmn = stri(randNumber(1000000000,9999999999)) 'Random Request Number
var_utmn = right(var_utmn,len(var_utmn)-1) 'Remove Space Added By Stri()
var_cookie = stri(randNumber(1000000000,9999999999)) 'Random Cookie Number
var_cookie = right(var_cookie,len(var_cookie)-1) 'Remove Space Added By Stri()
var_random = stri(randNumber(1000000000,2147483647)) 'Random Number Under 2147483647
var_random = right(var_random,len(var_random)-1) 'Remove Space Added By Stri()
var_today = stri(timestamp.asSeconds()) 'Unix Timestamp For Current Date
var_today = right(var_today,len(var_today)-1) 'Remove Space Added By Stri()
var_referer = "Roku" 'Referer Url (Doesn't Exist Here)
if len(var_uservar) = 0 var_uservar = "Roku" 'User Defined Variable
if len(var_URI) = 0 var_URI = "Roku" 'URL For Page View
urchin_url = "http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=" + var_utmn
urchin_url = urchin_url + "&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=" + var_utmhn
urchin_url = urchin_url + "&utmr=" + var_referer
urchin_url = urchin_url + "&utmp=" + xfer.Escape(var_URI)
urchin_url = urchin_url + "&utmac=" + var_utmac
urchin_url = urchin_url + "&utmcc=__utma%3D" + var_cookie
urchin_url = urchin_url + "." + var_random
urchin_url = urchin_url + "." + var_today
urchin_url = urchin_url + "." + var_today
urchin_url = urchin_url + "." + var_today
urchin_url = urchin_url + ".2%3B%2B__utmb%3D" + var_cookie
urchin_url = urchin_url + "%3B%2B__utmc%3D" + var_cookie
urchin_url = urchin_url + "%3B%2B__utmz%3D" + var_cookie
urchin_url = urchin_url + "." + var_today
urchin_url = urchin_url + ".2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D" + var_cookie
urchin_url = urchin_url + "." + xfer.Escape(var_uservar) + "%3B"
xfer.SetURL(urchin_url)
response = xfer.GetToString()
End Function
Function randNumber(num_min As Integer, num_max As Integer) As Integer
return (RND(0) * (num_max - num_min)) + num_min
End Function
*** Trevor Anderson - bloggingwordpress.com - moviemavericks.com ***