Hello. We trying to send data from one Webhook to ...
# support
a
Hello. We trying to send data from one Webhook to another with Data Transformation. But got troubles that RudderStack send empty data to Source. Why it may happens? Here is the screenshot of testing Transformation (shows correct output). But when I look Live events sent to the destination, events parameters are empty. Thank you!)
p
Hey @abundant-helmet-98984 can you share the data transformation you used for this?
a
@plain-parrot-49913 Hey. You mean code that we use for Transformation?
Here is it: export function transformEvent(event, metadata) { const EVENT_NAME = event.properties.event.name; const productID = event.properties.event.properties.product_id; const userId = event.properties.user.devices[0].device_id; const VALUE = event.properties.event.properties.usd_price; var VALUE_round = Math.round(VALUE * 100) / 100 if (isNaN(VALUE_round)) VALUE_round = 0; const isoTimestamp = event.properties.event.created_at; const timestampDate = new Date(isoTimestamp); const timestampSeconds = Math.round(timestampDate.getTime()/1000); var platform = “”; if (event.properties.user.subscriptions[0].store == “play_store”) { platform = “Android”; } else { platform = “iOS”; } var result = { “a”: “key”, “p”: platform, “n”: “apphud_“+EVENT_NAME, “i”: event.properties.app.bundle_id, “custom_user_id”: userId, // “value”: String(VALUE_round), “value”: String(0.1), “purchase_product_id”: productID, // “amt”: String(VALUE_round), “amt”: String(0.1), “cur”: “USD”, “is_revenue_event”: true, “utime”: timestampSeconds, “ip”: “85.253.16.7” }; if (platform == “iOS”) { if (event.properties.user.devices[0].idfa) { result.idfa = event.properties.user.devices[0].idfa; } if (event.properties.user.devices[0].idfv) { result.idfv = event.properties.user.devices[0].idfv; } } else { if (event.properties.user.devices[0].idfa) { result.aifa = event.properties.user.devices[0].idfa; } } return result; }
p
@abundant-helmet-98984 Rudderstack Trasformations operate on an event level, I notice that at the end here you are retuning a result value, while he expected returned value here is an event. Please use this definition to write your transformation: https://www.rudderstack.com/docs/features/transformations%20-%20old/#transformevent-definition
a
@plain-parrot-49913 You mean that we should modify event to add required fields? Here is new Transformation. Is it right?
export function transformEvent(event, metadata) { const EVENT_NAME = event.properties.event.name; const productID = event.properties.event.properties.product_id; const userId = event.properties.user.devices[0].device_id; const VALUE = event.properties.event.properties.usd_price; var VALUE_round = Math.round(VALUE * 100) / 100 if (isNaN(VALUE_round)) VALUE_round = 0; const isoTimestamp = event.properties.event.created_at; const timestampDate = new Date(isoTimestamp); const timestampSeconds = Math.round(timestampDate.getTime()/1000); var platform = “”; if (event.properties.user.subscriptions[0].store == “play_store”) { platform = “Android”; } else { platform = “iOS”; } event.a = “token”; event.p = platform; event.n = “apphud_“+EVENT_NAME; event.i = event.properties.app.bundle_id; event.custom_user_id = userId; event.value = “0.1”; event.purchase_product_id = productID; event.amt = “0.1"; event.cur = “USD”; event.is_revenue_event = true; event.utime = timestampSeconds; event.ip = “85.253.16.7"; if (platform == “iOS”) { if (event.properties.user.devices[0].idfa) { event.idfa = event.properties.user.devices[0].idfa; } if (event.properties.user.devices[0].idfv) { event.idfv = event.properties.user.devices[0].idfv; } } else { if (event.properties.user.devices[0].idfa) { event.aifa = event.properties.user.devices[0].idfa; } } return event; }
Yes, it’s works. Thank you