# Send Events via Custom Domains

This guide covers the steps to use your own domain instead of the RudderStack domains for sending events to the RudderStack backend (data plane).

## Setup overview

Usually, all tracked events are sent to RudderStack via your data plane URL. To have events routed through your own domain, you need to set up a proxy and then use it as the data plane URL while initializing the SDK.

Create a new distribution by following these steps:

1. Log in to your [AWS console](https://aws.amazon.com/console/).
2. Click **Services** and go to **Network & Content Delivery** > **CloudFront**.
3. Click **Create a CloudFront distribution**.

The following table gives a high-level overview of the required cache policy, origin request policy, and response headers policy for routing the events through your own domain:

| Cache policy | Origin request policy | Response headers policy (optional) |
| :------| :--------| :----------- | 
| `CachingDisabled` | [Origin request policy settings](#event-origin-request-policy-settings) | `CORS-With-Preflight` | 

## Step 1: Configure distribution

{{< image src="images/user-guides/custom-domains/send-events-distribution-settings.webp" alt="Custom domains distribution settings" >}}

The following sections highlight the required distribution settings:

#### Origin

| Field | Setting              |
| :--------------------- | :------------------- |
| Origin domain     | `DATA_PLANE_URL` |
| Protocol | `HTTPS Only`           |
| HTTPS port | `443` |
| Minimum origin SSL protocol | `TLSv1.2` |
| Name | `<YOUR_ORIGIN_NAME>` |
| Enable Origin Shield | `No` |

#### Default cache behavior settings

{{< image src="images/user-guides/custom-domains/custom-domains-2-new.webp" alt="Custom domains distribution settings" >}}

| Field     | Setting                 |
| :---------- | :---------------------- |
| Compress objects automatically | `Yes` |
| Viewer protocol policy              | `Redirect HTTP to HTTPS`                                     |
| Allowed HTTP methods                | `GET`, `HEAD`, `OPTIONS`, `PUT`, `POST`, `PATCH`, `DELETE` |
| Restrict viewer access | `No` |

#### Cache key and origin requests

Select **Cache policy and origin request policy (recommended)** and configure the following settings:

{{< image src="images/user-guides/custom-domains/custom-domains-sending-events-1.webp" alt="Cache and origin request policy" >}}

| Field | Setting |
| :------| :------|
| Cache policy | `CachingDisabled` |
| Origin request policy | See [Origin request policy settings](#event-origin-request-policy-settings). | 
| Response headers policy | `CORS-With-Preflight` |

#### Origin request policy settings {#event-origin-request-policy-settings}

Create a new origin request policy with the following settings:

{{< image src="images/user-guides/custom-domains/custom-domains-origin-request-policy.webp" alt="Origin request policy settings" >}}

| Field       | Setting |
| :------- | :------------------- |
| Name | `rudderstack-allow-headers` | 
| Headers | `Include the following headers` | 
| Add header | <ul><li>`Access-Control-Request-Headers`</li><li>`Access-Control-Request-Method`</li><li>`Origin`</li><li>`Content-Encoding`</li></ul> |
| Query strings | `All` |
| Cookies | `None` |

#### Additional distribution settings

{{< customreadfile "/includes/custom-domains/additional-distribution-settings.md" >}}

## Step 2: Deploy distribution

{{< customreadfile "/includes/custom-domains/deploy-distribution.md" >}}

##  Step 3: Send events

Once the setup and DNS propagation is completed, you can use the newly created URL as the data plane URL when initializing the SDK:

Before:

```javascript
rudderanalytics.load( 
  WRITE_KEY ,
  DATA_PLANE_URL
)
```

After:

```javascript
rudderanalytics.load(
  WRITE_KEY,
  "https://<YOUR_CUSTOM_DOMAIN>"
)
```

{{< warning >}}
Make sure that the events are routed through your own domain and not the `rudderstack.com` domain in the network tab of your browser console.

See [JavaScript SDK FAQ]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/faq.md#how-can-i-verify-if-the-sdk-is-sending-data-to-the-specified-destinations" >}}) for more information.
{{< /warning >}}

## Use custom SSL certificates

{{< customreadfile "/includes/custom-domains/custom-ssl-certificates.md" >}}

## Custom request header for GCP external load balancer

{{< customreadfile "/includes/custom-domains/gcp-load-balancer.md" >}}

