Skip to content

Instantly share code, notes, and snippets.

@timgl
Created January 31, 2020 18:37
Show Gist options
  • Save timgl/599cee52740b56af461abe12701e8855 to your computer and use it in GitHub Desktop.
Save timgl/599cee52740b56af461abe12701e8855 to your computer and use it in GitHub Desktop.
# In your time-sensitive process
tracker = Mixpanel::Tracker.new(YOUR_POSTHOG_TOKEN) do |type, message|
@queue.set('mixpanel_queue', [ type, message ].to_json)
end
# Track just like you would in any other situation
tracker.track(user_id, 'Sent Message')
tracker.people.increment(user_id, {
'Messages Sent' => 1
})
# In a worker process on another machine
mixpanel = Mixpanel::Consumer.new(events_endpoint='https://t.posthog.com/track', update_endpoint='https://t.posthog.com/engage', groups_endpoint='https://t.posthog.com/groups', import_endpoint='https://t.posthog.com/import')
loop do
job = @queue.get('mixpanel_queue')
mixpanel.send!(*JSON.load(job))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment