Search code examples
sessiongoogle-analyticsuniversal-analytics

Store Universal Google Analytics inside server session


I have a unique situation with two separate domains. I'm having trouble with session data from the main website not carrying over with the decorator (most users are coming over as (direct) / (none) after excluding the unsecure domain). In trying to fix this, I realized that decorator has an edge case where this won't work. We offer PayPal as a payment option and while I pass the decorator along, there's a chance the user could take longer than the 2 minutes that decorate allows. While uncommon, I would prefer to not lose any data if possible. So I dug into the cross-domain page further and found that you can pass the cookie directly into GA

ga('create', 'UA-XXXX-Y', 'auto', {
  'clientId': clientId
})

The cookie has a much longer life (2 years) than the tracker so I've considered extracting the GA session ID from the cookie which looks like this (emphasis on the actual ID)

GA1.2.1948991702.1414423123

That part is easy, and once stored in my server session I could then pass it back in at will. My question is will this retain the session data in general? I'm kinda hoping this also solves the referral problem (causing issues with Adwords). Has anyone tried storing a UA session in a server session? Are there any pitfalls I've missed?


Solution

  • I finally got this working by doing the steps outlined above. I have no idea why the decorator method doesn't work but directly passing clientID did the trick.