Click the Minified or Unminified tab followed by Copy snippet.
Set asyncScript (highlighted below) to false.
varasyncScript=false;
Paste the modified script in your website’s <head> section.
Note that:
Depending on the browser, the SDK loads either the legacy or modern JavaScript SDK bundle. The legacy bundle is built for ES5 while the modern bundle (with Module Federation) is built for ES6.
You can also pass your loadOptions as a third argument in the rudderanalytics.load method. See Load JavaScript SDK for more information.
Using NPM
While it is recommended to install the JavaScript SDK on your website via CDN, you can also use the NPM module for packaging RudderStack directly into your project.
Use this NPM module only for browser applications. To integrate RudderStack with your Node.js apps, see the Node.js SDK documentation.
To install the JavaScript SDK via NPM, run the following command:
npm install @rudderstack/analytics-js --save
Run the following code snippet once and use the exported object throughout your project:
The JavaScript SDK provides the ready API with a callback that triggers when the SDK is done initializing itself and the other third-party destination SDKs.
You can make a page call to track the current web page and pass any additional information:
rudderanalytics.page("Cart","Cart Viewed",{path:"/best-seller/1",referrer:"https://www.google.com/search?q=estore+bestseller",search:"estore bestseller",title:"The best sellers offered by EStore",url:"https://www.estore.com/best-seller/1"},()=>{console.log("page call");});
Note that the above example highlights how to override and set custom values for path, referrer, search, title, and url. In reality, the SDK automatically captures these fields.
Single page applications
In the case of single-page applications (SPA) where a route change does not reload the page, you need to make the page call explicitly after the route change on the frontend.
The identify method lets you identify a user and associate them with their actions. It also enables you to record any traits about them like their name, email, etc.
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.