> For the complete documentation index, see [llms.txt](https://docs.formsort.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.formsort.com/integrations/integration-reference/amplitude/amplitude-cross-domain-tracking.md).

# Amplitude cross domain tracking

Track responders in Amplitude across domains

## Overview

If you would like to track Amplitude users across multiple domains e.g:

* Site 1: <https://www.example.com>
* Site 2: <https://www.flow.example.com> (the domain hosting the Formsort flow)

You must explicitly pass the amplitude device id from the top level domain to the one hosting the Formsort flow. This can be done for the both with a direct link deployment or an embedded flow.

## Setup

### Step 1: Enable using cross domain tracking in the Amplitude integration

Navigate to the Amplitude integration and enable "Use device ID from URL parameter".

![](https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FnzSJ95kRDTryXOPPieXW%2Fimage.png?alt=media\&token=8abe81a4-944d-43f1-9f0b-f59428159d00)

### Step 2: Pass the device id as a query parameter to responders hitting the flow

Follow the [official Amplitude documentation](https://developers.amplitude.com/docs/advanced-settings#cross-domain-tracking-javascript). After deploying the flow in Step 1, you can now pass a device id into the flow as a parameter.&#x20;

#### Passing via direct link

Pass the device id as a query parameter, for example this may look like:

1. From the initial Site 1 grab the Device ID from the Amplitude SDK using `amplitude.getInstance().options.deviceId`.
2. Pass the Device ID to the new Site 2 via a URL parameter when the user navigates. (e.g. `https://flow.example.com/client/{{your_account_name}}/flow/{{your_flow_name}}/variant/{{your_flow_variant_name}}/?amp_device_id=device_id_from_site_1`)
3. Initialize the Amplitude SDK on Site 2 with `amplitude.init('API_KEY', null, {deviceIdFromUrlParam: true})`.

#### Passing via embed

If you want to enable cross domain tracking in an embedded flow, you can pass `amp_device_id` via `query_params` in our [react-embed](https://github.com/formsort/oss/tree/master/packages/react-embed) package. e.g.

```tsx
// in the main site retrieve device id from amp instance
const ampDeviceId = amplitude.getInstance().options.deviceId;

// pass the device id to Formsort flow
<EmbedFlow
  clientLabel="client"
  flowLabel="onboarding"
  queryParams={[['amp_device_id', ampDeviceId]]}
/>
```

If you don't use react, you can do the same using our [web-embed-api](https://github.com/formsort/oss/tree/master/packages/web-embed-api#loadflowclientlabel-string-flowlabel-string-variantlabel-string-queryparams-arraystring-string--void). e.g.

```typescript
// in the main site retrieve device id from amp instance
const ampDeviceId = amplitude.getInstance().options.deviceId;

embed.loadFlow(
  'client', // client label
  'onboarding', // flow label
  'main', // variant label - optional
  [['amp_device_id', ampDeviceId]] // query params
)
```

Note: After initializing amplitude, Formsort flow removes device id from URL. But cross-domain tracking keeps working if user refreshes the page.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.formsort.com/integrations/integration-reference/amplitude/amplitude-cross-domain-tracking.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
