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

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside