Does anyone know how to bulk update existing user profiles with a new user property? I'm trying to create a cohort of users by creating a new property and assigning a value to it. I have a list of emails that tie to the user profiles -- I don't have the ability to grab their distinct_id from the source list.
Hi Daniel C., 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 bulk update existing user profiles with a new user property in Mixpanel, you can use the Profile API to upload a group of user profiles and sort them into a cohort. Here's how you can do it:1. First, create a CSV file with the user emails and the new property you want to add. Include a column for the new property that will be used to create the cohort.2. Use the Profile API to upload this data. You'll need to add a unique property to the CSV that will sort the profiles into a cohort. For example, you could add a column called "Cohort" with a value like "New Feature Users".3. After uploading, you can create a cohort based on this new property.Here's an example of how to implement this using Python:LBKS# Fill this out. You can get it from [https://mixpanel.com/settings/project](https://mixpanel.com/settings/project) PROJECT_TOKEN = ""LBKSimport json import requestsLBKSdef get_users_from_database(): # Replace this with code that reads users from your database or CSV return [ {"$email": "alice@​[example.com](http://example.com)", "Cohort": "New Feature Users"}, {"$email": "bob@​[example.com](http://example.com)", "Cohort": "New Feature Users"}, {"$email": "carol@​[example.com](http://example.com)", "Cohort": "New Feature Users"} ]LBKSdef transform_to_mp_format(user): """Transform the above into Mixpanel's format""" # We're using $email as the distinct_id here distinct_id = user.pop("$email")LBKS return {"$distinct_id": distinct_id, "$token": PROJECT_TOKEN, "$ip": "0", "$set": user}LBKSusers = get_users_from_database() profiles = [transform_to_mp_format(u) for u in users]LBKS# We recommend calling this API with batches of 200 user profiles to do this at scale. 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) )LBKSprint(resp.json())LBKS
This approach is based on the information provided in the Mixpanel documentation on Users.After uploading the data, you can create a cohort in Mixpanel by filtering for users with the "Cohort" property equal to "New Feature Users".Note that when creating cohorts this way, the cohort will remain static, meaning it will not update over time like other cohorts, as the property is unchanging.Remember to handle your data securely and in compliance with relevant data protection regulations when working with user emails and other personal information.
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.
Is there a way to this without hitting the API? I'd like to perform this action via a CSV upload
Let me check the knowledge base for you again. One moment! đź“š
Yes, you can definitely perform this action via a CSV upload without hitting the API directly. Mixpanel provides a way to import user profiles using a CSV file. Here's how you can do it:1. Prepare your CSV file:
- Do not include column headers in your CSV file.
- Make sure you have a column for the email addresses and another for the new property you want to add.2. Use the Users report to upload your CSV:
- Go to the Users report in Mixpanel.
- Look for the "Import from CSV" option.3. Upload your CSV:
- Select your prepared CSV file to begin the import process.4. Choose an identifier column:
- In your case, since you don't have the distinct_id
, you'll use the email column as the identifier.
- Mixpanel will use the $email
column as the $distinct_id
if you don't assign an identifier column.5. Map your CSV columns:
- You'll have the opportunity to preview the values in your CSV and map them to Mixpanel profile properties.
- Make sure to map your new property column correctly.6. Import the profiles:
- After mapping the columns, click the "Import profiles" button to proceed with the import.This information is based on the Mixpanel documentation on User Profiles.Some important notes:- If you import profiles with $email
values that already exist, those profiles will be updated with the additional profile properties.
- The maximum size for your CSV should be 1M rows.
- If you upload new information for existing properties on existing profiles, the existing property values will be overwritten.After importing, you can create a cohort based on the new property you've added, just as you would with API-imported data.Remember to handle user data securely and in compliance with relevant data protection regulations when working with CSV files containing personal information.
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.