i want to do an ab test. how can I create a new property and give it names for example: the property would be “User Group” and the possible values: “control”, “variant_1”
Hi Eugeni, 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 create a new property for an A/B test in Mixpanel, you can use custom properties. Here's how you can create a custom property called "User Group" with values like "control" and "variant_1":1. First, you need to create the custom property in your Mixpanel project settings: Navigate to your Project Settings, then click the plus button next to the search bar and select "Event Property" or "User Property" to open the property builder Creating a Custom Property.2. Give your property a name, in this case, "User Group".3. Define the formula for your custom property. You can use the formula builder to create logic that assigns users to either "control" or "variant_1" groups.4. Once you've created the custom property, you need to implement it in your tracking code. Here's an example of how you might do this using the JavaScript SDK:
let userGroup = Math.random() < 0.5 ? "control" : "variant_1";LBKS // Track an event with the User Group property
mixpanel.track("Experiment Started", {
"User Group": userGroup
});LBKS // You can also set it as a user property
mixpanel.people.set({
"User Group": userGroup
});
```LBKSLBKS5. After implementing this, you can use the "User Group" property to segment your users in your analysis.LBKSRemember, for proper A/B testing in Mixpanel, you should also track a specific "$experiment_started" event <https://docs.mixpanel.com/docs/reports/apps/experiments|Experiments>. This allows Mixpanel to automatically detect and analyze your experiments.LBKSAlways ensure that your A/B test groups are mutually exclusive to get accurate results [Experiments](https://docs.mixpanel.com/docs/reports/apps/experiments).
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! 📚
To create a custom property for an A/B test that only applies to users who have performed a specific event X, you can use Mixpanel's custom properties feature with a conditional statement. Here's how you can approach this:1. First, create a custom property as described in the previous answer Creating a Custom Property.2. When defining the formula for your custom property, you can use a conditional statement to check if the user has performed event X. Here's an example of how the formula might look:
if(random() < 0.5, "control", "variant_1"),
null)
```LBKSLBKS This formula checks if the user has performed event X, and if so, randomly assigns them to either "control" or "variant_1". If they haven't performed event X, it assigns null.LBKS3. In your tracking code, you would then use this custom property when tracking events or updating user profiles. Here's an example using the JavaScript SDK:LBKS
```LBKS // Track an event with the User Group property
mixpanel.track("Experiment Started", {
"User Group": mixpanel.get_property("User Group")
});LBKS // Or set it as a user property
mixpanel.people.set({
"User Group": mixpanel.get_property("User Group")
});
```LBKSLBKS4. You can then use this "User Group" property to segment your users in your analysis, focusing only on those who have performed event X.LBKSRemember, for proper A/B testing in Mixpanel, you should also track a specific "$experiment_started" event when a user enters the experiment <https://docs.mixpanel.com/docs/reports/apps/experiments#add-experiments-to-an-implementation|Experiments>.LBKSThis approach allows you to create an A/B test group only for users who have performed a specific event, giving you more targeted control over your experiment population.
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.