jam-cloud/ruby/lib/jam_ruby/resque/google_analytics_event.rb

43 lines
1018 B
Ruby

class GoogleAnalyticsEvent
@queue = 'google_analytics_event'
@@log = Logging.logger[GoogleAnalyticsEvent]
def self.perform(category, action)
@@log.info("starting (#{category}, #{action})")
run(category, action)
@@log.info("done (#{category}, #{action})")
end
def self.enqueue(category, event)
begin
Resque.enqueue(AudioMixer, category, event)
true
rescue
# implies redis is down. but since there is no retry logic with this, we should at least log a warn in case we've configured something wrong
@@log.warn("unable to enqueue")
false
end
end
def self.run(category, action)
raise "no google analytics tracking ID" unless APP_CONFIG.ga_ua
params = {
v: APP_CONFIG.ga_ua_version,
tid: APP_CONFIG.ga_ua,
cid: APP_CONFIG.ga_anonymous_client_id,
t: "event",
ec: category,
ea: action
}
RestClient.post(APP_CONFIG.ga_endpoint, params: params, timeout: 8, open_timeout: 8)
end
end