Forum Discussion

simon_safhalter's avatar
13 years ago

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

9 Replies

  • 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).
  • 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?
  • 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. :]
  • 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.