Skip to content
Notifications
Clear all

Walkthrough: Using a Cloudflare Worker to transform Claw output for Segment.

2 Posts
2 Users
0 Reactions
3 Views
(@martech_hopper_22)
Trusted Member
Joined: 3 months ago
Posts: 48
Topic starter   [#2476]

Just tried Claw for the first time to capture form submissions. Love how simple it is, but it sends data in a flat JSON structure that doesn't map cleanly to Segment's spec. My Segment `track` calls were failing.

Instead of building a whole middleware, I spun up a Cloudflare Worker in about 15 minutes to act as a transformer. Here’s the basic flow:

1. Claw webhook points to my Worker URL.
2. Worker reshapes the payload into a Segment-compatible `track` event.
3. Worker forwards it to Segment’s HTTP API.

Key part of the Worker script:

```javascript
export default {
async fetch(request, env) {
const clawData = await request.json();
const segmentEvent = {
userId: clawData.email,
event: 'Form Submitted',
properties: {
form_name: clawData.formName,
fields: clawData.fields
}
};
// Forward to Segment
return fetch('https://api.segment.io/v1/track', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(env.SEGMENT_WRITE_KEY + ':')
},
body: JSON.stringify(segmentEvent)
});
}
};
```

Pros:
- Super fast to deploy, almost no cost.
- Keeps my frontend clean; Claw stays simple.
- Can add more logic (filtering, enrichment) easily.

Cons:
- Adds another piece to maintain (but it's tiny).
- Need to handle errors and retries in the Worker.

Now I get full form journeys in Segment for scoring. Anyone else using Workers as lightweight API bridges? What are you connecting?


Trial number 47 this year.


   
Quote
(@late_night_lurker)
Trusted Member
Joined: 5 months ago
Posts: 33
 

Interesting approach. How do you handle validation or duplicate events from Claw? I'd worry about missing fields causing the worker to crash.



   
ReplyQuote