Use Custom Domains

Use your own domain to serve the RudderStack JavaScript SDK and send events to RudderStack.

This guide covers the steps to use your own domain instead of RudderStack domains for the following use cases:

Setting up custom domains for the above use cases can help you adhere to your Content Security Policy (CSP), reduce the impact of adblockers, and satisfy any compliance-related requirements.

info
The steps and examples in this guide are applicable for AWS CloudFront. However, the settings should be similar regardless of your CDN.

Setup overview

warning
You must have access to your domain’s DNS settings and your CDN settings.

Create a new distribution by following these steps:

  1. Log in to your AWS 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:

ScenarioCache policyOrigin request policyResponse headers policy (optional)
Serve the JavaScript SDKCachingOptimizedOrigin request policy settings.None
Serve source configurationSee Cache policy settingsSee Origin request policy settings.CORS-With-Preflight
Send events to data planeCachingDisabledSee Origin request policy settings.CORS-With-Preflight

Domains to proxy

The following table lists the three domains that you need to proxy via your own domain to successfully load the SDK and route the events to the RudderStack backend (data plane).

DomainUse case
cdn.rudderlabs.comTo load the JavaScript SDK.
api.rudderstack.comTo fetch the source configuration based on the source write key.
DATA_PLANE_URLTo send events to RudderStack. See the Dashboard Overview guide for more information on obtaining your data plane URL.

For each domain, you will need to create a CDN distribution and add a CNAME record in your domain for the distribution domain.

warning
To use your own domain for the above endpoints, you will need to route the traffic through your CDN for which you will incur charges.

FAQ

Can I overcome ad blockers by serving the JavaScript SDK on my domain?

Many popular ad blockers block specific SDK-related downloads and API calls based on the domain name and URL. You can serve the SDK on your CDN to circumvent this issue.



Questions? Contact us by email or on Slack