$npx -y skills add rudderlabs/rudder-agent-skills --skill rudder-typer-workflowGenerates type-safe SDKs (Swift/Kotlin) from tracking plans with compile-time validation. Use when generating type-safe event tracking code from tracking plans using RudderTyper
| 1 | # RudderTyper Workflow |
| 2 | |
| 3 | This skill teaches how to use **RudderTyper** to generate type-safe SDKs from your tracking plan, enabling compile-time validation of analytics calls. |
| 4 | |
| 5 | ## What is RudderTyper? |
| 6 | |
| 7 | RudderTyper generates native code from your tracking plan so developers: |
| 8 | - Get **compile-time validation** of event names and properties |
| 9 | - Have **autocomplete** for events and properties in their IDE |
| 10 | - Catch **instrumentation errors before runtime** |
| 11 | - See **documentation** from your tracking plan inline |
| 12 | |
| 13 | ``` |
| 14 | ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 15 | │ Tracking Plan │────▶│ RudderTyper │────▶│ Generated SDK │ |
| 16 | │ (YAML) │ │ (Generator) │ │ (Swift/Kotlin) │ |
| 17 | └─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 18 | │ |
| 19 | ▼ |
| 20 | ┌─────────────────┐ |
| 21 | │ Mobile App │ |
| 22 | │ (Type-safe!) │ |
| 23 | └─────────────────┘ |
| 24 | ``` |
| 25 | |
| 26 | ## Supported Platforms |
| 27 | |
| 28 | | Platform | Language | Status | Use Case | |
| 29 | |----------|----------|--------|----------| |
| 30 | | iOS | Swift | Available | iOS, macOS, tvOS, watchOS apps | |
| 31 | | Android | Kotlin | Available | Android apps, JVM applications | |
| 32 | | Web | TypeScript | Manual | Web apps, Node.js (see [TypeScript Type Alignment](#typescript-type-alignment-manual)) | |
| 33 | |
| 34 | ## Quick Start |
| 35 | |
| 36 | ### Step 1: Initialize RudderTyper |
| 37 | |
| 38 | ```bash |
| 39 | rudder-cli typer init |
| 40 | ``` |
| 41 | |
| 42 | Creates `ruddertyper.yml`: |
| 43 | |
| 44 | ```yaml |
| 45 | version: "1.0.0" |
| 46 | trackingPlan: |
| 47 | id: "tp_abc123" # Your tracking plan ID |
| 48 | workspace: "ws_xyz789" # Your workspace ID |
| 49 | language: kotlin # or "swift" |
| 50 | output: |
| 51 | path: ./generated # Where to generate code |
| 52 | ``` |
| 53 | |
| 54 | ### Step 2: Generate Code |
| 55 | |
| 56 | ```bash |
| 57 | rudder-cli typer generate |
| 58 | ``` |
| 59 | |
| 60 | ### Step 3: Integrate |
| 61 | |
| 62 | Add the generated directory to your project and import the Analytics class. |
| 63 | |
| 64 | ## Real-World Example: E-Commerce App |
| 65 | |
| 66 | ### Your Tracking Plan |
| 67 | |
| 68 | ```yaml |
| 69 | # tracking-plan.yaml |
| 70 | version: "rudder/v1" |
| 71 | kind: "tracking-plan" |
| 72 | metadata: |
| 73 | name: "tracking-plans" |
| 74 | spec: |
| 75 | name: "Mobile App Tracking Plan" |
| 76 | events: |
| 77 | - event: "urn:rudder:event/product-viewed" |
| 78 | - event: "urn:rudder:event/product-added-to-cart" |
| 79 | - event: "urn:rudder:event/order-completed" |
| 80 | ``` |
| 81 | |
| 82 | ### Generated Kotlin Code |
| 83 | |
| 84 | RudderTyper generates: |
| 85 | |
| 86 | ```kotlin |
| 87 | // generated/Analytics.kt |
| 88 | |
| 89 | /** |
| 90 | * User viewed a product detail page |
| 91 | */ |
| 92 | fun productViewed( |
| 93 | product: ProductType, |
| 94 | pageUrl: String? = null, |
| 95 | referrerUrl: String? = null |
| 96 | ) { |
| 97 | track("Product Viewed", mapOf( |
| 98 | "product" to product.toMap(), |
| 99 | "page_url" to pageUrl, |
| 100 | "referrer_url" to referrerUrl |
| 101 | )) |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * User added a product to their cart |
| 106 | */ |
| 107 | fun productAddedToCart( |
| 108 | product: ProductType, |
| 109 | quantity: Int, |
| 110 | cartTotal: Double? = null, |
| 111 | productCount: Int? = null |
| 112 | ) { |
| 113 | track("Product Added to Cart", mapOf( |
| 114 | "product" to product.toMap(), |
| 115 | "quantity" to quantity, |
| 116 | "cart_total" to cartTotal, |
| 117 | "product_count" to productCount |
| 118 | )) |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Customer completed a purchase |
| 123 | */ |
| 124 | fun orderCompleted( |
| 125 | orderId: String, |
| 126 | orderTotal: Double, |
| 127 | customerEmail: String, |
| 128 | products: List<ProductType>, |
| 129 | shippingAddress: AddressType, |
| 130 | billingAddress: AddressType |
| 131 | ) { |
| 132 | track("Order Completed", mapOf( |
| 133 | "order_id" to orderId, |
| 134 | "order_total" to orderTotal, |
| 135 | "customer_email" to customerEmail, |
| 136 | "products" to products.map { it.toMap() }, |
| 137 | "shipping_address" to shippingAddress.toMap(), |
| 138 | "billing_address" to billingAddress.toMap() |
| 139 | )) |
| 140 | } |
| 141 | |
| 142 | // Custom type classes |
| 143 | data class ProductType( |
| 144 | val productId: String, |
| 145 | val productSku: String, |
| 146 | val productName: String, |
| 147 | val productCategory: ProductCategory, |
| 148 | val productPrice: Double, |
| 149 | val productMsrp: Double? = null |
| 150 | ) |
| 151 | |
| 152 | enum class ProductCategory { |
| 153 | FOOTWEAR, |
| 154 | CLOTHING, |
| 155 | ACCESSORIES |
| 156 | } |
| 157 | |
| 158 | data class AddressType( |
| 159 | val address: String, |
| 160 | val city: String, |
| 161 | val state: String, |
| 162 | val zipcode: String |
| 163 | ) |
| 164 | ``` |
| 165 | |
| 166 | ### Using Generated Code |
| 167 | |
| 168 | **Before RudderTyper** (error-prone): |
| 169 | |
| 170 | ```kotlin |
| 171 | // Typos won't be caught until runtime |
| 172 | analytics.track("Product Viewd", mapOf( // Typo in event name! |
| 173 | "product_id" to "shoes-001", |
| 174 | "proudct_name" to "Running Shoes", // Typo in property! |
| 175 | "price" to "89.99" // Wrong type (string vs number)! |
| 176 | )) |
| 177 | ``` |
| 178 | |
| 179 | **After RudderTyper** (type-safe): |
| 180 | |
| 181 | ```kotlin |
| 182 | // IDE autocomplete, compile-time validation |
| 183 | analytics.productViewed( |
| 184 | product = ProductType( |