Getting started overview

Getting started with Mixpanel involves a series of steps to set up your account, retrieve necessary API credentials, and send your first event data. The process typically begins with account creation, followed by locating your Project Token and API Secret within the Mixpanel dashboard. These keys are fundamental for authenticating any data sent to your Mixpanel project. Once you have these credentials, you can choose an appropriate SDK for your application's programming language or use the HTTP API directly to track user interactions and product events. The initial setup focuses on sending a simple event to confirm that data is being received and processed correctly by Mixpanel.

Mixpanel provides official SDKs for a range of platforms, including web (JavaScript), mobile (iOS, Android, React Native, Flutter, Unity, Electron), and backend languages (Python, Ruby, Java, PHP). These SDKs abstract much of the complexity of the HTTP API, offering methods for tracking events, setting user profiles, and managing user identities. For scenarios where an SDK is not suitable or for direct server-side integrations, the Mixpanel HTTP Tracking API can be used to send data via standard HTTP requests. Understanding the basic structure of an event, which includes an event name and properties, is crucial for effective data collection.

The primary goal of the initial setup is to confirm data flow. This involves sending a minimal event, such as a "Sign Up" or "Page Viewed" event, and then verifying its appearance in your Mixpanel project's Live View or Events report. This validation step ensures that your credentials are correct and that your integration method is functioning as expected before proceeding with more complex tracking implementations.

Quick Reference Table

Step What to Do Where
1. Create Account Sign up for a new Mixpanel account. Mixpanel Homepage
2. Locate Project Keys Find your Project Token and API Secret. Mixpanel Project Settings > Project Access (or similar)
3. Choose Integration Method Select an SDK (e.g., JavaScript) or HTTP API. Mixpanel Developer Docs
4. Install SDK/Prepare Request Add the SDK to your project or structure an HTTP POST. Your application code or terminal
5. Send First Event Execute a basic track() call or HTTP request. Your application executing the code
6. Verify Data Check for the event in Live View or Events report. Mixpanel Dashboard > Live View

Create an account and get keys

To begin using Mixpanel, the first step is to create an account. Mixpanel offers a free tier that supports up to 100,000 monthly tracked users, which is suitable for initial testing and smaller projects. Navigate to the Mixpanel homepage and follow the sign-up process. During this process, you will typically create an organization and a default project.

Once your account is set up and you're logged into the Mixpanel dashboard, you'll need to locate your API credentials. These credentials are vital for authenticating your application or server when sending data to Mixpanel. The primary credentials you will use for tracking events are the Project Token and, for some server-side operations or specific API calls, the API Secret.

  1. Navigate to Project Settings: From the Mixpanel dashboard, click on the gear icon (⚙️) in the top right corner to access your project settings.
  2. Access Project Access: Within the settings menu, look for a section typically named "Project Access" or "Project Settings".
  3. Locate Credentials: On this page, you will find your Project Token. The Project Token is a unique identifier for your Mixpanel project and is included with every event sent. For server-side integrations or specific API operations, you may also need the API Secret. Keep these credentials secure, as they grant access to your Mixpanel data.

It's important to differentiate between the Project Token, which is often safe to expose in client-side code (like JavaScript in a web browser), and the API Secret, which should always be kept confidential and only used in secure server-side environments. Misusing or exposing your API Secret can lead to unauthorized data access or manipulation. For example, the OAuth 2.0 framework, a common standard for secure API authorization, emphasizes the importance of keeping client secrets confidential on server-side applications to prevent unauthorized access to resources (OAuth 2.0 Specification).

Your first request

After obtaining your Project Token, you can send your first event to Mixpanel. This section provides examples for a common web integration using JavaScript and a server-side cURL example for the HTTP API.

JavaScript (Web) Example

For web applications, the Mixpanel JavaScript SDK is the recommended method. First, you need to include the SDK in your HTML file. Place the following script tag in the <head> or just before the closing </body> tag of your web page:

<script type="text/javascript">
  (function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].apply(a,arguments))}};var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);return d};a.people.toString=function(){return a.toString(1)+".people"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_session end_session add_group set_group remove_group track_with_groups get_group".split(" ");for(h=0;h<i.length;h++)g(a,i[h]);e="get_distinct_id get_group_key get_group_properties get_init_extension on identify_target people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove people.unset people.merge people.track_charge_for_email people.track_charge_for_id people.track_charge_for_user_id people.lookup_user people.engage people.track_revenue people.track_revenue_for_email people.track_revenue_for_id people.track_revenue_for_user_id".split(" ");for(h=0;h<e.length;h++)g(a.people,e[h]);b._i.push([e,f,c])};b.__SV=1})(document,window.mixpanel||[]);
  mixpanel.init("YOUR_PROJECT_TOKEN");
</script>

Replace "YOUR_PROJECT_TOKEN" with the actual Project Token you retrieved from your Mixpanel settings. After initializing, you can track an event using the mixpanel.track() method:

<script type="text/javascript">
  mixpanel.init("YOUR_PROJECT_TOKEN");

  // Track a simple event when the page loads
  mixpanel.track("Page Loaded", {
    "Page Name": "Getting Started Page",
    "User Status": "Anonymous"
  });

  // Example of tracking a button click
  document.getElementById('myButton').addEventListener('click', function() {
    mixpanel.track("Button Clicked", {
      "Button Name": "Submit Form",
      "Location": "Header"
    });
  });
</script>
<button id="myButton">Click Me</button>

This code snippet initializes Mixpanel with your Project Token and then tracks two events: one when the page loads and another when a specific button is clicked. The second argument to mixpanel.track() is an object containing properties that provide additional context about the event.

cURL (HTTP API) Example

For server-side applications or when an SDK is not available, you can use the Mixpanel HTTP Tracking API directly. Events are sent as JSON payloads, which must be Base64 encoded and then sent as a POST request to Mixpanel's ingest endpoint. The data parameter contains the encoded event data, and the verbose parameter can be set to 1 to receive a more detailed response from the API.

First, compose your event data as a JSON object. For example:

{
  "event": "Server Event",
  "properties": {
    "token": "YOUR_PROJECT_TOKEN",
    "distinct_id": "user_12345",
    "Server ID": "api_server_01",
    "Action": "Data Processed",
    "time": 1678886400 // Unix timestamp in seconds
  }
}

Next, Base64 encode this JSON string. Many programming languages have built-in functions for Base64 encoding. For instance, in Python, you might use base64.b64encode(json_string.encode('utf-8')). Then, construct your cURL command:

curl -X POST \
  'https://api.mixpanel.com/track/' \
  --data-urlencode 'data=BASE64_ENCODED_JSON_STRING' \
  --data-urlencode 'verbose=1'

Replace YOUR_PROJECT_TOKEN with your actual Project Token and BASE64_ENCODED_JSON_STRING with the Base64 encoded event payload. The distinct_id property is crucial for identifying unique users in Mixpanel. The time property, when provided, specifies the time the event occurred in Unix epoch seconds, which is a standard timestamp format often used in web APIs and databases (MDN Web Docs on getTime()).

After sending your first event, navigate to the "Live View" section in your Mixpanel dashboard. You should see your event appear there within a few seconds, confirming a successful integration. If you don't see the event, double-check your Project Token and the structure of your event data.

Common next steps

Once you have successfully sent your first event to Mixpanel, several common next steps can help you build out a more comprehensive analytics implementation:

  1. Identify Users: Implement user identification using mixpanel.identify(distinct_id). This links anonymous events to a known user ID, allowing you to track user journeys across sessions and devices. This is a crucial step for building complete user profiles and understanding individual user behavior, as detailed in the Mixpanel User Identity documentation.
  2. Set User Profiles (People Properties): Use mixpanel.people.set() to store static or slowly changing user attributes, such as email, name, subscription plan, or signup date. These properties enable powerful segmentation and personalization within Mixpanel reports.
  3. Track Core Product Events: Beyond your first event, identify and track key user actions within your product. This includes events like "Item Added to Cart," "Feature Used," "Video Played," or "Purchase Completed." Focus on events that are critical for understanding user engagement and conversion funnels.
  4. Implement Super Properties: Super Properties are event properties that are automatically included with every subsequent event. Use mixpanel.register() to set global properties like "App Version," "Device Type," or "Referring Source" once, rather than including them with every individual track() call.
  5. Explore Reports: Start exploring Mixpanel's various reports, such as "Insights," "Funnels," and "Retention," to visualize and analyze the data you've collected. This helps you gain initial insights into user behavior and product performance.
  6. Integrate with Other Systems: Consider integrating Mixpanel with other tools in your stack. Mixpanel offers integrations with various platforms for data import/export, advertising, and customer engagement, which can be found in the Mixpanel Integrations documentation.

Planning your event taxonomy and property schema early can prevent data quality issues later on. A well-defined tracking plan ensures consistency and makes your data easier to analyze.

Troubleshooting the first call

Encountering issues when sending your first event to Mixpanel is common. Here are some troubleshooting steps:

  • Check Project Token: Verify that the Project Token used in your code or cURL command exactly matches the one found in your Mixpanel project settings. A common mistake is a typo or using the wrong project's token.
  • Network Requests: For web integrations, open your browser's developer tools (usually F12 or right-click > Inspect > Network tab). Look for requests being sent to api.mixpanel.com/track/. Check the status code (should be 200 OK) and the payload to ensure your event data is correctly formatted and sent.
  • Base64 Encoding (HTTP API): If using the HTTP API directly, ensure your JSON event payload is correctly Base64 encoded. Incorrect encoding will result in Mixpanel being unable to parse the data, leading to errors or dropped events. Many online tools can help verify Base64 encoding.
  • JSON Structure: Ensure your event JSON payload (before Base64 encoding for HTTP API) is well-formed and adheres to Mixpanel's expected structure, including the event and properties fields. The token property within properties is mandatory for HTTP API calls.
  • Live View Delay: While Mixpanel's Live View is near real-time, there can sometimes be a slight delay of a few seconds. If you've just sent an event, wait a moment and refresh the Live View.
  • Ad Blockers/Browser Extensions: Some browser extensions (especially ad blockers or privacy-focused tools) can block Mixpanel's tracking scripts or network requests. Try disabling them temporarily or testing in an incognito window.
  • Error Responses: If you're using the HTTP API with verbose=1, check the response from Mixpanel's API for specific error messages. These messages often provide clues about what went wrong, such as "Invalid token" or "Malformed data."
  • SDK Debugging: Mixpanel SDKs often have debug modes or logging options that can provide more detailed output in your console, helping you diagnose issues. For example, the JavaScript SDK might log errors directly to the browser console. Refer to the specific SDK documentation for debugging instructions.
  • Time Property: If you manually set the time property in your event, ensure it's a valid Unix timestamp (in seconds). Incorrect timestamps can cause events to appear out of order or not at all in certain reports.

If you've gone through these steps and are still facing issues, consulting the official Mixpanel documentation or contacting Mixpanel support for assistance would be the next logical steps.