Integrate data collection and management for user analytics.

Using the Segment API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Segment background job resumable and appear in our dashboard.

  • Use io.runTask() and the official SDK or fetch.

  • Use our HTTP endpoint to subscribe to webhooks

  • Example code using Segment

    Below are some working code examples of how you can use Segment with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

    import { TriggerClient } from "@trigger.dev/sdk";
    import crypto from "crypto";
    // Create an HTTP Endpoint, with the Segment details
    const segment = client.defineHttpEndpoint({
    id: "segment",
    source: "segment.com",
    icon: "segment",
    verify: async (request) => {
    const signature = request.headers.get("X-Signature");
    if (!signature) {
    return { success: false, reason: "Missing header" };
    }
    const body = await request.text();
    const bodyDigest = crypto
    .createHmac("sha1", process.env.SEGMENT_WEBHOOK_SIGNING_SECRET!)
    .update(body)
    .digest("hex");
    if (signature !== bodyDigest) {
    return { success: false, reason: "Failed sha1 verification" };
    }
    return { success: true };
    },
    });
    client.defineJob({
    id: "http-segment",
    name: "HTTP Segment",
    version: "1.0.0",
    enabled: true,
    // Create a trigger from the HTTP endpoint
    trigger: segment.onRequest(),
    run: async (request, io, ctx) => {
    const body = await request.json();
    await io.logger.info(`Body`, body);
    },
    });
    ,