> For the complete documentation index, see [llms.txt](https://help.distro.so/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.distro.so/integrations/javascript-events.md).

# JavaScript

Use the script from **Install Router** when connecting a website form. The `Distro` browser interface also supports submitting data from your own form flow.

## Connect an existing form

```html
<script src="https://app.distro.so/inbound.js"></script>
<script>
  const distro = new Distro({ routerId: 'YOUR_ROUTER_ID' });
  distro.schedule('#contact-form');
</script>
```

Use a selector that identifies the intended form. Load the provider library before initializing a HubSpot or Marketo integration. See [Forms](/routing-forms/overview.md) for provider-specific setup.

## Submit from a custom flow

`submit(data)` creates a routing attempt and returns the qualified session data when scheduling can proceed. Call `open(session)` to show the scheduler. A disqualified or failed response can be empty; do not open a scheduler for it.

```javascript
const distro = new Distro({ routerId: 'YOUR_ROUTER_ID' });
const session = await distro.submit({
  email: 'prospect@example.com',
  name: 'Alex Morgan'
});
if (session) distro.open(session);
```

Use the exact field names expected by your form mapping. Do not attach both this custom submission flow and `schedule()` to the same submission, or you can create duplicate attempts.

## Track confirmed outcomes

A browser submission or opened scheduler is not proof of a booking. Use a [workflow webhook](/workflows/webhook-payloads.md) when another system needs confirmed booking and lifecycle events. Internal iframe messages control the widget's display and redirects; they should not be treated as an authenticated booking feed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.distro.so/integrations/javascript-events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
