# Destination

A Destination is custom code that behaves like one of our built-in channels. It runs at event time on the EdgeTag edge, at page load in the browser, and optionally via a cron. It can call third-party APIs, read and write your identity graph, store data in its own database, and expose HTTP endpoints on your domain.

Use a Destination when you need something that isn't covered by the channels EdgeTag ships with. Typical examples include forwarding events to an in-house analytics tool, building a warehouse webhook, or exposing a first-party `/api/subscribe` endpoint backed by your own database.

{% hint style="info" %}
If you're modifying events flowing through **existing** channels (dropping, renaming, enriching), use a [Transformation](broken://pages/SbZJG1KnDnq3GEIyi6Vc) instead. Destinations are for creating **new** integrations.
{% endhint %}

{% embed url="<https://www.loom.com/share/9ddb51e5014644d5b2ea9e9f7115dd41>" %}

### What's in a Destination

A Destination is made up of a small set of stage files and, optionally, custom HTTP endpoints:

* **Edge files** — `edge/init`, `edge/tag`, `edge/user`, `edge/scheduled`. Run on the EdgeTag edge (Cloudflare Workers) at their respective lifecycle points.
* **Browser files** — `browser/init`, `browser/tag`, `browser/user`. Run in the visitor's browser alongside the EdgeTag SDK.
* **CDN APIs** — browser-callable HTTP endpoints on your EdgeTag domain.
* **Server APIs** — authenticated server-only HTTP endpoints, with access to the current user.

Only the files you actually write are invoked — leaving a file empty skips that stage entirely.

{% content-ref url="/pages/983b45d97791714f87a341bc60152bcdf2082402" %}
[File Structure](/playground/destination/file-structure.md)
{% endcontent-ref %}

### Capabilities at a glance

From Destination code, you can:

* Make outbound HTTP requests through `params.requestHandler`
* Read and write the EdgeTag identity graph via `params.userSave`, `params.userGet`, and `params.providerSave`
* Persist state in a **D1** database, **KV** store, **R2** bucket, or **Analytics Engine** dataset
* Run **scheduled** jobs on a cron
* Load and initialize third-party scripts in the browser, with full consent awareness
* Expose **custom HTTP endpoints** (authenticated server APIs and browser-callable CDN APIs) on your EdgeTag domain


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edgetag.io/playground/destination.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
