# Simulation

Simulation runs your Destination code in an isolated sandbox against a realistic sample event, captures every side effect, and shows you the result — without anything reaching production. Use it after every change before you save.

<figure><img src="/files/o1Q9ynmoIIywMEwLWumL" alt=""><figcaption></figcaption></figure>

### What gets run

When you click **Simulate**, Playground:

1. Takes the current code from every stage file
2. Injects your [Variables](/playground/destination/variables.md) as `params.secrets`
3. Mocks every [Infrastructure](/playground/destination/infrastructure.md) binding in memory
4. Runs the file you selected (default is `edge/tag`) against the current sample event
5. Captures all HTTP requests, logs, and any thrown errors

Nothing leaves the sandbox. No real API calls are made, no rows are written to your D1 database, no files are uploaded to R2.

### Sample events

Every session starts with three pre-populated sample events you can switch between:

* **Purchase** — a full purchase with two line items, a value, an order ID, and user PII.
* **PageView** — a page view with a name and category.
* **AddToCart** — a single-item add-to-cart with a value and currency.

You change the sample event from the UI (click on View/Edit Input); the rest of the `params` object (user, host data, provider data, custom data) stays the same across events.

### What you see

The simulation output has three sections:

* **Captured requests** — every call your code made through `params.requestHandler`. Shows URL, method, headers, and body for each request.
* **Logs** — everything you wrote with `params.logger.log(...)` or `params.logger.error(...)`.
* **Error** — if your code threw, the error message and stack.

Sensitive values are redacted automatically: any header or body key matching `authorization`, `token`, `api-key`, `api_key`, `secret`, `password`, or `cookie` is replaced with `[REDACTED]` before it's shown.

### A complete worked example

Say you're writing a Destination that forwards `Purchase` events to a third-party conversions API with a SHA-256-hashed email and a Bearer token from Variables. After you simulate against the Purchase sample event, the output will look roughly like this:

{% code title="Simulation output" %}

```json
{
  "requests": [
    {
      "url": "https://api.example.com/conversions",
      "method": "POST",
      "headers": {
        "Authorization": "[REDACTED]",
        "Content-Type": "application/json"
      },
      "body": {
        "orderId": "ORD-2024-001234",
        "value": 149.99,
        "currency": "USD",
        "hashedEmail": "a1b2c3...",
        "country": "US"
      }
    }
  ],
  "logs": [
    "Forwarded Purchase ORD-2024-001234"
  ]
}
```

{% endcode %}

From that output, you can verify your code is:

* Hitting the right URL with the right method
* Passing the right headers (your Bearer token is present, even though it's redacted in the display)
* Sending the right body fields, in the right shape
* Logging what you expected

If anything is off — wrong URL, missing field, a `null` value you didn't expect — you fix it in the editor and simulate again. No deploy, no rollback, no risk.

{% hint style="info" %}
Simulate after every meaningful change. It's the fastest way to catch issues before they hit production, and it's the only way to see exactly what your third-party APIs will receive.
{% endhint %}


---

# 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/simulation.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.
