-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Events tracked via Resque never appear #14
Comments
I'm less familiar with Resque, but do your workers run in new processes or threads? If that's the case, you'll have to call Analytics.flush shouldn't work for a minute in that case though, it should just exit immediately if there aren't any messages to be processed Here's the code another one of our users have implemented: module Segment
module Tracking
def self.perform(action, data)
data.symbolize_keys!
data.values.each { |v| v.symbolize_keys! if v.is_a? Hash }
Analytics.init secret: APP_CONFIG[:segment_secret]
Analytics.send action, data
Analytics.flush
end
def track_event(name, properties)
data = { user_id: current_user.id.to_s, event: name, properties: properties }
Resque.enqueue Segment::Tracking, 'track', data
end
def identify_user(event)
traits = { email: current_user.email,
name: current_user.name }
data = { user_id: current_user.id.to_s, traits: traits }
Resque.enqueue Segment::Tracking, 'identify', data
end
end
end |
Calling Analytics.init does solve this issue. I'll go ahead and close it. For the record, whichever user wrote this code would probably benefit from the changes I made last night. It should prevent them from needing to symbolize keys. They're symbolizing recursively, which I didn't account for, but I think analytics-ruby only looks one level deep in the hash for its keys anyway. Also, if they're using ActiveSupport (which it seems like they are based on the presence of symbolize_keys!), they should look into Hash#with_indifferent_access. |
It might be worth adding a small snippet somewhere in the documentation that specifically highlights the need to call Analytics.init when a new process/thread spins up. It's covered in the Passenger + Unicorn sections, but it didn't jump out at me with regard to Resque (although it's obvious in hindsight). Thanks! |
I have a tracking job that I'm enqueueing via Resque. It's a fairly simple passthrough to Analytics.track:
However, I'm never seeing these statistics show up in Segment.io or any of the connected accounts.
Per the documentation, I also tried with
but that just sits there for about a minute, then appears to timeout.
If I call Analytics.track directly in a console or in that after_filter, it works as expected.
Any thoughts? Am I doing something horribly wrong?
The text was updated successfully, but these errors were encountered: