RudderStack JavaScript SDK (Deprecated)

2.52.11 · deprecated · verified Sun Apr 19

The `rudder-sdk-js` package is the original JavaScript SDK for RudderStack, a customer data platform. It enables tracking of customer event data from websites and sending it to various destinations via the RudderStack platform. The current stable version observed in the npm metadata is `2.52.11`. However, this specific package is explicitly marked as *deprecated* and is no longer actively maintained. Users are strongly recommended to migrate to the newer `@rudderstack/analytics-js` package for continued support, enhanced features, and security updates. This SDK allowed for identifying users, tracking actions, and managing event readiness through a global `rudderanalytics` object. Its primary differentiator was providing a unified API for sending data to multiple analytics and marketing tools, acting as a server-side customer data router.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the deprecated RudderStack JavaScript SDK via a script tag and track a product view event after it's ready, along with user identification.

<html>
<head>
  <title>RudderStack Deprecated SDK Quickstart</title>
  <script type="text/javascript">
    !function(){var e=window.rudderanalytics=window.rudderanalytics||[];e.methods=["load","page","track","identify","alias","group","ready","reset","getAnonymousId","setAnonymousId"],e.factory=function(t){return function(){var n=Array.prototype.slice.call(arguments);n.unshift(t);e.push(n);return e}};for(var t=0;t<e.methods.length;t++){var n=e.methods[t];e[n]=e.factory(n)}e.load=function(t,n){var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.rudderlabs.com/rudder-analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);e._writeKey=t;e._options=n};}();

    // Initialize RudderStack (replace with your actual keys)
    rudderanalytics.load('YOUR_WRITE_KEY', 'YOUR_DATAPLANE_URL');

    rudderanalytics.ready(function() {
      console.log('RudderStack SDK is ready!');
      rudderanalytics.track('Product Viewed', {
        productId: 'RS-123',
        productName: 'Example Product',
        category: 'Electronics'
      });
      rudderanalytics.identify('user-123', {
        email: 'test@example.com',
        plan: 'premium'
      });
    });
  </script>
</head>
<body>
  <h1>Welcome to the website!</h1>
  <button onclick="rudderanalytics.track('Button Clicked', { buttonName: 'Test' })">Click Me</button>
  <p>Check your browser console and network requests for RudderStack events.</p>
</body>
</html>

view raw JSON →