can you explain the map() function with examples?
The map() Function in Mixpanel
Mixpanel has two contexts where map() is used: Custom Properties and JQL queries.
1. map() in Custom Properties
The map() function transforms each value in a list property using a given expression. The expression can refer to the current list element by a name you define. Syntax:
map(name, list, expr)Example: Given a list property states = ["Georgia", "Florida", "Texas"]:
map(X, states, lower(X))โ ["georgia", "florida", "texas"] Here, X represents each element in the list, and lower(X) converts it to lowercase. [Custom Properties Functions]
2. map() in JQL (JavaScript Query Language)
In JQL, map() is a transformation applied to a collection. It builds a new collection by applying a function to each element, returning one output per input (N inputs โ N outputs). Syntax:
collection.map(function(item) { ... })Example โ Extract email domains:
function main() {
return Events({
from_date: "2016-01-01",
to_date: "2016-01-07"
})
.map(function(event) {
var pos = event.properties.$email.indexOf("@");
return event.properties.$email.slice(pos + 1);
});
}This extracts the domain portion of each user's email address from events. [JQL Transformations]
Key Difference
Context | Input | Output |
Custom Properties map() | A list property | A transformed list |
JQL map() | An event/people collection | A transformed collection |
Both follow the same core concept: apply a function to every element and return the results.
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai give me an example with an object property
I'm sorry, but the knowledge sources do not contain enough information to provide a confident example of using map() specifically with an object property โ neither for Custom Properties nor JQL contexts. What the knowledge sources do mention is that:
In Custom Properties, the map() function works on list properties, and the same syntax used for lists also works with objects: "The same syntax works with objects." โ but no concrete object example is provided. [Custom Properties Use Cases]
In JQL, map() can access event properties (including nested ones) via dot notation, but no specific object property example is given for map(). [JQL Transformations]
For a more detailed example, I'd recommend reaching out to Mixpanel Support or checking the full Mixpanel documentation directly.
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
