Set up a custom domain proxy in Segment

Custom Domains allow you to proxy Analytics.js and proxy all tracking event requests through your domain.

Getting Started

In order to get started using custom domains, you will need:

  1. Access to your site DNS settings
  2. A CDN you’re using to serve assets from
  3. Access to the CDN settings

This guide will go through how to setup a custom domain in Cloudfront. The same principles can be applied to virtually any modern CDN that supports proxying.

You will need to setup two key pieces, regardless of the CDN provider you’re using:

  1. Proxy to Segment CDN (cdn.segment.com)
  2. Proxy to Segment tracking API (api.segment.io)

Setup

Follow the directions listed for Cloudfront or use your own CDN setup. Once you have completed those steps and have verified that your proxy is working for both cdn.segment.com and api.segment.io, email us with the following template email:

Hi,

This is {person} from {company}. I would like to request a proxy be added for the following source(s) to point to the corresponding proxy url:

* Source {link to source in Segment} with source ID {source id} should point to {api host}
* Source {link to source in Segment} with source ID {source id} should point to {api host}

Please double check the source link, the Source ID and the api host to ensure they are correct. A member of our Success team will respond and setup the proxy for you.

Cloudfront

CDN Proxy

You will need to first login to AWS and navigate to CloudFront.

Click “Create Distribution”

Here, you will need to select a delivery method for your content. Select the “Get Started” button in the “Web” section.

Now we’ll need to configure our distribution settings. Under origin settings, you will need to update the following values:

Field Value Description
Origin Domain Name cdn.segment.com The domain name you would like the proxy to be served to
Origin ID (optional) The Segment CDN A Description of the origin. This can be anything you would like that describes the origin domain name.
Origin Protocol Policy Set to HTTPS Only
Alternate Domain Names (CNAMEs) yourdomain.com Add the domain you are proxying to segment here. If you don’t do this you will get an error.

Next, you’ll want to configure the Default Cache Behavior Settings.

Field Value Description
Viewer Protocol Policy Redirect HTTP to HTTPS Ensure that all traffic goes through HTTPS
Allowed HTTP Methods GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE Select which HTTP methods are allowed to be proxied.
Forward Cookies All Ensure that cookies are forwarded on.
Query String Forwarding and Caching Forward all, cache based on all Ensure that all query string values are forwarded and properly cached.

Click “Create Distribution” at the bottom of the page. This distribution will show as “In Progress” until the distribution is deployed.

We’ll need the “Domain Name” for the next step so keep this browser window open.

Add CNAME Record to DNS Next, we’ll need to add a CNAME record to your DNS settings. Go to your domain registrar and add a new record to your DNS of type “CNAME”.

Field Value
Name {subdomain_name}.yourdomain.com
Value Cloudfront Distribution Domain Name

Save your record. Depending on the TTL you have set, it may take some time to take effect. Try curling your domain to ensure it’s proxying correctly.

Tracking API Proxy

Next, we’re going to setup a proxy for the tracking API so that all calls will be proxied through your domain. We’re going to setup a Cloudfront distribution that’s very similar to the previous step with a few minor changes:

Field Value Description
Origin Domain Name api.segment.io The domain name you would like the proxy to be served to

Add CNAME Record to DNS Next, we’ll need to add a CNAME record to your DNS settings. Go to your domain registrar and add a new record to your DNS of type “CNAME”. This time we’ll be using the Cloudfront distribution for the tracking API proxy.

Field Value
Name {subdomain_name}.yourdomain.com
Value Tracking API Cloudfront Distribution Domain Name

Save your record. Depending on the TTL you have set, it may take some time to take effect. Try curling your domain to ensure it’s proxying correctly.


Get started with Segment

Segment is the easiest way to integrate your websites & mobile apps data to over 300 analytics and growth tools.
or
Create free account