How to set event property as user property?
Hi Maksym D., 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 set an event property as a user property in Mixpanel, you need to understand the difference between these two types of properties and how to properly associate them.
Understanding Event vs User Properties
In Mixpanel, event properties describe specific actions users take, while user properties describe the users themselves. As mentioned in the documentation: > An Event Property describes an event. For a coffee purchase, the event would be Purchased Item and the event properties could be type (in this case a Coffee) and price (in this case $2.50).
A User Property describes a User. This could be their name, email, age, etc.
Setting Event Properties as User Properties
To set an event property as a user property, you need to: 1. Track the event with its properties 2. Then set the same property value to the user profileHere's how you can do it in different SDKs:
JavaScript Example
mixpanel.track('Purchase', {
'item': 'Coffee',
'price': 2.50
});LBKS// Then set the same property to the user profile
mixpanel.people.set({
'last_purchase_item': 'Coffee',
'last_purchase_price': 2.50
});LBKS```
Server-Side Example (Python)
When implementing server-side tracking, you can follow this pattern: ```def track_to_mp(request, event_name, properties):
Track the event with properties
mp.track(request.user.username, event_name, properties)
Set the same properties as user properties
mp.people_set(request.user.username, { 'last_' + key: value for key, value in properties.items() })```Server-side Identity Management
Best Practices
According to Mixpanel's documentation: > We recommend primarily using User Properties to track demographic attributes of the user, like their name, email, and domain. Most other properties are better tracked as Event Properties.
That said, User Properties are as flexible as any other properties in Mixpanel, so you can send arbitrary JSON.
User Profiles FAQAdditionally: > As a best practice, think of event properties that you track under events which might also be useful as user properties. This would allow you to analyze a user property which provides the latest state or value against the same event property that records a value in the past. Build Your Tracking StrategyRemember that user profiles are mutable and store only the latest value of each property, while event properties are immutable and provide historical data.
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 extract and record only part of an event property as a user property in Mixpanel. This can be done in several ways:
Using Custom Properties
If you're on a Growth or Enterprise plan, you can use Custom Properties to extract specific parts of an event property before setting it as a user property: LBKS// First extract the part you need using Custom Properties // Then set that extracted value as a user property mixpanel.people.set({ 'domain_name': extractedDomainValue });LBKS
For example, you could extract just the domain from an email address: LBKS// Extract domain from email using SPLIT function in Custom Properties // Then set just the domain as a user property mixpanel.people.set({ 'email_domain': domainPart });LBKS
Custom Properties: Calculate new properties on the fly
Manual Transformation
You can also manually transform event properties before setting them as user properties: LBKS// Track an event with a complex property mixpanel.track('Sign Up', { 'full_name': 'John Smith', 'email': 'john.smith@​[example.com](http://example.com)' });LBKS// Extract and set only parts as user properties const nameParts = 'John Smith'.split(' '); mixpanel.people.set({ 'first_name': nameParts[0], 'last_name': nameParts[1], 'email_domain': 'john.smith@​[example.com](http://example.com)'.split('@​')[1] });LBKS
Best Practices
When deciding which parts of event properties to store as user properties, remember Mixpanel's recommendation: > We recommend primarily using User Properties to track demographic attributes of the user, like their name, email, and domain. Most other properties are better tracked as Event Properties.User Profiles FAQKeep in mind that user properties are mutable and only store the latest value, so they're best used for current user attributes rather than historical data points.
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 provide a step-by-step guide on using custom properties in Mixpanel to extract part of an event property and set it as a user property.
Creating a Custom Property in Mixpanel
1. Access the Custom Property Builder: - Click the plus button to the right of the search bar - Select either "Event Property" or "User Property" to open the property builder Custom Properties: Calculate new properties on the fly2. Name Your Custom Property: - Give your property a descriptive name (e.g., "Email Domain")3. Write Your Formula: - Click into the formula bar to start defining it - Press Ctrl + Space to see available functions and their descriptions - Press period (.) to search for event or profile properties to add to the formula Custom Properties: Calculate new properties on the fly4. Example Formula: - To extract a domain from an email address, you could use:
```LBKSLBKS5. **Test and Apply**:
- Custom properties are local to the report by default when you select "Apply"
- Test the property in your local analysis first before savingLBKS6. **Save the Custom Property** (Growth and Enterprise plans only):
- Click "Save" to make the custom property permanent and usable in other reports
- Add a description so you and colleagues know what the property is for
- Choose whether to keep it private or "Save and Share" with colleagues or your organization
[Custom Properties: Calculate new properties on the fly](https://docs.mixpanel.com/docs/features/custom-properties#creating-a-custom-property)
Example Use Cases
Here are some examples of extracting parts of properties: 1. Extract domain from email address:
```LBKSLBKS2. **Extract first item from a list**:
```LBKS LIST_ITEM(event.recommendations, 0)
```LBKS [Custom Properties: Calculate new properties on the fly](https://docs.mixpanel.com/docs/features/custom-properties)LBKS3. **Compare different properties**:
```LBKS IF(user.signup_country == event.purchase_country, "Same", "Different")
Borrowed Properties
If you need to use a property from one event in another event: 1. Create a borrowed property (Admin & Owner roles only) 2. This allows you to borrow a specific property from a preceding action 3. Note that borrowing is limited to the most recent event in a 7-day lookback windowCustom Properties: Calculate new properties on the flyRemember that a project can have a maximum of 20 borrowed properties, so it's best to create only those that will be useful to the larger team.Is there a specific part of an event property you're looking to extract?
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.