Created
March 18, 2013 08:56
-
-
Save bkutil/5185839 to your computer and use it in GitHub Desktop.
Wrapper around Gabba to report events in background using Sidekiq's delay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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