How can I add a user property to all user profiles with the timestamp when each user did an event for the first time?
Hi Dominic B., 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 add a user property that captures the timestamp when each user performed an event for the first time, you have a few options in Mixpanel:
Using Custom Properties
You can create a custom property that calculates when a user first performed a specific event: 1. Click the plus button to the right of the search bar 2. Select "User Property" to open the property builder 3. Give your property a name (e.g., "First Purchase Time") 4. In the formula, you can use functions to determine the first time a user performed an eventCreating a Custom Property provides more details on this approach.
Using Profile Set Once API
A more programmatic approach is to use the $set_once
operator when updating user profiles. This operator only sets a property if it doesn't already exist, making it perfect for "first time" properties: LBKS// Example using JavaScript SDK mixpanel.identify('user_id'); mixpanel.people.set_once({ 'first_purchase_time': new Date().toISOString() });LBKS
The $set_once
operator works just like "$set", except it will not overwrite existing property values, which is ideal for properties like "First login date".
Implementation in Different SDKs
Various Mixpanel SDKs support the setOnce()
method: - JavaScript: mixpanel.people.set_once()
- PHP: $mp-> people-> setOnce()
- React Native: mixpanel.getPeople().setOnce()
- Android: mixpanel.getPeople().setOnce()
For example, in PHP: LBKS$mp-> people-> setOnce("USER_ID", array( 'first_event_time' => date('c') ), $ip = 0);LBKS
Best Practices
When implementing this, remember that: 1. User profiles in Mixpanel are mutable, but using $set_once
ensures you only capture the first occurrence
2. You should call .identify()
before setting profile properties to associate the profile update with the correct user
3. For analyzing first-time users more broadly, you can also use Mixpanel's First Time Filter in reportsMixpanel also has a reserved profile property $mp_first_event_time
that represents the time of the user's very first event in Mixpanel, which you can use for filtering/segmenting reports by new users in a particular timeframe.
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.