Migrate the RudderStack JavaScript SDK from v1 to v1.1.
4 minute read
The latest JavaScript SDK (v1.1) is the lightweight, efficient, and optimized version of the SDK with a size reduction of approximately 70%, thereby increasing its loading speed considerably.
Another significant improvement in the latest version (v1.1) is that the device mode destinations are published as individual plugins and loaded dynamically as per the dashboard configurations. In v1, device mode destinations were bundled with the core SDK.
Migrating to JavaScript SDK v1.1
If you have installed the JavaScript SDK v1 from the RudderStack CDN, you can simply upgrade it to v1.1 by updating the script tag in your website:
This section covers the detailed steps on migrating to JavaScript SDK v1.1 depending on how you installed JavaScript SDK v1.
Forwarded/proxied RudderStack CDN
Refer to the Custom Domains guide to use a custom domain to forward or proxy the JavaScript SDK hosted on the RudderStack CDN.
The following steps assume that you are using AWS CloudFront to forward or proxy the RudderStack CDN:
Go to Behaviors and verify that the sub-path /v1.1/* is not configured to be blocked in any way. This is required to ensure that both the core SDK and destination SDKs are forwarded properly.
In this structure, the filename for the JavaScript SDK is rudder-analytics.min.js and device mode destination SDKs are located next to the core SDK file under the js-integrations directory.
To migrate to v1.1 with this setup, update the script tag in your website:
If the filename of your self-hosted JavaScript SDK is rudder-analytics.min.js but the destination SDKs are not located next to the core SDK file under the js-integrations directory, update the script tag in your website:
<script>// rudderanalytics object initialization
// provide the location of the destination SDKs in the load options
rudderanalytics.load(WRITE_KEY,DATA_PLANE_URL,{destSDKBaseURL:"https://<subdomain>.<yourdomain>.com/<path-to-integration-sdks-directory>"});// ...
</script><scriptsrc="https://<subdomain>.<yourdomain>.com/<path-to-sdk-base-directory>rudder-analytics.min.js"></script>
Destination SDKs are located elsewhere, alternate filename for rudderanalytics
If your JavaScript SDK file name is notrudder-analytics.min.js, and the destination SDKs are not located under the js-integrations directory, update the script tag in your website as follows:
<script>// rudderanalytics object initialization
// provide the location of the destination SDKs in the load options
rudderanalytics.load(WRITE_KEY,DATA_PLANE_URL,{destSDKBaseURL:"https://<subdomain>.<yourdomain>.com/<path-to-integration-sdks-directory>"});// ...
</script><scriptsrc="https://<subdomain>.<yourdomain>.com/<path-to-custom-sdk-file>/<custom-sdk-file-name.js>"></script>
Using NPM
The latest NPM package is based on the JavaScript SDK v1.1 architecture and is released with the 2.x.x version.
To update the SDK package using NPM, use any of the following options:
Upgrade rudder-sdk-js package to v1.1 using the below command:
npminstallrudder-sdk-js@2.x.x
Manually modify the package.json file like below and run npm install:
In v1.1, the core JavaScript SDK does not contain any destination-specific SDKs by default. It fetches them dynamically from the hosted location, depending on the device mode destinations configured in your dashboard (control plane).
How does RudderStack determine the root location of the destination SDK?
RudderStack follows the below precedence order while determining the root location of the destination SDK:
It refers to the destSDKBaseURL value in the options parameter of the load API call.
If absent, it checks the src attribute of the <script> tag (that adds the core JavaScript SDK to your website) if /js-integrations is automatically appended to the root location.
If none of the above options are applicable, it uses the default CDN URL: https://cdn.rudderlabs.com/v1.1/js-integrations/.
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.