Automatically Separate Development Data

This article shows how to separate your production and development project data automatically.

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 in the later stages of a project.

Setting Up Separate Environments

To set up separate environments:

  1. Create two separate Mixpanel projects for development and production.
    (Mixpanel doesn't limit the number of projects you can use).
  2. Use the logic in the code snippet below to switch automatically between the two project tokens when you're in development or when you're ready to push data to production.
  3. Specify your production domain and project tokens

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

Remember, use this solution only if your development environment uses a different hostname, such as development.yourdomain.com.

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) { mixpanel.init(devToken);
} else { mixpanel.init(prodToken); } 
Is this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.