Mixpanel Community Icon

Custom Property for Conditional String Return in Programming

·
·

I want to create a custom property that returns a string if the property is not set, otherwise returns the set property

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Max M., 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

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    You can create a custom property in Mixpanel that returns a default string value when a property is not set, using the defined() function combined with an if statement. Here's how to do it: 1. Navigate to the custom property builder by clicking the plus button to the right of the search bar, then select Event Property or User Property.2. In the formula bar, use the following pattern: LBKSif(defined(properties["YourPropertyName"]), properties["YourPropertyName"], "Default String Value")LBKSThis formula checks if the property is defined (set). If it is, it returns the property value; if not, it returns your default string value.For example, if you want to check if a "City" property is set and return "Unknown Location" when it's not set: LBKSif(defined(properties["City"]), properties["City"], "Unknown Location")LBKSYou can create this custom property locally for just your current report by clicking "Apply", or save it permanently for use in other reports by clicking "Save" or "Save and Share" if you want to make it available to your colleagues.Custom Properties documentation provides more details on creating and managing custom properties in Mixpanel.

    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.

  • Avatar of Max M.
    Max M.
    ·
    ·

    I had alrady tried using defined, however it did not work. IF(DEFINED(@"""{"label":"CardScheme","propertyDefaultType":"string","resourceType":"event","type":"string","value":"CardScheme"}"""@), @"""{"label":"CardScheme","propertyDefaultType":"string","resourceType":"event","type":"string","value":"CardScheme"}"""@, "amex")

  • Avatar of Max M.
    Max M.
    ·
    ·

    kapa.ai I tried to use DEFINED() but it did not work,

    IF(DEFINED(@"""{"label":"CardScheme","propertyDefaultType":"string","resourceType":"event","type":"string","value":"CardScheme"}"""@), @"""{"label":"CardScheme","propertyDefaultType":"string","resourceType":"event","type":"string","value":"CardScheme"}"""@, "amex")
  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Let me check the knowledge base for you again. One moment! 📚

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    I see the issue with your custom property formula. The syntax you're using is incorrect for Mixpanel's custom property formulas. Let me help you fix it.In Mixpanel's custom property feature, you should use a simpler syntax. Here's the correct way to check if a property is defined and provide a default value: LBKSif(defined(properties["CardScheme"]), properties["CardScheme"], "amex")LBKSThis formula will: 1. Check if the "CardScheme" property is defined 2. If it is defined, return its value 3. If it's not defined, return "amex" as the default valueThe complex JSON-like structure you're using in your formula isn't the correct syntax for Mixpanel's custom property formulas. Mixpanel uses a more straightforward approach to reference properties.Custom Properties documentation provides examples of the correct syntax for using functions like defined() in custom property formulas.

    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.