Mixpanel Community Icon

Incorrect Syntax for Custom Property in IF Statement

·
·

why this syntax is incorrect for a custom property? IF( “utm_source=” NOT in Current URL,UNDEFINED,utm_source)

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

    Hi Elena 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
    ·
    ·

    There are several issues with your custom property formula syntax in Mixpanel: 1. The in operator is being used incorrectly. In Mixpanel's custom property formulas, the in operator checks if a value is contained within another value or list, but your syntax has it reversed. The correct syntax would be to check if a value is in a string, not if a string contains a value.2. The NOT keyword is incorrectly placed. In Mixpanel, you should use the not function or simply use the not in operator.3. "Current URL" is not a valid reference in Mixpanel custom properties. You would need to use an actual property that contains the URL, such as $current_url.4. "UNDEFINED" should be lowercase undefined or you can simply omit the value to get an undefined result.Based on the Mixpanel documentation on custom properties, a correct formula might look like: LBKSif(not defined(utm_source) or utm_source == "", undefined, utm_source)LBKSOr if you're trying to check if a URL contains a UTM parameter: LBKSif(not regex_match($current_url, "utm_source="), undefined, utm_source)LBKSMixpanel's custom property formulas support various functions like if, not, defined, and regex_match that you can use to create conditional logic Custom Properties Functions.

    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.