LearnAPI & Server-side

API & Server-side Setup

Send events from your backend or any server to Hardal with an HTTP POST to the /collect endpoint.

When to use the API

Use the API to send events from your backend, such as confirmed orders and CRM leads.

The endpoint and payload are identical to Mobile Setup. Both send an HTTP POST to /collect.

Privacy by default

You can send server events without a known user identity. Include userId or other identity fields only when your consent rules allow it. If a destination requires consent, send the applicable consent state with the event.

Consent Signals

When to send consent and what each signal changes.

Server event endpoint

POST https://analytics.yourdomain.com/collect

Use the collection URL generated for the source in Setup. Connect the tracking domain before sending requests.

HeaderRequiredValue
Content-TypeYesapplication/json
User-AgentYesOriginal client user agent when forwarding a request, or the application's user agent for backend events
x-hrd-session-idNoStable UUID for the current session
x-hrd-consentNogranted or denied
X-Forwarded-ForNoOriginal client IP from a trusted source, when consent permits it

Send tenantId in the top-level JSON body and sourceId inside each event's payload. Copy both UUIDs from Setup.

Reuse x-hrd-session-id for events from the same session. If you send no session ID, Hardal creates one. Send x-hrd-consent: granted only when identity processing is allowed. Send denied when consent is declined or unknown.

Server event payload

{
  "tenantId": "your-tenant-id",
  "type": "event",
  "eventName": "purchase",
  "payload": {
    "sourceId": "your-source-id",
    "url": "https://www.yourdomain.com/order/confirmation",
    "timestamp": 1750000000000,
    "data": {
      "transaction_id": "ORD-20260615-7891",
      "value": 214.98,
      "currency": "USD",
      "items": [
        { "item_id": "SKU-1", "item_name": "Example item", "price": 214.98, "quantity": 1 }
      ]
    }
  }
}

timestamp must be the moment the event happened, in milliseconds since the Unix epoch. Use Date.now() in Node.js, int(time.time() * 1000) in Python, or time.Now().UnixMilli() in Go. The value in the example is only a placeholder.

One event cannot contain both a non-empty items array and a non-empty leads array.

Send a server event

# Create once and reuse for events from this test session.
SESSION_ID=$(uuidgen)
# Event time in milliseconds. Reuse a stored value for a delayed or retried event.
NOW_MS=$(($(date +%s) * 1000))

curl -X POST https://analytics.yourdomain.com/collect \
  -H "Content-Type: application/json" \
  -H "User-Agent: ${USER_AGENT:?Set USER_AGENT to the application User-Agent}" \
  -H "x-hrd-session-id: $SESSION_ID" \
  -H "x-hrd-consent: denied" \
  -d "{
    "tenantId": "your-tenant-id",
    "type": "event",
    "eventName": "generate_lead",
    "payload": {
      "sourceId": "your-source-id",
      "url": "https://www.yourdomain.com/contact",
      "timestamp": $NOW_MS,
      "data": {
        "lead_id": "LEAD-12345",
        "value": 500,
        "currency": "USD"
      }
    }
  }"

Check data.accepted in the 202 Accepted response, then confirm the event in Engagement → Events for the same source. See Send Events if the event is missing.

Send a batch

Send multiple events to the same endpoint by wrapping them in an events array. Use one Tenant ID per request. Batch events that share the same session, consent, and request context.

{
  "tenantId": "your-tenant-id",
  "events": [
    {
      "type": "page_view",
      "eventName": "page_view",
      "payload": {
        "sourceId": "your-source-id",
        "url": "https://www.yourdomain.com/products",
        "timestamp": 1750000000000,
        "data": {}
      }
    },
    {
      "type": "event",
      "eventName": "purchase",
      "payload": {
        "sourceId": "your-source-id",
        "url": "https://www.yourdomain.com/order/confirmation",
        "timestamp": 1750000000060,
        "data": {
          "transaction_id": "ORD-20260615-7891",
          "value": 214.98,
          "currency": "USD",
          "items": [
            { "item_id": "SKU-1", "item_name": "Example item", "price": 214.98, "quantity": 1 }
          ]
        }
      }
    }
  ]
}

Send each event's own occurrence time in Unix milliseconds. Replace the example timestamps with the actual values.

Purchase workflow

Use Track Server-Confirmed Purchases to connect confirmed backend orders to the purchase schema, session context, and Commerce verification.

Send Events API

Full reference and a live playground for the /collect endpoint.

Pick your events