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 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:
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
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/ruddertyper
Tip:
Put the generated code depending on your application’s structure.
Generally, developers put the generated code under build/generated/source directories, 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 =.
The 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:
importcom.rudderstack.ruddertyper.RudderAnalyticsimportcom.rudderstack.sdk.kotlin.android.Analyticsimportcom.rudderstack.sdk.kotlin.android.Configuration// Example setup of the SDK
valconfiguration=Configuration(writeKey=BuildConfig.WRITE_KEY,application=this,dataPlaneUrl=BuildConfig.DATA_PLANE_URL,flushPolicies=listOf(CountFlushPolicy(1)))analytics=Analytics(configuration)// Setup of RudderTyper bindings
valtyper=com.rudderstack.ruddertyper.RudderAnalytics(analytics)
importRudderStackAnalytics// Example setup of the SDKletconfig=Configuration(writeKey:"<WRITE_KEY>",dataPlaneUrl:"<DATA_PLANE_URL>")letanalytics=Analytics(configuration:config)// Setup of RudderTyper bindingsletrudderTyper=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 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:
typer.trackUserLogin(properties=TrackUserLoginProperties(// ... properties defined in your Tracking Plan
))
rudderTyper.trackUserLogin(properties:TrackUserLoginProperties(// ... properties defined in your Tracking Plan))
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
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.