Skip to content

Update custom-proxy.md #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ You need to set up two important parts, regardless of the CDN provider you use:

## Set up

Follow the directions listed for CloudFront or use your own CDN setup. Once you complete those steps and verify that your proxy works for both `cdn.segment.com` and `api.segment.io`, [contact Segment Product Support](https://segment.com/help/contact/) with the following template email:
There are 2 options you can choose from when you set up your custom domain proxy.
1. [CloudFront](#cloudfront)
2. [Custom CDN or API proxy](#custom-cdn--api-proxy)

Follow the directions listed for [CloudFront](#cloudfront) or [use your own CDN setup](#custom-cdn--api-proxy). Once you complete those steps and verify that your proxy works for both `cdn.segment.com` and `api.segment.io`, [contact Segment Product Support](https://segment.com/help/contact/) with the following template email:

```text
Hi,
Expand All @@ -51,6 +55,58 @@ A Segment Customer Success team member will respond that they have enabled this
> info ""
> The **Host Address** field does not appear in source settings until it's enabled by Segment Customer Success.


## Custom CDN / API Proxy

### Snippet instructions
If you're a snippet user, you need to modify the [analytics snippet](/docs/getting-started/02-simple-install/#step-1-copy-the-snippet) that's inside your `<head>`.

To proxy settings and destination requests that typically go to `http://cdn.segment.com`, replace:
```diff
- t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js"
+ t.src="https://MY-CUSTOM-CDN-PROXY.com" + key + "/analytics.min.js"
```

To proxy tracking calls that typically go to `api.segment.io/v1`, replace:
```diff
- analytics.load("<MY_WRITE_KEY>")
+ analytics.load("<MY_WRITE_KEY>", { integrations: { "Segment.io": { apiHost: "MY-CUSTOM-API-PROXY.com" }}})
```

### npm instructions
See the [`npm` library-users instructions](https://www.npmjs.com/package/@segment/analytics-next){:target="_blank"} for more information.

Proxy settings and destination requests that typically go to `http://cdn.segment.com` through a custom proxy.

```ts
const analytics = AnalyticsBrowser.load({
writeKey,
// GET http://cdn.segment.com/v1/projects/<writekey>/settings ->
// https://MY-CUSTOM-CDN-PROXY.com/v1/project/<writekey>/settings
// GET https://cdn.segment.com/next-integrations/actions/...js ->
// https://MY-CUSTOM-CDN-PROXY.com/next-integrations/actions/...js
cdnURL: 'https://MY-CUSTOM-CDN-PROXY.com'
})
```

Proxy tracking calls that typically go to `api.segment.io/v1` by configuring `integrations['Segment.io'].apiHost`.
```ts
const analytics = AnalyticsBrowser.load(
{
writeKey,
cdnURL: 'https://MY-CUSTOM-CDN-PROXY.com'
},
{
integrations: {
'Segment.io': {
// POST https://api.segment.io/v1/t -> https://MY-CUSTOM-API-PROXY.com/t
apiHost: 'MY-CUSTOM-API-PROXY.com' // omit the protocol (http/https) e.g. "api.segment.io/v1" rather than "https://api.segment.io/v1"
}
}
}
)
```

## CloudFront

These instructions refer to Amazon CloudFront, but apply more generally to other providers as well.
Expand Down