RudderTyper
Detailed technical documentation on RudderTyper - focusing on the supported commands, configuration reference, and using it with your app.
RudderTyper is a tool that lets you generate strongly-typed RudderStack analytics library wrappers based on your Tracking Plan spec.
Simply put, it uses an event from your specified tracking plan and generates an analytics call in the supported languages.
RudderTyper currently generates native clients for the JavaScript, Node.js, Android, and iOS SDKs.

Key Features

Some key features of RudderTyper are:
    Allows you to contextualize your analytics instrumentation and validate it with your event spec, before deploying to production.
    You can access and validate your event names, properties, types, etc.
    It provides compile-time errors and warns you about any missing required properties, data mismatch, and any issues in the JSON schema configured in your tracking plan.
This feature is currently in a closed beta. If you're interested, please contact your account representative for more information.

Get Started

To fire up a quick start wizard to create a ruddertyper.yml and generate your first client with the specified configuration details, run the following command:
1
$ npx rudder-typer init | initialize | quickstart
Copied!

Other Commands

Update

1
$ npx rudder-typer update | u | * (default)
Copied!
This command syncs plan.json with RudderStack to pull the latest changes in your tracking plan and then generates an updated development client.

Build

1
$ npx rudder-typer build | b | d | dev | development
Copied!
This command generates a development client from plan.json.

Production

1
$ npx rudder-typer prod | p | production
Copied!
This command generates a production client from plan.json.

Token

1
$ npx rudder-typer token | tokens | t
Copied!
This command prints the local RudderStack API token configuration.

Version

1
$ npx rudder-typer version
Copied!
This command prints the RudderTyper CLI version.

Help

1
$ npx rudder-typer help
Copied!
This command prints the help message describing different commands available with RudderTyper.

CLI Arguments

Argument
Type
Description
config
string
An optional path to a ruddertyper.yml (or a directory with ruddertyper.yml).
debug
boolean
An optional (hidden) flag for enabling Ink debug mode.
version
boolean
Standard --version flag to print the version of this CLI.
v
boolean
Standard -v flag to print the version of this CLI.
help
boolean
Standard --help flag to print help on a command.
h
boolean
Standard -h flag to print help on a command.

Configuration Reference

RudderTyper stores its configuration in a ruddertyper.yml file in the root of your repository.
A sample configuration looks like the following:
1
# RudderStack RudderTyper Configuration Reference (https://github.com/rudderlabs/rudder-typer)
2
# Just run `npx rudder-typer` to re-generate a client with the latest versions of these events.
3
4
scripts:
5
# You can supply a RudderStack API token using a `script.token` command. The output of `script.token` command should be a valid RudderStack API token.
6
token: source .env; echo $RUDDERTYPER_TOKEN
7
# You can supply email address linked to your workspace using a `script.email` command.The output of `script.email` command should be an email address registered with your workspace.
8
email: source .env: echo $EMAIL
9
# You can format any of RudderTyper's auto-generated files using a `script.after` command.
10
# See `Formatting Generated Files` below.
11
after: ./node_modules/.bin/prettier --write analytics/plan.json
12
13
client:
14
# Which RudderStack SDK you are generating for.
15
# Valid values: analytics.js, analytics-node, analytics-ios, analytics-android.
16
sdk: analytics-node
17
# The target language for your RudderTyper client.
18
# Valid values: javascript, java, objective-c, swift.
19
language: javascript
20
# Javascript Transpilation Settings
21
# Valid values: 'ES3','ES5','ES2015','ES2016','ES2017','ES2018','ES2019','ESNext','Latest'
22
scriptTarget: 'ES6'
23
# Valid values: 'CommonJS','AMD','UMD','System','ES2015','ESNext'
24
moduleTarget: 'ESNext'
25
26
trackingPlans:
27
# The RudderStack Tracking Plan that you are generating a client for.
28
# Provide your workspace slug and Tracking Plan id
29
# You also need to supply a path to a directory to save your RudderTyper client.
30
- id: rs_QhWHOgp7xg8wkYxilH3scd2uRID
31
workspaceSlug: rudderstack-demo
32
path: ./analytics
Copied!

How to integrate RudderTyper-generated client with your app?

This section includes steps to integrate your RudderTyper-generated client with your app across different RudderStack SDKs.

RudderStack Android SDK

    Import all the files in the client generated by RudderTyper as a package in your project.
    Then, you can directly make the calls using the RudderTyper client as shown below:
1
// Import your auto-generated RudderTyper client:
2
import com.rudderstack.generated.*
3
4
// Issue your first RudderTyper track call!
5
RudderTyperAnalytics.with(this).orderCompleted(
6
OrderCompleted.Builder()
7
.orderID("ck-f306fe0e-cc21-445a-9caa-08245a9aa52c")
8
.total(39.99)
9
.build()
10
);
Copied!

RudderStack iOS SDK

    Import your RudderTyper client into your project using XCode.
Note: If you place your generated files into a folder in your project, import the project as a group not a folder reference.
    Then, you can directly make the calls using the RudderTyper client as shown:
1
// Import your auto-generated RudderTyper client:
2
#import "RSRudderTyperAnalytics.h"
3
4
// Issue your first RudderTyper track call!
5
[RSRudderTyperAnalytics orderCompletedWithOrderID: "ck-f306fe0e-cc21-445a-9caa-08245a9aa52c" total: @39.99];
Copied!

RudderStack JavaScript SDK

    Import the RudderTyper-generated client using require() and make the calls if your framework supports them. Otherwise, you can use Browserify to generate a bundle that supports your implementation. The implementation for each of the alternatives mentioned above will be as shown:

Using the require()method

1
// Import RudderStack JS SDK and initialize it
2
const rudderanalytics = require("rudder-sdk-js")
3
rudderanalytics.load(YOUR_WRITE_KEY, DATA_PLANE_URL)
4
// Import your auto-generated RudderTyper client:
5
const rudderTyper = require('./rudderTyperClient')
6
// Pass in your rudder-sdk-js instance to RudderTyper client
7
rudderTyper.setRudderTyperOptions({
8
analytics: rudderanalytics
9
});
10
// Issue your first RudderTyper track call!
11
rudderTyper.orderCompleted({
12
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
13
total: 39.99
14
})
Copied!

Using browserify

    Execute the following command to generate a bundle from the RudderTyper client:
1
browserify rudderTyperClient.js --standalone rudderTyper > rudderTyperBundle.js
Copied!
    Now you can make calls from your html file as shown:
1
<head>
2
<script>
3
rudderanalytics = window.rudderanalytics = [];
4
var methods = ["load", "page", "track", "identify", "alias", "group", "ready", "reset", "getAnonymousId", "setAnonymousId"];
5
for (var i = 0; i < methods.length; i++) {
6
var method = methods[i];
7
rudderanalytics[method] = function(methodName) {
8
return function() {
9
rudderanalytics.push([methodName].concat(Array.prototype.slice.call(arguments)));
10
};
11
}(method);
12
}
13
rudderanalytics.load(YOUR_WRITE_KEY, DATA_PLANE_URL);
14
rudderanalytics.page();
15
</script>
16
<script src="https://cdn.rudderlabs.com/v1/rudder-analytics.min.js"></script>
17
<script src="./rudderTyperBundle.js"></script>
18
<meta charset="UTF-8">
19
<meta http-equiv="X-UA-Compatible" content="IE=edge">
20
<meta name="viewport" content="width=device-width, initial-scale=1.0">
21
<title>Document</title>
22
</head>
23
<script>
24
rudderTyper.setRudderTyperOptions({
25
analytics: rudderanalytics
26
});
27
rudderTyper.orderCompleted({
28
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
29
total: 39.99
30
})
31
</script>
Copied!

RudderStack Node.js SDK

    Import the the RudderTyper-generated client and start making calls using RudderTyper as shown:
1
// Import Rudder Node SDK and intialize it
2
const Analytics = require("@rudderstack/rudder-sdk-node");
3
const client = new Analytics(WRITE_KEY, DATA_PLANE_URL / v1 / batch);
4
const ruddertyper = require("./rudderTyperClient");
5
// Pass in your rudder-sdk-node instance to RudderTyper.
6
ruddertyper.setRudderTyperOptions({
7
analytics: client
8
});
9
// Issue your first RudderTyper track call!
10
ruddertyper.orderCompleted({
11
orderID: 'ck-f306fe0e-cc21-445a-9caa-08245a9aa52c',
12
total: 39.99
13
})
Copied!

Contribute

    To submit a bug report or feature request, file an issue here.
    To develop on ruddertyper or propose support for a new language, see our contributors documentation.

Contact Us

For queries on any of the sections in this guide, start a conversation on our Slack channel.
Last modified 3mo ago