Skip to content

Instantly share code, notes, and snippets.

@bkutil
Created March 18, 2013 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkutil/5185839 to your computer and use it in GitHub Desktop.
Save bkutil/5185839 to your computer and use it in GitHub Desktop.
Wrapper around Gabba to report events in background using Sidekiq's delay.
class GA
def self.track(type, args, cookies = nil, request = nil)
begin
self.delay(:queue => :analytics).track_send(type, args, cookies, request)
rescue Redis::CannotConnectError => e
Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
end
end
private
def self.track_send(type, args, cookies = nil, request = nil)
return if Rails.env == "test"
ga = Gabba::Gabba.new(Settings.analytics.tracking_code, Settings.analytics.tracking_domain)
ga.identify_user(cookies[:__utma], cookies[:__utmz]) if cookies
ga.referrer(request[:referrer]) if request && request[:referrer]
ga.ip(request[:ip]) if request && request[:ip]
ga.send(type, *args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment