Skip to content

Commit 90cd1b0

Browse files
authored
Merge pull request #5896 from segmentio/add-self-hosted-ajs
Clarify self-hosted ajs and add more links.
2 parents 4185b0a + 86757f1 commit 90cd1b0

File tree

1 file changed

+15
-4
lines changed
  • src/connections/sources/catalog/libraries/website/javascript

1 file changed

+15
-4
lines changed

src/connections/sources/catalog/libraries/website/javascript/custom-proxy.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,21 @@ To add a CNAME record to your DNS settings:
168168
4. Run `curl` on your domain to check if the proxy is working correctly.
169169

170170

171-
## Self Hosting Analytics.js
171+
## Self-hosting Analytics.js
172172

173-
Follow the instructions at [Using Analytics.js as an NPM Package](https://github.com/segmentio/analytics-next/tree/master/packages/browser#-using-as-an-npm-package), to host Analytics.js and eliminate the requirement of downloading it from the CDN file during every page load. This enables you to self-host/import the library itself.
173+
To reduce fetching assets from Segment's CDN, you can bundle Analytics.js with your own code.
174174

175-
> warning ""
176-
> Segment does not recommend self-hosting, as it requires that you configure integration settings individually and manually redeploy Analytics.js when there are changes to your settings. Self-hosting your own Analytics.js instead of using the CDN means that you lose the automatic downstream updates to your analytics when you make changes. Self-hosting means that you must configure the settings for each integration directly and redeploy your Analytics.js any time you make changes to your settings. When you enable third-party libraries in device-mode, Segment loads them for you, which defeats the purpose of self-hosting.
175+
To bundle Analytics.js with your own code, you can:
176+
* [Use Analytics.js as an npm package](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2b-install-segment-as-a-npm-package).
177+
178+
* [Use npm to install your destinations](/docs/connections/sources/catalog/libraries/website/javascript/#add-destinations-from-npm).
177179

180+
* Hardcode your settings instead of fetching from the CDN (Segment doesn't recommend this as it completely bypasses the Segment source GUI).
181+
```ts
182+
// npm-only
183+
export const analytics = new AnalyticsBrowser()
184+
analytics.load({
185+
...
186+
cdnSettings: {...} // object from https://cdn.segment.com/v1/projects/<YOUR_WRITE_KEY>/settings'
187+
})
188+
```

0 commit comments

Comments
 (0)