# Snippet

> Retrieve the org-level tracking snippet and embeddable lead-capture form configuration

Source: https://docs.graph8.com/developers/snippet/

The snippet endpoints return the org-level tracking code and embeddable lead-capture form that you place on your website. They use the organisation's first stream, so no stream ID is required.

---

## Get Tracking Snippet

`GET /snippet`

Returns the same payload shape as `GET /repos/{repo_id}/snippet` but automatically resolves to the organisation's first stream. Use this when you do not need to target a specific stream.

### Example

**cURL**

```bash
curl "https://be.graph8.com/api/v1/snippet" \
  -H "Authorization: Bearer $API_KEY"
```

### Response

```json
{
  "data": {
    "write_key": "wk_abc123...",
    "tracking_host": "https://t.graph8.com",
    "domains": ["example.com"],
    "react_snippet": "import { G8Analytics } from '@graph8/nextjs'\n...",
    "script_tag": "<script src=\"https://t.graph8.com/p.js\" data-write-key=\"...\" data-tracking-host=\"...\" defer></script>",
    "config": {
      "write_key": "wk_abc123...",
      "tracking_host": "https://t.graph8.com",
      "project_id": "proj_xyz",
      "domains": ["example.com"]
    }
  }
}
```

| Field | Type | Description |
|-------|------|-------------|
| `write_key` | string | Public write key used to authenticate tracking events |
| `tracking_host` | string | Base URL that the snippet sends events to |
| `domains` | array of strings | Domains associated with this stream |
| `react_snippet` | string | Ready-to-use React/Next.js import snippet |
| `script_tag` | string | HTML `script` tag for non-React sites |
| `config` | object | Machine-readable config object for custom integrations |
| `config.write_key` | string | Write key (same as top-level `write_key`) |
| `config.tracking_host` | string | Tracking host (same as top-level `tracking_host`) |
| `config.project_id` | string | Internal project identifier |
| `config.domains` | array of strings | Domains list (same as top-level `domains`) |

---

## Get Form Snippet

`GET /snippet/form`

Returns the embeddable HTML lead-capture form along with its configuration — write key, tracking host, field list, and event name — ready to drop into any page.

### Example

**cURL**

```bash
curl "https://be.graph8.com/api/v1/snippet/form" \
  -H "Authorization: Bearer $API_KEY"
```

### Response

```json
{
  "data": {
    "html": "<form id=\"g8-lead-form\">...</form><script>...</script>",
    "write_key": "...",
    "tracking_host": "https://t.graph8.com",
    "fields": ["name", "email", "company"],
    "event_name": "form_submitted",
    "notes": "..."
  }
}
```

| Field | Type | Description |
|-------|------|-------------|
| `html` | string | Ready-to-embed HTML string containing the form markup and inline script |
| `write_key` | string | Public write key used by the snippet to authenticate tracking events |
| `tracking_host` | string | Base URL that the snippet sends events to |
| `fields` | array of strings | Ordered list of field names rendered in the form |
| `event_name` | string | Event name fired when the form is submitted |
| `notes` | string | Optional implementation notes or instructions |

> **Note:**
> The `X-Org-Id` header is optional and defaults to the organisation associated with your API key. Pass it explicitly only when targeting a different org.
