End-to-End Walkthrough: RudderTyper v2 with Rudder CLI Beta
- free
- growth
- enterprise
4 minute read
This tutorial shows you how to use RudderTyper v2 via the Rudder CLI tool to:
- Generate type-safe TypeScript, Kotlin, or Swift bindings from your Tracking Plans
- Install the generated bindings in your web (JavaScript), Android, JVM, or iOS application
- Customize the generated code with platform-specific options
- Instrument your application using the generated bindings
Prerequisites
- Rudder CLI tool (
rudder-cli) installed locally - A workspace-level Service Access Token or Personal Access Token with read access to the Tracking Plan you want to use
- An existing Tracking Plan in your RudderStack workspace
1. Authenticate Rudder CLI
Run the following command and enter your access token when prompted:
rudder-cli auth login2. Identify your Tracking Plan ID
To generate type-safe bindings, first identify the Tracking Plan you want to generate bindings against. Run the following command:
rudder-cli workspace tracking-plans listThe above command displays an interactive table with all available Tracking Plans in your workspace. The output shows a list of Tracking Plans on the left, and selecting a Tracking Plan displays its details on the right, including the plan’s name, description, and current version.
Use this information to identify the Tracking Plan you want to use and copy its ID, as highlighted below:

Navigate using the arrow keys if you have more Tracking Plans than what can be displayed, and exit the view by pressing the Escape key.
3. Generate bindings
Using the Tracking Plan ID, run the following command for your target platform:
rudder-cli typer generate --platform=typescript --tracking-plan-id=<TRACKING_PLAN_ID> -o <OUTPUT_DIRECTORY>rudder-cli typer generate --platform=kotlin --tracking-plan-id=<TRACKING_PLAN_ID> -o <OUTPUT_DIRECTORY>rudder-cli typer generate --platform=swift --tracking-plan-id=<TRACKING_PLAN_ID> -o <OUTPUT_DIRECTORY>The above command generates bindings for the platform indicated by the --platform flag (typescript, kotlin, or swift), for the Tracking Plan indicated by the --tracking-plan-id flag, and stores the generated files in the directory indicated by the -o flag.
Note that:
--platformand--tracking-plan-idare required flags-ois optional and defaults to the current working directory if omitted- You can view all available options by running
rudder-cli typer generate -h
See the RudderTyper v2 Command Reference for more information on the above command and the supported flags.
4. Install bindings in your application
RudderTyper generates a single RudderTyper.ts file. Add this file to your application’s source directory and import the generated RudderTyper class where you instrument events.
The generated code depends on the RudderStack JavaScript SDK (@rudderstack/analytics-js), which your application should already be configured to use. If you haven’t set up the SDK yet, follow the steps in the JavaScript SDK documentation.
Copy the generated files to a location of your choice inside your application’s source directory. Typically, this should be in a structure that mimics the generated code’s package name.
By default, the package name is com.rudderstack.ruddertyper, which means the code should be copied to a directory that looks like below:
src/main/kotlin/com/rudderstack/ruddertyperPlace the generated code based on your application’s structure.
Generally, developers put the generated code under
build/generated/sourcedirectories, which IDEs treat specifically as generated code that cannot be modified.
The generated code only has a dependency on the SDK library, which your application should already be configured to use, following the steps in the Android (Kotlin) SDK documentation.
RudderTyper generates a single RudderTyper.swift file. Add this file to your Xcode project or Swift Package by dragging it into your project navigator or including it in your target’s Compile Sources build phase.
The generated code depends on the RudderStack Swift SDK (RudderStackAnalytics), which your application should already be configured to use. If you haven’t set up the SDK yet, follow the steps in the iOS (Swift) SDK documentation.
5. Optional: Customize the generated code
Depending on the platform, RudderTyper supports platform-specific options that customize the generated code.
You can provide these options to the rudder-cli typer generate command using one or more --option flags that accept a key-value pair separated by =.
To view available options for your platform, run:
rudder-cli typer options --platform=typescriptThe TypeScript platform supports the following options:
| Option | Default | Description |
|---|---|---|
outputFileName | RudderTyper.ts | Name of the generated TypeScript file, for example, Events.ts |
For example, to generate bindings with a custom output file name:
rudder-cli typer generate --platform=typescript --tracking-plan-id=<TRACKING_PLAN_ID> --option outputFileName=Events.tsrudder-cli typer options --platform=kotlinThe above command gives an output like below:
>
<img src="/docs/images/dev-tools/ruddertyper-v2/quickstart-2.webp"
alt="Rudder CLI Kotlin platform options"decoding="async" loading="lazy" class="img-shortcode"/>
</a>
The Kotlin platform supports the following options:
| Option | Default | Description |
|---|---|---|
packageName | com.rudderstack.ruddertyper | Package name for the generated Kotlin code. |
outputFileName | Main.kt | Name of the generated Kotlin file, for example, MyEvents.kt |
composeImmutable | false | Annotates every generated data class with @androidx.compose.runtime.Immutable. Enable this if you use the generated types directly in Jetpack Compose UI trees. |
For example, to generate bindings with a custom package name:
rudder-cli typer generate --platform=kotlin --tracking-plan-id=<TRACKING_PLAN_ID> --option packageName=com.example.packageTo enable Compose @Immutable annotations:
rudder-cli typer generate --platform=kotlin --tracking-plan-id=<TRACKING_PLAN_ID> --option composeImmutable=trueEnablingcomposeImmutablerequiresandroidx.compose.runtimeon your module’s classpath. Any module that already uses Jetpack Compose has this dependency. If you enable this flag in a non-Compose module, the build fails with an unresolved reference.
rudder-cli typer options --platform=swiftThe Swift platform does not currently expose any platform-specific options. The generated code is output as a single RudderTyper.swift file.
6. Instrument your application
After installing the generated files in your application’s source folders, you can use them as a wrapper over the RudderStack SDK.
Assuming your SDK instance is initialized and available through a variable called analytics, instantiate and use the RudderTyper wrapper by passing the analytics object as an argument:
import { RudderAnalytics } from "@rudderstack/analytics-js";
import { RudderTyper } from "./RudderTyper";
// Example setup of the SDK
const analytics = new RudderAnalytics();
analytics.load("<WRITE_KEY>", "<DATA_PLANE_URL>");
// Setup of RudderTyper bindings
const typer = new RudderTyper(analytics);import com.rudderstack.ruddertyper.RudderAnalytics
import com.rudderstack.sdk.kotlin.android.Analytics
import com.rudderstack.sdk.kotlin.android.Configuration
// Example setup of the SDK
val configuration = Configuration(
writeKey = BuildConfig.WRITE_KEY,
application = this,
dataPlaneUrl = BuildConfig.DATA_PLANE_URL,
flushPolicies = listOf(
CountFlushPolicy(1)
)
)
analytics = Analytics(configuration)
// Setup of RudderTyper bindings
val typer = com.rudderstack.ruddertyper.RudderAnalytics(analytics)import RudderStackAnalytics
// Example setup of the SDK
let config = Configuration(
writeKey: "<WRITE_KEY>",
dataPlaneUrl: "<DATA_PLANE_URL>"
)
let analytics = Analytics(configuration: config)
// Setup of RudderTyper bindings
let rudderTyper = RudderTyperAnalytics(analytics: analytics)Use the generated bindings
The wrapper object exposes methods that correspond to the events in your Tracking Plan.
For identify, screen, and group event types added as rules to the Tracking Plan, the wrapper exposes methods with signatures identical to those exposed by the SDK, except with strongly typed properties or trait arguments. For TypeScript, which targets the web-based JavaScript SDK, the wrapper exposes a page method instead of screen.
For example, an identify event with a single name property added to its traits through the Tracking Plan:
typer.identify("1hKOmRA4GRlm", {
name: "Alex Keener"
})import com.rudderstack.ruddertyper.IdentifyTraits
typer.identify(
userId = "1hKOmRA4GRlm",
traits = IdentifyTraits(
name = "Alex Keener"
)
)rudderTyper.identify(
userId: "1hKOmRA4GRlm",
traits: IdentifyTraits(name: "Alex Keener")
)Similarly, track events added as rules in a Tracking Plan correspond to methods named with a track prefix followed by a CamelCase version of the event’s name. For example, you can send an event named User Login using:
typer.trackUserLogin({
// ... properties defined in your Tracking Plan
})typer.trackUserLogin(
properties = TrackUserLoginProperties(
// ... properties defined in your Tracking Plan
)
)rudderTyper.trackUserLogin(
properties: TrackUserLoginProperties(
// ... properties defined in your Tracking Plan
)
)Next steps
- See the RudderTyper v2 Command Reference for detailed information about all available CLI commands and parameters
- See the Limitations section for more information on the limitations of the generated bindings