Spec Version:

End-to-End Walkthrough: RudderTyper v2 with Rudder CLI Beta

Step-by-step tutorial to generate and use type-safe Kotlin or Swift bindings from your Tracking Plans.
Available Plans
  • starter
  • growth
  • enterprise

This tutorial shows you how to use RudderTyper v2 via the Rudder CLI tool to:

  • Generate type-safe Kotlin or Swift bindings from your Tracking Plans
  • Install the generated bindings in your Android, JVM, or iOS application
  • Customize the generated code with platform-specific options
  • Instrument your application using the generated bindings

Prerequisites

1. Authenticate Rudder CLI

Run the following command and enter your access token when prompted:

rudder-cli auth login

2. 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 list

The 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:

List of Tracking Plans in your workspace
tip
Tip: 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:

The above command generates bindings for the platform indicated by the --platform flag (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:

  • --platform and --tracking-plan-id are required flags
  • -o is 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 Command Reference for more information on the above command and the supported flags.

4. Install bindings in your application

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:

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:

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 example, an identify event with a single name property added to its traits through the Tracking Plan:

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:

Next steps

  • See the Limitations section for more information on the limitations of the generated bindings
  • See the Command Reference for detailed information about all available CLI commands and parameters

Questions? We're here to help.

Join the RudderStack Slack community or email us for support