Last Updated: February 25, 2016
· bostonaholic

Mock Mixpanel.js in development and staging

If you're using Mixpanel for tracking users and analyzing their behaviors (and you should be!), here is how I setup my site to mock the mixpanel tracking service so that I'm not posting events while in my development or staging environments.


- if Rails.env.production?
  = javascript_include_tag "mixpanel"
- else
    function MixPanelMock() {
      this.track = track;
      function track(eventString) {
    window.mixpanel = new MixPanelMock();

Now, anytime you call mixpanel.track("Some event"); it just prints to the console.