Git Product home page Git Product logo

rudder-sdk-js's Introduction

What is RudderStack?

Rudder is an enterprise-ready, open-source alternative to Segment, for collecting and routing customer event data. More information on Rudder can be found here.

What is the RudderStack JavaScript SDK?

The RudderStack JavaScript SDK (released under Apache License 2.0) allows you to utilize our rudder-analytics.js library to start sending event data from your website to RudderStack. After integrating this SDK, you will also be able to connect to multiple destinations such as Amplitude, Google Analytics, etc. to send the data.

How to use the RudderStack JavaScript SDK?

This Quick Start Guide will help you get up and running with using the RudderStack JavaScript SDK in no time. You just need to follow the steps below:

Step 1: Install RudderStack using the code snippet

To integrate the SDK, place the following code snippet in the <head> section of your website.

You can use either the minified or non-minified version of the code:

The minified version is as follows:

<script> 
rudderanalytics=window.rudderanalytics=[];for(var methods=["load","page","track","identify","reset"],i=0;i<methods.length;i++){var method=methods[i];rudderanalytics[method]=function(d){return function(){rudderanalytics.push([d,...arguments])}}(method)}rudderanalytics.load("YOUR_WRITE_KEY","DATA_PLANE_URI"),rudderanalytics.page();
</script>

<script  src="https://cdn.rudderlabs.com/rudder-analytics.min.js"></script>

The non-minified version of the code is shown below:

<script>
	rudderanalytics = window.rudderanalytics = [];
	
	var  methods = [
		"load",
		"page",
		"track",
		"identify",
		"reset"
	];

	for (var i = 0; i < methods.length; i++) {
  		var method = methods[i];
  		rudderanalytics[method] = function (methodName) {
    			return function () {
      				rudderanalytics.push([methodName].concat(Array.prototype.slice.call(arguments)));
    			};
  			}(method);
	}
	rudderanalytics.load("YOUR_WRITE_KEY", "DATA_PLANE_URI");
	//For example,
	//rudderanalytics.load("1Qb1F3jSWv0eKFBPZcrM7ypgjVo", "http://localhost:8080");
	rudderanalytics.page();
</script>

<script  src="https://cdn.rudderlabs.com/rudder-analytics.min.js"></script>

NOTE: Whichever version of the code you use, you need to replace YOUR_WRITE_KEY with the write key in the RudderStack Control Plane and DATA_PLANE_URI with the URI of the RudderStack Server/ Data Plane.

Step 2: Identify your users using the identify() method:

The identify() method allows you to link users and their actions to a specific userid.

A sample example of how the identify() method works is as shown:

rudderanalytics.identify(
      "12345",
      { email: "[email protected]" },
      {
        context: {
          ip: "0.0.0.0"
        },
        page: {
          path: "",
          referrer: "",
          search: "",
          title: "",
          url: ""
        },
        anonymousId: "12345" 
      },
  () => {console.log("in identify call");}
);

In the above example, information such as the user ID, email along with contextual information such as IP address, anonymousId, etc. will be captured.

NOTE: There is no need to call identify() for anonymous visitors to your website. Such visitors are automatically assigned an anonymousId.

Step 3: Track your users’ actions using the track() method

The track() method allows you to track any actions that your users might perform.

A sample example of how the track() method works is as shown:

rudderanalytics.track(
  "test track event GA3",
  {
    revenue:  30,
    currency:  'USD' ,
    user_actual_id:  12345
  },
  {
    context: {
      ip:  "0.0.0.0"
    },
    anonymousId:  "00000000000000000000000000"
  }, 
  () => {console.log("in track call");}
);

In the above example, the method tracks the event ‘test track event GA3’, information such as the revenue, currently, user ID and other contextual information such as IP address.

You can use this method to track various other success metrics for your website, such as user signups, item purchases, article bookmarks, and much more.

And we’re done! You’ve successfully installed rudder-analytics.js tracking. Now you can enable and use any event destination to send your processed event data that you want, in no time at all.

For a detailed technical documentation and troubleshooting guide on the RudderStack’s JavaScript SDK, click here.

Contribute

You can start adding integrations of your choice for sending data through their JavaScript SDKs.

How to build the SDK

  1. Look for run scripts in the package.json file for getting browser minified and non-minified builds
  2. For adding or removing integrations, modify the imports in index.js under integrations folder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.