5 min read

How to Calculate Event Frequency in Mixpanel

Event frequency tells you how many times a user (or cohort) triggers a specific event in a given period. In Mixpanel, this is essential for understanding usage intensity, detecting power users, and spotting drop-offs. You can measure it directly in the UI, query it with JQL, or export the raw data for custom analysis.

Calculate Frequency Using Segmentation

The fastest way to see event frequency is through Mixpanel's Segmentation report, which breaks down event counts by user or property without writing any code.

Navigate to Events and open Segmentation

Go to Events in the left sidebar and click the event you want to analyze. Click the Segmentation tab (the second option). This automatically shows the count of that event over time in a line chart and table.

Segment by user to see per-user frequency

In the Segmentation view, click Breakdown and select Distinct ID (or User ID if you've renamed it). The table will now show each user and their total event count in the selected time period.

javascript
// If you need to export segmentation data programmatically:
const exportSegmentation = async (eventName, property = 'distinct_id') => {
  const response = await fetch(
    `https://api.mixpanel.com/api/2.0/events/properties/top?event=${eventName}&limit=100&unit=day`,
    {
      headers: {
        'Authorization': `Bearer YOUR_SERVICE_ACCOUNT_TOKEN`
      }
    }
  );
  const data = await response.json();
  return data; // Returns top values for a property
};
Export segmentation data via the Mixpanel Events API

Filter by date range to calculate frequency for a specific period

Use the date picker at the top of the Segmentation report. Select the time window you care about—for example, the last 30 days. The table recalculates automatically, showing how many times each user triggered the event in that window.

Tip: If you have thousands of users, export the full table using the Export button to analyze the data in a spreadsheet.

Calculate Frequency with JQL

For custom calculations and filtering, use Mixpanel's JQL (Mixpanel Query Language) in the Data View to write queries that calculate frequency by user or cohort.

Open the Data View and navigate to JQL

Go to Events > Data View, then click the JQL tab. The editor shows a default query that fetches recent events. You'll modify this to count frequency per user.

Write a JQL query to count events per user

Use groupBy and aggregate to tally events. Type this query into the editor: events.groupBy(['properties.distinct_id']).aggregate([sum(1)]). This groups all events by user ID and counts the total occurrences. Click Run to execute.

javascript
// JQL query syntax (paste into the Data View editor):
// Group events by distinct_id and sum the count
const jqlQuery = `
  events
    .filter(e => e.timestamp >= new Date().getTime() - 30 * 24 * 60 * 60 * 1000)
    .groupBy(['properties.distinct_id'])
    .aggregate([sum(1)])
`;
// This outputs: distinct_id | sum(1) [event count per user]
// Example result:
// user123 | 47
// user456 | 12
// user789 | 3
JQL to calculate 30-day event frequency per user

Export the results

Click Export to download the query results as CSV. You now have a list of every user and their event frequency for the time period.

Watch out: JQL queries on datasets with millions of events can timeout. If you hit a timeout, narrow your date range or use the Data Export API instead.

Calculate Frequency Programmatically with the Data Export API

For automation or integration into a pipeline, fetch raw event data via the Mixpanel Data Export API and calculate frequency in your own code.

Set up authentication with a Service Account token

Go to Settings > Project Settings > API Credentials and copy your Service Account Token. This token allows API calls without exposing your project token.

javascript
const serviceAccountToken = 'YOUR_SERVICE_ACCOUNT_TOKEN';

// Headers for all Mixpanel API requests
const headers = {
  'Authorization': `Bearer ${serviceAccountToken}`,
  'Content-Type': 'application/json'
};
Set up authentication for the Mixpanel API

Call the Data Export API to fetch events

Use the export endpoint to retrieve raw events for a specific event name and date range. Mixpanel returns the data as a newline-delimited JSON stream with all event properties intact.

javascript
const getEventFrequency = async (eventName, startDate, endDate) => {
  // Format dates as YYYYMMDD for the API
  const fromDate = startDate.split('-').join('');
  const toDate = endDate.split('-').join('');
  
  const response = await fetch(
    `https://data.mixpanel.com/api/2.0/export?event=${eventName}&from_date=${fromDate}&to_date=${toDate}`,
    { headers }
  );
  
  const text = await response.text();
  const events = text.trim().split('\n').map(line => JSON.parse(line));
  return events;
};

// Get all 'purchase' events from the last 7 days
const now = new Date();
const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
const events = await getEventFrequency('purchase', sevenDaysAgo.toISOString().split('T')[0], now.toISOString().split('T')[0]);
Fetch raw events from Mixpanel Data Export API

Group events by user and calculate frequency

Process the event array in JavaScript to tally occurrences per user. Build a map of distinct_id to count, then filter for high-frequency users or convert to a sorted list.

javascript
const calculateFrequency = (events) => {
  const frequencyMap = {};
  
  events.forEach((event) => {
    const userId = event.properties.distinct_id;
    frequencyMap[userId] = (frequencyMap[userId] || 0) + 1;
  });
  
  // Sort users by frequency descending
  const frequencyArray = Object.entries(frequencyMap)
    .map(([userId, count]) => ({ userId, frequency: count }))
    .sort((a, b) => b.frequency - a.frequency);
  
  return frequencyArray;
};

const frequency = calculateFrequency(events);
console.log(frequency.slice(0, 10)); // Top 10 users by frequency

// Find power users (triggered event 10+ times)
const powerUsers = frequency.filter(u => u.frequency >= 10);
Calculate frequency per user and identify power users
Tip: The Data Export API returns data in newline-delimited JSON format, not a single array. Split by \n and parse each line separately.

Common Pitfalls

  • Forgetting to filter by date range. Event frequency varies wildly depending on the time window. Always specify whether you're measuring daily, weekly, or monthly frequency.
  • Confusing event count with active users. Frequency tells you how many times users triggered an event, not how many users triggered it. These are different metrics with different implications.
  • Not accounting for zero-event users. Segmentation and JQL only show users who triggered the event at least once. If you need baseline engagement across all users (including inactive ones), use a cohort.
  • Hitting Data Export API rate limits. Mixpanel throttles bulk exports. For large datasets, space out your requests or schedule exports during off-peak hours.

Wrapping Up

Event frequency in Mixpanel is straightforward: use Segmentation for quick analysis, JQL for custom queries, or the Data Export API for automation. Once you have frequency data, you can segment power users, detect engagement drop-offs, and identify which features drive repeat usage. If you want to track and calculate event frequency automatically across multiple tools, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free