Search code examples
ruby-on-railsmixpanel

Requiring something in entire Rails project


I want to require 'mixpanel-ruby' so that I can use it anywhere in my Rails app, but I'm not sure which file it should go into.


Solution

  • You could create a new .rb file in the /config/initializers/ folder and initialize MixPanel from there, like this:

    MixPanelTracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
    

    Then, you can call MixPanelTracker from any place in your app.