Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GoogleAnalytics unique visitor

Hi,

I have implemented GoogleAnalytics for roku with this tutorial:
http://bloggingwordpress.com/2012/04/go ... evelopers/

the code works great, EXCEPT that I can’t get it to work for the unique visitor on GoogleAnalytics.

I am using the GATrackPageView(“Page Title”, “Page URL”, “User Value”) with fixed values.

- Every time I close and start my channel on ROKU, I get the record on the GoogleAnalytics page, BUT it’s every time a NEW unique visitor.
- BUT if I run the same GoogleAnalytics link directly in the browser, it’s working properly (records every visit but only ONE unique visitor).

Example link: http://analytics.somedomain.com/ga.php? ... debug=true

Is someone facing the same problem?
Did someone manage to make it work for unique visitor?

Simon
0 Kudos
9 REPLIES 9
shumanity
Visitor

Re: GoogleAnalytics unique visitor

I had a few issues with that helper script also and eventually rewrote most of it, but that was largely because I needed to track events with custom variables. To handle visitor IDs, I'd try setting a utmvid= parameter in the Google Analytics URL to the Roku's unique ID. That way each Roku will identify itself consistently. You can get the unique ID using roDeviceInfo (GetDeviceUniqueId).
0 Kudos

Re: GoogleAnalytics unique visitor

I've set the utmvid parameter with the DeviceUniqueId and still the analytics records every time a new unique user.
And still if I run the link directly in the browser it works correctly. :?

Does your rewritten code record a unique user correctly?
Any other ideas?
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: GoogleAnalytics unique visitor

Have you tried replacing the UA prefix on your property ID with MO? https://developers.google.com/analytics ... leWebsites
0 Kudos
shumanity
Visitor

Re: GoogleAnalytics unique visitor

Huh, now I have no idea where I read about utmvid, it doesn't seem to be working as desired. I took a look and just about everything is showing up as non-unique. Here's hoping that the new GA Measurement Protocol is easier to use...

I've never used the MO stuff RokuChris linked to, that could work. I also found a pretty good explanation of the cookie parameters at http://www.tutkiun.com/2011/04/a-google-analytics-cookie-explained.html. Using that as a guide, things seem to work if I use the registry to keep track of things. Something like this (using a RegRead helper that takes a default value if the key doesn't exist... you get the idea):


' Initialize our "cookies"
domainHash = "1234567890" ' Change this, should be unique for the domain (usually set by google)
visitorID = RegRead("AnalyticsID", "analytics", invalid)
if visitorID = invalid then
visitorID = GARandNumber(1000000000,9999999999).ToStr()
RegWrite("AnalyticsID", visitorID, "analytics")
end if

timestamp = CreateObject("roDateTime")
firstTimestamp = RegRead("FirstTimestamp", "analytics", invalid)
prevTimestamp = RegRead("PrevTimestamp", "analytics", invalid)
curTimestamp = timestamp.asSeconds().ToStr()

RegWrite("PrevTimestamp", curTimestamp, "analytics")
if prevTimestamp = invalid then prevTimestamp = curTimestamp
if firstTimestamp = invalid then
RegWrite("FirstTimestamp", curTimestamp, "analytics")
firstTimestamp = curTimestamp
end if

numSessions = RegRead("NumSessions", "analytics", "0").toint() + 1
RegWrite("NumSessions", numSessions.ToStr(), "analytics")

url = url + "&utmcc=__utma%3D" + domainHash + "." + visitorID + "." + firstTimestamp + "." + prevTimestamp + "." + curTimestamp + "." + numSessions.tostr()
url = url + "%3B%2B__utmb%3D" + domainHash + ".0.10." + curTimestamp + "000"
url = url + "%3B%2B__utmc%3D" + domainHash + ".0.10." + curTimestamp + "000"


I'm only using events, not pageviews, so I'm not worrying about the .0 value in the utmb/utmc cookies. I'm not sure if you'll want to increment that on each request. Good luck. :]
0 Kudos
bosborne
Visitor

Re: GoogleAnalytics unique visitor

The above code is good, but you wouldn't want to run that for every event. The info relating to a visit, such as first time, prev time, and cur time should be set relative to what you consider a visit. Is every event triggered within the Roku app a visit? No. Probably just the initial app launch is. So you'd want to set that info on app launch and use the same timestamps and whatnot for every event tracked while that app is opened. Then when the user closes the app, you can recalculate the values and register a new visit.
0 Kudos
shumanity
Visitor

Re: GoogleAnalytics unique visitor

FWIW, the new measurement protocol is now available for Google Analytics - https://developers.google.com/analytics ... otocol/v1/

In my opinion, it's a much better fit for analytics on the Roku. All of the parameters are documented, and there's no need to mess around with fake cookies.
0 Kudos
bosborne
Visitor

Re: GoogleAnalytics unique visitor

Absolutely, 100% agree with going w/ the new Measurement Protocol. I just implemented it last night in the Roku for event tracking. Far less code and much more straight forward. No need to reverse engineer what their parameters are, everything is clearly documented.

https://developers.google.com/analytics ... otocol/v1/
0 Kudos
snagfilms
Visitor

Re: GoogleAnalytics unique visitor

Can you guys share some sample code here
0 Kudos
snagfilms
Visitor

Re: GoogleAnalytics unique visitor

Can you share some same code for v1 protocol
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.