for Users if I want add more fileds from my database such as total orders for each users and be update I need to know steps
Hi Anhar S., 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 and keep updated custom fields like "total orders" from your database to Mixpanel user profiles, follow these steps:
1. Extract Data from Your Database
Write a script to pull user data from your database, including the unique user ID (to be used as Mixpanel's distinct_id) and the custom field(s) you want to add or update (e.g., total_orders).
2. Format Data for Mixpanel
Transform your user data into the format expected by Mixpanel's Engage API. For each user, create a dictionary/object with at least:
- $distinct_id: the unique user identifier (should match the one used in your event tracking)
- $set: an object containing the properties to update, e.g., {"total_orders": 42}
Example in Python:
def transform_to_mp_format(user):
distinct_id = user.pop("user_id")
return {
"$distinct_id": distinct_id,
"$token": PROJECT_TOKEN,
"$ip": "0",
"$set": user # user dict now contains total_orders, etc.
}
3. Send Data to Mixpanel Use the Engage API to send the profile updates. You can batch up to 200 profiles per request for efficiency.
Example using Python and requests:
import json
import requests
profiles = [transform_to_mp_format(u) for u in users]
resp = [requests.post](http://requests.post)(
"[https://api.mixpanel.com/engage](https://api.mixpanel.com/engage)",
params={"verbose": "2"},
headers={"Content-Type": "application/json"},
data=json.dumps(profiles)
)
print(resp.json())
4. Schedule Regular Updates
To keep the field (like total_orders) up to date, schedule your script to run periodically (e.g., hourly or daily), so Mixpanel always has the latest values from your database.
Important Notes:
- Make sure the distinct_id you use matches the one used in your event tracking, so profile data joins correctly with events.
- You can update any custom property this way, and Mixpanel will always show the latest value for each property on the user profileΒ User Profiles FAQ.
This approach works for any custom field you want to sync from your database to Mixpanel user profiles.
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.
