Is there a way to include, as a custom event property, the number of events that occurred earlier in the same session before every event? For example, I’d like each Page View event to have a property like prior_events that tells me how many other events happened in that session prior to it.
Hi Elena M., 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
Yes, there are a couple of approaches you can use to track the number of prior events in a session with Mixpanel:
1. Using Session Properties
Mixpanel automatically includes a "Session Event Count" property with session events that tracks the number of events during a session. This property is available as $event_count
(raw name) and doesn't include excluded or hidden events.Mixpanel Sessions documentation explains that session events automatically have properties like "Session Event Count" which tracks the number of events during a session.
2. Using Custom Properties
You could create a custom property that leverages behavioral properties to count events: 1. Create a custom property using the "Frequency per User" behavioral property 2. Configure it to count events within the session timeframeBehavioral Properties documentation explains how you can use behavioral properties to compute and use user activity as a property in your analysis.
3. Using Super Properties with a Counter
Another approach would be to implement a counter in your tracking code: 1. Maintain a counter variable in your application
2. Increment it before each event
3. Register it as a super property before sending each eventSetting Super Properties documentation shows how you can register super properties that will be included with all subsequent events.For example (pseudocode): LBKS// Initialize a counter let eventCounter = 0;LBKS// Before tracking each event eventCounter++; mixpanel.registerSuperProperties({ prior_events: eventCounter - 1 // Subtract 1 to get prior events count }); mixpanel.track('Page View');LBKS
This would give you the exact property you're looking for, with each event having a prior_events
property showing how many events occurred before it in the session.
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! 📚
Yes, you can capture the Session Start event ID in Mixpanel through several methods, depending on your implementation.
Session Replay ID
If you're using Mixpanel's Session Replay feature, you can get the Replay ID which is associated with the current session:
For Web:
mixpanel.get_session_recording_properties();
// Returns: {$mp_replay_id: '19221397401184-063a51e0c3d58d-17525637-1d73c0-1919139740f185'}LBKS```LBKS[Session Replay Web documentation](https://docs.mixpanel.com/docs/session-replay/implement-session-replay/session-replay-web#replay-id)
For Android:
MPSessionReplay.getInstance()?.getReplayId()LBKS```LBKS[Session Replay Android documentation](https://docs.mixpanel.com/docs/session-replay/implement-session-replay/session-replay-android#replay-id)
For iOS:
MPSessionReplay.getInstance()?.getReplayId()LBKS```LBKS[Session Replay iOS documentation](https://docs.mixpanel.com/docs/session-replay/implement-session-replay/session-replay-ios#replay-id)
Session Properties
For regular sessions (not using Session Replay), Mixpanel generates "Session Start" events with specific properties. While there isn't a direct method to get the Session Start event ID itself, you can access session-related properties: - Session Event Count ($event_count
)
- Session Start Event Name ($origin_start
)
- Session End Event Name ($origin_end
)Reserved Event Properties documentationIf you need to associate events with a specific session, you could consider using Property-Based Sessions where you define your own session ID property, which would give you more control over the session identification.Property-Based Sessions documentation
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.