Steps on self-hosting and setting up the JavaScript SDK in your CDN.
3 minute read
This guide walks you through the steps to self-host the RudderStack JavaScript SDK and also covers different scenarios based on your directory structure.
Prerequisites
For self-hosting the JavaScript SDK, following the below directory structure (as present in RudderStack’s CDN) to place your SDK and the associated files is recommended:
In this structure, there should be two directories - modern and legacy - under the base directory. Place the following files and folders within these directories:
rsa.min.js and rsa.min.js.map: Core SDK file.
js-integrations: Device mode destination SDKs are located in this directory.
plugins: Plugins are located in this directory. Note that this is applicable only to the modern folder.
The SDK bundle in the modern directory is built for ES2015, while the legacy bundle is for ES5. Moreover, in the legacy version, all the plugins are bundled into the core SDK.
Download the required device mode destination SDK file along with the corresponding map file from the RudderStack CDN (https://cdn.rudderlabs.com/v3/modern/js-integrations). Place the below files in the js-integrations folder:
Download the following plugin files along with the corresponding map files from the RudderStack CDN (https://cdn.rudderlabs.com/v3/modern/plugins). Place the below files in the plugins folder:
rsa-plugins-remote-<plugin_name>.min.js
rsa-plugins-remote-<plugin_name>.min.js.map
rsa-plugins-<helper_name>.min.js
rsa-plugins-<helper_name>.min.js.map
You can get the complete list of plugins from the JavaScript SDK repository. The helper plugin names are listed below:
rsa-plugins-common.min.js
rsa-plugins-legacyEncryptionUtils.min.js
rsa-plugins-deviceModeDestinations.min.js
rsa-plugins-RetryQueue.min.js
Note that you cannot access the parent folders directly. Add the above file names to the parent folder path to access the specific file.
For example:
https://cdn.rudderlabs.com/v3/modern/js-integrations is inaccessible. However, https://cdn.rudderlabs.com/v3/modern/js-integrations/Amplitude.min.js is accessible.
https://cdn.rudderlabs.com/v3/modern/plugins is inaccessible. However, https://cdn.rudderlabs.com/v3/modern/plugins/rsa-plugins-remote-BeaconQueue.min.js is accessible.
Download and host the rsa.plugins.js file along with its .map file from the below URLs - this is the index file for all the plugins listed above.
If your JavaScript SDK file name is notrsa.min.js, then update sdkName in the loading snippet to:
varsdkName="<custom-file-name>.min.js";
Load device mode destinations and plugins
If you’ve installed the SDK via CDN and have retained the recommended directory and file structure, the SDK automatically determines the location of the device mode destinations and plugins.
Otherwise, provide location of the destination SDKs via the destSDKBaseURLload API option:
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.