Mixpanel API call only in Rails production environment

I am currently using mixpanel with the standard 'mixpanel' gem for analytics and has some calls configured in my controllers. I would like these calls to be carried out only in a working environment. The best way to do this for each call:

@mixpanel.track_event("Job Accepted", {:user=> current_user.id}) if RAILS_ENV == 'production'

This seems to be too much, but I try to think of a better solution. Any help would be great!

+3
source share
3 answers

You have the right idea. Although you can use:

Rails.env.production?

instead of this. (See Rails.env vs RAILS_ENV )

+4
source

, . Mixpanel ( API) - . . , mixpanel.rb.

if Rails.env.production?
  MIXPANEL = Mixpanel::Tracker.new(ENV['MIXPANEL_TOKEN'])
else
  MIXPANEL = Mixpanel::Tracker.new(ENV['MIXPANEL_TOKEN']) do |type, message|
     Rails.logger.debug("Mixpanel Request: #{type}, #{message}")
  end
end
+4
+1
source

Source: https://habr.com/ru/post/1795287/


All Articles