in mixpanel ui, create a custom property to extract the value in utm_source=value in an URL with REGEX_EXTRACT()
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
To create a custom property in the Mixpanel UI that extracts the value of utm_source from a URL using REGEX_EXTRACT(), you can use the following formula:
```
REGEX_EXTRACT(properties["<your_url_property> "], "[?&]utm_source=([^&#]*)", 1)
LBKSReplace `<your_url_property> ` with the actual property name that contains your URL (for example, `properties["page_url"]`).
- This regex looks for `utm_source=` preceded by either `?` or `&`, and captures everything after the `=` up to the next `&`, `#`, or the end of the string.
- The `1` at the end specifies that you want the first capture group, which is the value of `utm_source`.
You can enter this formula in the custom property builder in Mixpanel as described in the documentation. For more on using `REGEX_EXTRACT()`, see the [Custom Properties: Functions reference](https://docs.mixpanel.com/docs/features/custom-properties#functions)<source> [https://docs.mixpanel.com/docs/features/custom-properties#functions</source](https://docs.mixpanel.com/docs/features/custom-properties#functions</source)> .
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! 📚
The “syntax error, unexpected ‘)’” message usually means there is a problem with the formula syntax in the Mixpanel custom property builder. Based on the knowledge sources, here are some things to check:
1. Delimiter Must Be a Single ASCII Character:
The split() function in Mixpanel only accepts a single ASCII character as a delimiter, not a string or regex. If you tried to use split with a multi-character delimiter or regex, it will throw a syntax error. For extracting with regex, use REGEX_EXTRACT() instead.
2. REGEX_EXTRACT Syntax:
The correct syntax for REGEX_EXTRACT is:
regex_extract(haystack, pattern, <optional capture group#> )
For example:
regex_extract(properties["page_url"], "[?&]utm_source=([^&#]**)", 1)
Make sure:
- You use lowercase regex_extract (not uppercase).
- All parentheses are matched and closed.
- The property name is correct and exists in your data.
3. Check for Extra or Missing Parentheses: A common cause of this error is an extra or missing parenthesis. Double-check your formula for this.
4. Function Name Case Sensitivity:
Mixpanel’s formula language is case-sensitive. Use regex_extract, not REGEX_EXTRACT.
Example (correct usage):
regex_extract(properties["page_url"], "[?&]utm_source=([^&#]**)", 1)
If you still get the error, ensure that the property you are referencing (e.g., properties["page_url"]) actually exists in your events.
For more details, see the Custom Properties: Functions reference<source> https://docs.mixpanel.com/docs/features/custom-properties#functions</source> .
If you continue to encounter issues, please provide the exact formula you are using so I can help debug further.
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.
