simon_safhalter
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2013
03:47 AM
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
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
9 REPLIES 9
shumanity
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2013
06:51 PM
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).
simon_safhalter
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2013
03:50 AM
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?
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?


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2013
10:15 AM
Re: GoogleAnalytics unique visitor
Have you tried replacing the UA prefix on your property ID with MO? https://developers.google.com/analytics ... leWebsites
shumanity
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2013
10:47 AM
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):
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. :]
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. :]
bosborne
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2013
04:54 PM
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.
shumanity
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2013
08:58 AM
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.
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.
bosborne
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2013
06:21 AM
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/
https://developers.google.com/analytics ... otocol/v1/
snagfilms
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2013
03:58 PM
Re: GoogleAnalytics unique visitor
Can you guys share some sample code here
snagfilms
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2013
03:59 PM
Re: GoogleAnalytics unique visitor
Can you share some same code for v1 protocol