A common use case for functions is cleaning up webhook data from other tools so that they may be ingested into your warehouse, or forwarded to other tools.
These webhooks usually contain event data that are helpful for building a full profile of your users. For example, Shopify has webhooks for when users check out, and Iterable has webhooks for when users open emails.
To set this up, you can create a Webhook Source and add it to your tool that emits events. You can then process the raw webhook data using Functions.
For example, your code might look something like:
async function transformEvents(events) {
return events.map((event) => ({
...event,
type: "track",
event: event.event,
messageId: event.messageId,
properties: {
...event.properties.body.dataFields,
email: event.properties.body.email,
},
anonymousId: event.properties.body.userId
? null
: event.properties.body.email,
userId: event.properties.body.userId,
}));
}