thankful-gpu-70135
01/09/2024, 12:42 AM{
"type": "track",
"event": "Upgrade CTA [Discounts] Clicked",
"originalTimestamp": "2024-01-08 23:16:51.589000",
"userId": "5476",
"request_ip": "24.143.104.2",
"context": {
"traits": {
"email": "test@bigcartel.com"
}
}
}
Looking at what the rudderstack Live Events view shows me from the webhook source is this.
{
"anonymousId": "38215463-e99f-4d2f-bec5-46e954dcea9f",
"event": "webhook_source_event",
"messageId": "7779a9ec-6635-4392-adf3-df6fd93cb976",
"properties": {
"event": "Upgrade CTA [Bulk Editing] Clicked",
"originalTimestamp": "2024-01-09 00:20:56.236000",
"request_ip": "71.212.158.50",
"traits": {
"email": "test@bigcartel.com"
},
"type": "track",
"userId": "5476"
},
"rudderId": "28b43a9c-d1b5-4385-b156-db1bdbe5144d",
"type": "track"
}
Notice that my original event is within the properties and there is an outer event called webhook_source_event. Thihs makes webhook events behave differently than other SDK sources which doesn't do this. This has ramifications with how to easily reuse transformations for a single destination that may say get events from a webhook source vs javascript source.
E.g. you cannot just look for event.context.traits. You have to see if it's a webhook source event, then look at event.properties.context.traits
What the heck?
For downstream destinations, it seems I now how have these differently than other events to "unwrap" the webhook events because Rudderstack isn't automatically handling this.
For example looking at the event send to Klaviyo the payload looks like this. Notice the event is webhook_source_event instead of my actual event. This is a huge fail IMO. Webhook events should be handled exactly the same as other events from other SDKs. This forced us to now special case webhook events to deal with this and manually construct the real event payload that RS shoudl be doing automatically
{
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://a.klaviyo.com/api/events",
"headers": {
"Authorization": "******e47c",
"Content-Type": "application/json",
"Accept": "application/json",
"revision": "2023-02-22"
},
"params": {},
"body": {
"JSON": {
"data": {
"type": "event",
"attributes": {
"metric": {
"name": "webhook_source_event"
},
"properties": {
"type": "track",
"event": "Upgrade CTA [Bulk Editing] Clicked",
"traits.email": "test@bigcartel.com",
"userId": "5476",
"request_ip": "71.212.158.50",
"originalTimestamp": "2024-01-09 01:24:03.526000"
},
"profile": {
"$id": "c1aeb07f-7697-402c-bc6a-9b472536b8ca"
},
"time": "2024-01-09T01:24:05.588Z"
}
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}millions-activity-52391
01/09/2024, 12:42 AMmillions-activity-52391
01/09/2024, 1:06 PMthankful-gpu-70135
01/09/2024, 8:11 PMexport function unwrapWebhookEvent(event) {
if (event.event === 'webhook_source_event' && event.properties) {
// Move all event properties to root level
for (const key in event.properties) {
event[key] = event.properties[key];
}
// Overwrite event name at the root level to be the actual event name
event.event = event.properties.event;
// Remove the 'properties' property as it's no longer needed
delete event.properties;
}
return event;
}
It seems like everyone using webhook event sources would need this.helpful-daybreak-79835
01/10/2024, 4:35 AMthankful-gpu-70135
01/10/2024, 4:37 AMhelpful-daybreak-79835
01/10/2024, 4:39 AMhelpful-daybreak-79835
01/10/2024, 4:40 AMthankful-gpu-70135
01/10/2024, 4:41 AM