For the complete documentation index, see llms.txt. This page is also available as Markdown.

Server events

Server events are sent from your backend straight to Chord when something happens to an order: it's placed, cancelled, refunded or shipped. They don't depend on the shopper's browser, so ad blockers and closed tabs can't stop them, and they're the reliable record of what was sold.

Your backend sends each event as an HTTP request to Chord's events endpoint. This page walks through it.

Step 1: Get your endpoint and write key

Ask Chord for:

  • Your CDP domain, such as https://production.cdp.ingest.chord.co.

  • A server-side write key. It's different from the write key your storefront uses. Keep it secret: store it with your other backend credentials, never in browser code.

Server events go to these endpoints on your CDP domain:

  • Track (something happened): /api/track

  • Identify (who a customer is): /api/identify

Step 2: Send events when they happen

Send a track event from your backend each time one of these happens. Each event's page in the tracking plan lists its properties.

If you sell subscriptions, send the subscription events in the tracking plan too, such as Subscription Created and Subscription Payment Failed.

Every track request carries:

  • type (required): track

  • event (required): the event name, such as Order Completed

  • properties: the event's properties from the tracking plan

  • userId: your ID for the customer, if they have an account

  • anonymousId: the browser's anonymous ID (see step 3)

Send your write key in the X-Write-Key header. Here's a complete Order Completed request:

Chord adds timestamp, receivedAt and messageId to each event. Send your own timestamp if the event happened earlier than you're sending it, for example when you replay a queue.

If your system can't set headers, you can send the write key as a writekey query parameter (all lowercase) or a writeKey property in the body. Use the header when you can.

Your backend's events and the shopper's browser events are separate streams. To join them, pass the browser's anonymous ID along with the order:

  1. On the storefront, read the anonymous ID that @chordcommerce/analytics gave the shopper. It's in the __eventn_id cookie.

  2. Save it on the cart or order in your platform, for example as a custom attribute, before the shopper reaches checkout.

  3. In your backend, send it as anonymousId on every server event for that order.

Without it, Chord can't connect an order to the browsing and ad clicks that led to it.

Step 4: Identify the customer

Server events carry no browser context, so destinations that match customers by email, phone or address only get those details if you send them. When an order is placed or an account is created, send an identify call with the customer's details:

Use these trait names: first_name, last_name, and address1, address2 and zipcode for addresses. Always include email if you have it; it's what most destinations match on. See the Context object for every trait.

An identify call updates the customer's profile. It isn't an event, so it can't trigger automations in destinations. On account creation, send both an identify and a User Created event.

Step 5: Verify

  1. Send a test Order Completed from your backend.

  2. In Chord, open Live Events for your back-end source and check that it arrived with the right properties.

  3. Place a real test order through your storefront, and check that its Order Completed carries the same anonymousId as the browser events from that session.

Last updated

Was this helpful?