I use Google Analytics to track pageviews, etc. but late last week I had the desire to track an event on the backend.
I discovered gabba.
I have a method within my User model that looks like this:
def track_ga(event_name, cookiea, cookiez, event_category=nil)
return unless Rails.env.production?
gabba = Gabba::Gabba.new("UA-MYCODE-1", "mywebsite.com")
gabba.identify_user(cookiea, cookiez)
gabba.set_custom_var(1, 'User Email', self.email, Gabba::Gabba::VISITOR)
gabba.set_custom_var(2, 'Private Code', private_code, Gabba::Gabba::VISITOR) if private_code
gabba.event(event_category || "Users", event_name, nil, nil)
end
However it's not working correctly, here are the results in GA:
To me, that suggests that the cookies are not correctly associated, i.e. it has no idea of where they previously visited (before this event was tracked). Perhaps I am misunderstanding the nature of this report but, assuming I'm not, I'd love some advice on where I'm going wrong.
Looks like the analytics.js code changed recently and perhaps it's caused an issue with gabba:
https://github.com/hybridgroup/gabba/issues/25
I use gabba for custom events to keep track of # of new user signups, and it seems to be working ok though may be overinflating my #hits count per the issue above.
gabba = Gabba::Gabba.new("UA-blah", "mysite.com")
gabba.identify_user(cookies[:__utma])
gabba.event(kind, action, title, 0, true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With