Community Tip: Automatically Separate Data - Mixpanel
Blog Post

Community Tip: Automatically Separate Data

Keeping your production data clean in Mixpanel is important. This Community Tip provides a simple way to separate your production and development project data automatically. It’s a few lines of code and should only take a few minutes to implement. You can also include similar logic in your Mixpanel Android, iOS and Server-Side code.

Keeping data sets separate is important to maintain the integrity of the metrics you’re tracking with Mixpanel. It’s very easy to prevent these data sets from co-mingling, but hard to detangle, so taking time up front is well worth it!

First, create two separate Mixpanel projects – a “Development” project and a “Production” project (Mixpanel doesn’t limit the number of projects you can use). Then, you can employ the following logic in your code to switch automatically between the two project tokens when you’re in development or when you’re ready to push data to production.
Here’s an example of how you would do this in JavaScript (also code snippet below).
N.B. we’re assuming the common convention in which your development environment uses a different hostname, e.g. If that’s not true, you’ll need to employ a different solution. Finally, specify your production domain, and project tokens (steps to find your tokens here).

var productionHost = 'Your production Domain';
var devToken = 'Development Token';
var prodToken = 'Production Token';

//If the hostname is anything other than your production domain, initialize the Mixpanel library with your Development Token

if (window.location.hostname.toLowerCase().search(productionHost) < 0) {
} else {

Dynamically changing project tokens will ensure that your testing data does not contaminate your production environment allowing you to easily build reports off of true user data. Plus, it removes the need to swap out tokens before every push to production.

Have any questions? Reach out to to speak to someone smart, quickly.

Get the latest from Mixpanel
This field is required.