> ## Documentation Index
> Fetch the complete documentation index at: https://docs.davazmysel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generic backend integration

> Send server-side events to Dáva from Node.js, PHP, or the command line.

Use this guide when your backend is a Node.js service, a PHP application, or any stack not covered by the platform-specific recipes. Every example calls `POST /v1/events` — the same endpoint regardless of your infrastructure.

For the full field reference, identity rules, deduplication behaviour, and the batch endpoint, see the [Server-Side Events](/tracking/server-side-events) guide.

## Browser tracking

Install the [Dáva tracking snippet](/tracking/install-snippet) on every landing and destination page so browser-side events (page views, clicks, form submits) flow automatically. Server events enrich that existing journey — they do not replace browser tracking.

## Server events

All three examples below post a `conversion` event for a completed purchase. Replace `dava_sk_live_...` with your API key from **Settings → Workspace → Settings & Integrations** (API Keys card) and `yourcompany.com` with your Dáva-registered subdomain.

<Note>
  `subdomain` is required when calling `api-v2.davazmysel.com` directly. If you have configured a custom-domain install (your own hostname registered in Dáva), omit `subdomain` — Dáva reads the domain from the `Host` header instead. See [Sending a single event](/tracking/server-side-events#sending-a-single-event) for details.
</Note>

<CodeGroup>
  ```js Node.js (fetch) theme={null}
  const response = await fetch("https://api-v2.davazmysel.com/v1/events", {
    method: "POST",
    headers: {
      "Authorization": "Bearer dava_sk_live_xxxxxxxxxxxxxxxxxxxx",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      subdomain: "yourcompany.com",
      event_type: "conversion",
      event_name: "purchase",
      anonymous_id: "anon-id-from-dava-cookie",
      dava_session_id: "01941b8c-3ae4-7e2a-9b5a-4e2a88c60d10",
      event_id: "order_ORD456",
      transaction_id: "ORD456",
      value: 99.00,
      currency: "AUD",
    }),
  });

  const data = await response.json();
  // data.session_match: "matched" or "unmatched" — confirm during integration testing
  // data.deduped: true if this was a duplicate delivery
  ```

  ```php PHP (cURL) theme={null}
  <?php
  $payload = json_encode([
      'subdomain'       => 'yourcompany.com',
      'event_type'      => 'conversion',
      'event_name'      => 'purchase',
      'anonymous_id'    => 'anon-id-from-dava-cookie',
      'dava_session_id' => '01941b8c-3ae4-7e2a-9b5a-4e2a88c60d10',
      'event_id'        => 'order_ORD456',
      'transaction_id'  => 'ORD456',
      'value'           => 99.00,
      'currency'        => 'AUD',
  ]);

  $ch = curl_init('https://api-v2.davazmysel.com/v1/events');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST           => true,
      CURLOPT_POSTFIELDS     => $payload,
      CURLOPT_HTTPHEADER     => [
          'Authorization: Bearer dava_sk_live_xxxxxxxxxxxxxxxxxxxx',
          'Content-Type: application/json',
      ],
      CURLOPT_TIMEOUT        => 10,
  ]);

  $response = curl_exec($ch);
  $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  $data = json_decode($response, true);
  // Check $data['session_match'] === 'matched' during integration testing
  ```

  ```bash cURL theme={null}
  curl -s -X POST https://api-v2.davazmysel.com/v1/events \
    -H "Authorization: Bearer dava_sk_live_xxxxxxxxxxxxxxxxxxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "subdomain": "yourcompany.com",
      "event_type": "conversion",
      "event_name": "purchase",
      "anonymous_id": "anon-id-from-dava-cookie",
      "dava_session_id": "01941b8c-3ae4-7e2a-9b5a-4e2a88c60d10",
      "event_id": "order_ORD456",
      "transaction_id": "ORD456",
      "value": 99.00,
      "currency": "AUD"
    }'
  ```
</CodeGroup>

### Identity

At least one of `anonymous_id`, `contact_id`, or `hashed_email` is required — the request is rejected with `400` if all three are absent. Use whichever identity signals you have:

* `anonymous_id` — the Dáva cookie value from the visitor's browser session.
* `contact_id` — your own customer or contact ID.
* `hashed_email` — SHA-256 hex of the customer's email address (with or without a `sha256:` prefix).

### Deduplication

`event_id` and `transaction_id` are your dedup keys. If a network retry or queue redelivery sends the same event twice, Dáva collapses it to one canonical event and returns `200` with `deduped: true`. See [Deduplication](/tracking/server-side-events#deduplication) for the full priority chain and merge behaviour.

## Hybrid setup (recommended)

A hybrid setup pairs the browser snippet with server-confirmed events, linking both onto the same visitor journey using `dava_session_id`.

**The flow:**

1. The browser snippet loads on your page and creates a session.
2. Your **frontend JavaScript** reads the session ID: `window.dava.sessionId`
3. The frontend passes that value to your backend — via a hidden form field, a cookie, a custom request header, or your own API call body.
4. Your backend reads it from wherever the frontend placed it and includes it as `dava_session_id` in the server event payload.

```js theme={null}
// In the browser — runs after the Dáva snippet has loaded:
const sessionId = window.dava ? window.dava.sessionId : null;

// Pass it to your backend however makes sense for your stack,
// e.g. a hidden form field:
const field = document.getElementById("dava_session_id_field");
if (field && sessionId) field.value = sessionId;
```

<Warning>
  The backend cannot read `window.dava.sessionId` directly — that is a browser object. The frontend must collect it and pass it to the server explicitly (form field, cookie, request body, etc.).
</Warning>

For more on journey joining and what happens when the session ID does not match, see [Joining the visitor's journey](/tracking/server-side-events#joining-the-visitor-s-journey).

## Next steps

* [Server-Side Events reference →](/tracking/server-side-events) — full field table, dedup chain, batch endpoint, and error codes
* [Install the tracking snippet →](/tracking/install-snippet) — browser snippet options, consent mode, and the Cloudflare Worker proxy install method
