tuzl4g
Last Updated: February 25, 2016
·
1.568K
· 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.

index.html.haml

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

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