How to track your first event on Mixpanel

beginner 8 min read Updated 2026-03-18
Quick Answer

To track your first event on Mixpanel, you need to install the Mixpanel SDK or JavaScript library, initialize it with your project token, and call the track function with an event name and properties. Events will then appear in your Mixpanel dashboard for analysis.

Prerequisites

  • A Mixpanel account
  • Basic understanding of web development
  • Access to your website or app code
  • Admin permissions in your Mixpanel project

Step-by-Step Instructions

1

Create a Mixpanel project and get your project token

Log into your Mixpanel account and navigate to Project Settings by clicking the gear icon in the top right. Copy your Project Token from the overview page - you'll need this to initialize the Mixpanel library in your code.
Keep your project token secure and never expose it in client-side code for server-side implementations.
2

Install the Mixpanel library

For web applications, add the Mixpanel JavaScript snippet to your HTML head section:

<script type="text/javascript">
(function(c,a){if(!a.__SV){var b,d,h,e;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))};}var g=a;"undefined"!==typeof f?g=a[f]=[]:f="mixpanel";g.people=g.people||[];g.toString=function(a){var b="mixpanel";"mixpanel"!==f&&(b+="."+f);a||(b+=" (stub)");return b};g.people.toString=function(){return g.toString(1)+".people (stub)"};h="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");for(e=0;e<h.length;e++)d(g,h[e]);var j="set set_once union unset remove delete".split(" ");g.get_group=function(){function a(c){b[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));g.push([e,call2])}}for(var b={},c=0;c<j.length;c++)a(j[c]);return b};a._i.push([b,c,f])};a.__SV=1.2;}})(document,window.mixpanel||[]);
For npm-based projects, install via: npm install mixpanel-browser
For mobile apps, use the native iOS or Android SDKs instead of the JavaScript library for better performance.
3

Initialize Mixpanel with your project token

Add the initialization code after including the Mixpanel library:

mixpanel.init('YOUR_PROJECT_TOKEN', {
  debug: true,
  track_pageview: true,
  persistence: 'localStorage'
});

Replace YOUR_PROJECT_TOKEN with the token you copied from step 1. Set debug: true to see tracking events in your browser console during development.
Enable debug mode during development to verify events are being sent correctly before going to production.
4

Track your first event

Use the mixpanel.track() function to send your first event. Add this code where you want to track user actions:

mixpanel.track('Button Clicked', {
  'button_name': 'Sign Up',
  'page': 'Homepage',
  'user_type': 'visitor'
});

The first parameter is the event name, and the second parameter is an object containing event properties with additional context.
Use descriptive event names and consistent naming conventions like 'Button Clicked' or 'Page Viewed' for better organization.
5

Test your event tracking

Open your browser's Developer Console (F12) and perform the action that should trigger your event. With debug mode enabled, you should see a message like Mixpanel track: Button Clicked in the console. You can also check the Network tab for HTTP requests to api.mixpanel.com.
Events may take a few minutes to appear in your Mixpanel dashboard, so don't worry if they don't show up immediately.
6

Verify events in Mixpanel dashboard

Go to your Mixpanel dashboard and click on Events in the left sidebar. Select Insights and you should see your tracked event listed in the event dropdown. Click on your event name to view the data and properties you sent.
Use the 'Live View' feature in Mixpanel to see events coming in real-time during testing.
7

Set up user identification

To track events for specific users, call mixpanel.identify() when a user logs in or signs up:

mixpanel.identify('user123');
mixpanel.people.set({
  '$email': 'user@example.com',
  '$name': 'John Doe',
  'plan': 'premium'
});

This associates future events with the identified user and enables user profile tracking.
Always identify users with a consistent, unique identifier like user ID or email address across all your tracking.

Common Issues & Troubleshooting

Events not showing up in Mixpanel dashboard

Check that your project token is correct and that you're looking at the right date range in the dashboard. Enable debug: true in your initialization to verify events are being sent from your browser console.

Console shows 'mixpanel is not defined' error

Ensure the Mixpanel library is loaded before your tracking code runs. Move your initialization and tracking code to after the library snippet, or wrap it in a window.onload function.

Events tracked but properties are missing

Verify that your event properties object is properly formatted JSON with string keys. Check the browser console for any JavaScript errors that might prevent the properties from being sent correctly.

CORS or network errors in browser console

This usually indicates ad blockers or privacy extensions blocking Mixpanel requests. Test in an incognito window or different browser. For production, consider implementing server-side tracking as a fallback.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official Mixpanel website before purchasing.