> For the complete documentation index, see [llms.txt](https://docs.birdie.so/birdie-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.birdie.so/birdie-docs/request-screen-recordings/installation/snippet/multiple-domains-setup.md).

# Multiple Domains Setup

Attach console logs and network requests to every recording when your product runs on several separate bare domains.

Birdie attaches console logs and network requests to every recording. Use this setup when your product runs on several separate bare domains, like `acme.com` and `acme.io`, or on your customers' own domains. Otherwise, follow the standard [Snippet](/birdie-docs/request-screen-recordings/installation/snippet.md) setup.

{% hint style="warning" %}
**Before you begin: activation required**\
Multiple domain support is not enabled by default. Contact the Birdie team to have it enabled for your workspace before following this guide. Your setup will not work until this is done. [Contact us](mailto:support@birdie.so)
{% endhint %}

<details>

<summary>How the multiple-domains recording works under the hood</summary>

The snippet is dormant until a recording starts. When triggered, the recorder needs to communicate with the snippets across different domains. Browser-native communication channels don't work cross-origin, so both sides connect to a shared WebSocket channel instead. The channel is keyed on the authenticated user's email, which means the snippet must be initialized with that email so both ends subscribe to the same channel. That's why identifying your users is required here, unlike the single-domain setup.

<figure><img src="https://3843507234-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FECPgvsGwy5oMz4WIZw3a%2Fuploads%2FnmcpGz6qdHo65hzg5lJy%2Fhost-page-flow-multi-domain.png?alt=media&amp;token=103af6f8-0850-4380-bee7-a66a62b6a102" alt=""><figcaption></figcaption></figure>

</details>

## Install the snippet

Add the snippet to every page of your product, on each of your domains, with npm or yarn, or by pasting it in the `<head>`.

{% tabs %}
{% tab title="npm or yarn" %}
{% code title="Install" %}

```bash
npm install @birdie-so/snippet
# or
yarn add @birdie-so/snippet
```

{% endcode %}

Then initialize it with your client ID, from [Settings → Snippet & logs](https://app.birdie.so/settings/logs), and your user's email (see [Identify your users](#identify-your-users-required) below):

{% code title="Initialize" %}

```javascript
import { initBirdie } from "@birdie-so/snippet";

initBirdie({
  clientId: "YOUR_CLIENT_ID",
  contact: { email: "alex@empire.com" }, // required to get logs
});
```

{% endcode %}

More on the package: [@birdie-so/snippet on npm](https://www.npmjs.com/package/@birdie-so/snippet?activeTab=readme).
{% endtab %}

{% tab title="Paste in the <head>" %}
In [Settings → Snippet & logs](https://app.birdie.so/settings/logs), open **Install options** and paste the snippet in the `<head>` of every page of your product. It already contains your client ID and is unique to your organization. You can also click **Send to developer** to email it.

Then pass your user's email (see [Identify your users](#identify-your-users-required) below).

{% hint style="info" %}
We do not recommend installing Birdie through Google Tag Manager or Segment. Pasting the code directly in your web app loads faster.
{% endhint %}
{% endtab %}
{% endtabs %}

### Allow Birdie in your Content Security Policy

The snippet loads from two hosts and talks to three. Allow exactly these:

```
script-src   https://cf.birdie.so/widget/embed/ https://cdn.birdie.so/widget/
connect-src  https://app.birdie.so https://cf.birdie.so https://cdn.birdie.so/widget/ wss://sock.birdie.so https://sock.birdie.so
frame-src    https://app.birdie.so
img-src      data:
```

If you use **sensitive-data masking** (elements marked as hidden are masked with a stylesheet and a font), also allow:

```
style-src    https://cdn.birdie.so/widget/
font-src     https://cdn.birdie.so/widget/
```

The snippet needs no inline scripts, inline styles, or workers. The two `script-src` entries are deliberately path-scoped: `cdn.birdie.so` serves only Birdie's static build output, and `cf.birdie.so` serves only the widget under `/widget/`.

{% hint style="info" %}
If you prefer a single entry per directive, `https://*.birdie.so` and `wss://*.birdie.so` also work. The list above is the minimum.
{% endhint %}

If your pages send `Cross-Origin-Opener-Policy: noopener-allow-popups`, the recorder opened in a new window can't reach `window.opener`, and popup-to-opener communication fails. Don't isolate the opened page from its opener.

## Identify your users <mark style="color:$danger;">(required)</mark>

{% hint style="danger" %}
**Without the user's email, no logs are captured.** The recorder and your snippet must use the **same user email**: it's how Birdie connects a recording to the right pages across your domains.
{% endhint %}

Pass the email of the logged-in user when you initialize the snippet. Your client ID is in [Settings → Snippet & logs](https://app.birdie.so/settings/logs).

{% tabs %}
{% tab title="npm or yarn" %}
{% code title="Initialize with the user's email" %}

```javascript
initBirdie({
  clientId: "YOUR_CLIENT_ID",
  contact: {
    email: "alex@empire.com", // required to get logs
    name: "Alexander",        // optional
    id: 65523                 // optional
  },
});
```

{% endcode %}

If you only know the user later, set the email once Birdie is ready:

{% code title="Update the email later" %}

```javascript
birdie.update({ contact: { email: "alex@empire.com" } })
```

{% endcode %}
{% endtab %}

{% tab title="Paste in the <head>" %}
Set `window.birdieSettings` before the snippet loads:

{% code title="Before the snippet" %}

```javascript
window.birdieSettings = {
  contact_email: "alex@empire.com", // required to get logs
};
// then add the snippet…
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Optional: metadata and recorder events

<details>

<summary>How to add custom metadata</summary>

Store additional data along the recordings.

{% tabs %}
{% tab title="npm or yarn" %}
{% code title="Add metadata" %}

```javascript
initBirdie({
  clientId: "YOUR_CLIENT_ID",
  contact: { email: "alex@empire.com" }, // required to get logs
  metadata: {
    any: {
      key: "123",
      product_id: "EBF-233"
    },
  },
});
```

{% endcode %}

To update it later, once Birdie is ready:

{% code title="Update metadata later" %}

```javascript
birdie.update({ metadata: { status: { id: "123", label: "active", color: "#000000" } } })
```

{% endcode %}
{% endtab %}

{% tab title="Paste in the <head>" %}
Set it in `window.birdieSettings` before the snippet loads:

{% code title="Before the snippet" %}

```javascript
window.birdieSettings = {
    contact_email: "john.doe@acme.com", // required to get logs
    metadata: {
        mykey: "value",
        otherkey: [
            { x: 12, y: 13 },
            { opacity: 35, width: 440 }
        ]
    }
}
```

{% endcode %}

Or set it after the snippet loads:

{% code title="After the snippet" %}

```javascript
if (window.birdie) {
    window.birdie.metadata = {
        mykey: "value",
        otherkey: [
            { x: 12, y: 13 },
            { opacity: 35, width: 440 }
        ]
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

If several tabs have the snippet loaded, only the latest metadata set is attached to a recording.

</details>

<details>

<summary>How to hook into recorder events</summary>

Know when a recording starts and stops, for example to add metadata at that moment.

{% tabs %}
{% tab title="npm or yarn" %}
{% code title="Listen to recording events" %}

```javascript
initBirdie({
  clientId: "YOUR_CLIENT_ID",
  contact: { email: "alex@empire.com" }, // required to get logs
  onReady(birdie) {
    birdie.on("start", (data) => {
      console.log("Recording started", data);
      birdie.metadata = { dynamicKey: "value" };
    });

    birdie.on("stop", (data) => {
      console.log("Recording stopped", data);
    });
  },
});
```

{% endcode %}
{% endtab %}

{% tab title="Paste in the <head>" %}
Register `onBirdieReady` before loading the snippet, so `window.birdie` is available, then listen for `start` and `stop`:

{% code title="Before the snippet" %}

```javascript
window.birdieReadyCallback = function() {
  console.log("Birdie Ready, window.birdie object is now available")
  window.birdie.on('start', function(data) {
    console.log("A recording was started", data);
    // save custom data, or add metadata
    window.birdie.metadata = { key: "value" }
  });
  window.birdie.on('stop', function(data) {
    console.log("A recording was stopped", data);
  });
}

window.birdieSettings = {
  contact_email: "john.doe@acme.com", // required to get logs
  onBirdieReady: birdieReadyCallback
}

// then add the snippet…
```

{% endcode %}
{% endtab %}
{% endtabs %}

</details>

{% hint style="success" %}
Need help? Contact us at <support@birdie.so>
{% endhint %}
