How do I create a custom user profile property that counts the number of sessions the user has performed?
Hi Imtiaz N., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To create a custom user profile property that counts the number of sessions a user has performed in Mixpanel, you have a few options:
Using the People API with Increment
The most direct way is to use Mixpanel's profile update methods to increment a counter each time a session starts. You can use the increment()
method (or its equivalent in your SDK of choice) to add to a numeric property that tracks sessions.For example, in JavaScript: LBKS// When a session starts mixpanel.identify('user_id'); mixpanel.people.increment('session_count', 1);LBKS
This method is available across Mixpanel's SDKs: - In JavaScript: .people.increment()
 JavaScript SDK
- In React Native: .getPeople().increment()
 React Native SDK
- In Python: .people_increment()
 Python SDK
- In Ruby: .people.increment()
 Ruby SDK
- In PHP: .people-> increment()
 PHP SDK
- In Node.js: .people.increment()
 Node.js SDK
Using Custom Properties with Behavioral Properties
Alternatively, you can use Mixpanel's Custom Properties feature to create a property that calculates session count: 1. Click the plus button to the right of the search bar in a report 2. Select "User Property" to open the property builder 3. Use the "Frequency per User" behavioral property to count sessions 4. Name your property (e.g., "Session Count") and save itThis approach uses Mixpanel's Behavioral Properties feature, which allows you to compute properties based on user activity.
Using Session Data
If you're using Mixpanel's Sessions feature, you can leverage the session data that Mixpanel automatically generates: 1. Make sure you have Sessions enabled in your project 2. Create a custom property that counts the "Session Start" events for each userThe advantage of this approach is that you don't need to manually track session starts and ends - Mixpanel handles this automatically based on your session configuration.Remember that custom properties can be saved globally for reuse across reports if you're on a Growth or Enterprise plan, or used locally within a specific report on the Free plan.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
Let me check the knowledge base for you again. One moment! 📚
I'll explain the session counting methods in Mixpanel step by step, focusing on how sessions are counted in reports.
Session Counting Methods in Mixpanel
Mixpanel offers three different counting methods for sessions in reports like Flows:
1. Uniques (Default Method)
1. Counts a single entry per user (determined by distinct_id) 2. Each user can do the first step only once 3. This happens on the first time they perform the Step A event in the date range 4. Even if a user completes the flow multiple times, they're only counted once 5. The count is based on their first attempt within the date range
2. Totals
1. Counts multiple entries per user 2. Users can re-start the flow multiple times 3. Users are counted every time they start the flow 4. Users may re-enter a totals flow only after exiting their previous attempt 5. Users exit a flow in three ways: - Completing the last required step - Failing to reach the last step within the conversion window - Being excluded by an exclusion step
3. Sessions
1. Ensures every step in the flow is performed in the same session 2. Like totals flows, users can re-start the flow in subsequent sessions 3. Sessions are defined based on your project's session settings (timeout-based, event-based, or property-based) 4. When you select "Sessions" as your counting method, the conversion window is limited to one session
Using Sessions in Reports
In Funnels:
1. Navigate to the Funnels report 2. Set up your funnel steps 3. In the Conversion Details section, select "Sessions" instead of "Uniques" or "Totals" 4. The conversion window will automatically be limited to one session 5. You can use session-specific properties like "Session Duration (Seconds)" and "Session Event Count" to filter or break down results
In Flows:
1. Navigate to the Flows report 2. Click on the word "Uniques" in the conversion criteria 3. Select "Sessions" from the dropdown 4. The flow will now be weighted by the number of sessions rather than unique users
In Insights:
1. You can analyze session metrics using the "Session Start" and "Session End" events 2. To count events by sessions, select the "Total" dropdown beside an event 3. Choose "Sessions" from the aggregation options 4. This will show how many sessions contained that particular eventLearn more about Sessions in Mixpanel reportsThis approach leverages Mixpanel's automatic session tracking, so you don't need to manually implement session counting in your code.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
Let me check the knowledge base for you again. One moment! 📚
I'll explain how to store session count as a custom property against each user in Mixpanel.
Using the People API to Store Session Count
The most direct way to store session count as a user profile property is to use Mixpanel's profile update methods to increment a counter each time a session starts:
React Native Example
mixpanel.identify('1234');
mixpanel.getPeople().increment('session_count', 1);LBKS```LBKSLBKSThis approach uses the `.increment()` method which is specifically designed for updating numeric profile properties. As shown in the React Native documentation: LBKS> The [`.getPeople().increment()`](https://mixpanel.github.io/mixpanel-react-native/People.html#increment) method increments a numeric property by a whole number.
>
> Use this method to add to or subtract from your numeric property based on its current value.LBKS[Mixpanel SDKs: React Native](https://docs.mixpanel.com/docs/tracking-methods/sdks/react-native#other-types-of-profile-updates)
JavaScript Example
mixpanel.identify('12345');
mixpanel.people.increment('session_count', 1);LBKS```
Implementation Steps
1. First, identify the user with identify()
to associate the profile update with the correct user
2. Use the appropriate increment method for your SDK to add 1 to the session count
3. Place this code at the point where a new session begins (based on your session definition)
When to Trigger the Increment
You have several options for when to trigger this increment, depending on how you define sessions: 1. Timeout-based sessions: Increment when a user returns after the timeout period
2. Event-based sessions: Increment when your defined "session start" event occurs
3. Property-based sessions: Increment when the session ID property changesIf you're using Mixpanel's automatic session tracking, you could set up a webhook or use Mixpanel's API to listen for "Session Start" events and then increment the user property accordingly.Remember that profile updates require you to call identify()
first to associate the update with the correct user profile. The session count will persist in the user's profile and can be used for segmentation, analysis, and personalization.This approach gives you a permanent record of each user's session count that you can use across all Mixpanel reports.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.