> For the complete documentation index, see [llms.txt](https://docs.keewano.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keewano.com/sdks/custom-events-codegen.md).

# Custom Events Codegen

Describe your custom events once in JSON; generate typed report helpers for every SDK.

The built-in events cover what every product does — launches, clicks, purchases, ad revenue. For the moments specific to *your* product, you declare the events once in a single JSON file and generate typed helpers for whichever SDK you use.

**One tool serves every Keewano SDK.** The language differs; the event set and its hash do not — so one definitions file can generate for several platforms at once.

The tool runs at development time only. Nothing from it ships inside your application.

## Install

```bash
npm install --save-dev @keewano/codegen
```

Node 20 or newer. A Python project has no Node, so it installs the same generator from PyPI instead:

```bash
pip install keewano-codegen
```

Both packages run the same generator, and every command and flag is identical.

## 1. Declare your events

Create `keewano.events.json` with one entry per event:

```json
{
  "events": [
    { "eventName": "PlayerRank", "eventValueType": "uint" },
    { "eventName": "EnemyKilled", "eventValueType": "string" },
    { "eventName": "GameOver", "eventValueType": "none" }
  ]
}
```

{% hint style="danger" %}
**An event's id is 2500 plus its position** — `PlayerRank` is 2500, `EnemyKilled` 2501, `GameOver` 2502. The file does not write the id down; the order *is* the numbering.

So **add new events at the end and never reorder**. An entry that moves starts reporting under a number the backend has never seen it on. `keewano-codegen add` appends for you.
{% endhint %}

`eventName` is PascalCase (up to 128 characters). `eventValueType` is the payload type:

| `eventValueType` | Payload                             |
| ---------------- | ----------------------------------- |
| `none`           | none                                |
| `string`         | UTF-8 string                        |
| `uint`           | unsigned 32-bit integer             |
| `bool`           | boolean                             |
| `timestamp`      | Unix timestamp, seconds             |
| `ushortvec2`     | two unsigned 16-bit integers (x, y) |
| `price_usd_cent` | price in USD cents, unsigned 32-bit |

## 2. Generate for your SDK

Name the directory the generated file goes in:

```bash
npx keewano-codegen --target web    --code src/analytics
npx keewano-codegen --target swift  --code Sources/App
npx keewano-codegen --target kotlin --code app/src/main/kotlin/com/keewano/sdk/generated --asset app/src/main/assets
npx keewano-codegen --target python --code myapp
```

There are seven targets — `react-native`, `expo`, `web`, `node`, `swift`, `kotlin`, `python`. `--code` is required rather than defaulted: the file has to sit in a source set your toolchain compiles, and only you know where that is.

{% hint style="info" %}
**Kotlin emits two artifacts.** The reporters go under `--code` in the contract's fixed package (`com.keewano.sdk.generated`), and the definition set goes under `--asset` as `keewano_custom_events.json`, where the Android SDK reads it at launch with no init code at all. `--asset` is required for this target and refused for every other.
{% endhint %}

## 3. Call the generated helpers

```
reportPlayerRank(42)
reportEnemyKilled("orc")
reportGameOver()
```

Where the helper lives differs by target:

* **Swift and Kotlin** put it on the SDK type, so it reads like a built-in `report*` method.
* **TypeScript targets** emit free functions you import from the generated module. TypeScript also exports `customEventSet` for `Keewano.init`; Swift exposes `KeewanoCustomEvents.set`.
* **Android** needs nothing passed — the SDK reads the emitted asset at launch.
* **The `node` target** takes the per-batch reporter as the first argument — `reportPlayerRank(reporter, 42)` — because the relay emits inside `reportUserBatch`.

***

Full documentation and the complete flag reference: [github.com/Keewano/keewano-codegen](https://github.com/Keewano/keewano-codegen)

Each SDK also documents the workflow from its own side: [React Native / Web / Node.js](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/codegen.md) · [Unity](https://keewano.github.io/Keewano-UnitySDK/CustomEventsPage.html) · [Android](https://github.com/Keewano/keewano-android-sdk/blob/main/docs/custom-events.md) · [iOS](https://github.com/Keewano/keewano-ios-sdk/blob/main/docs/custom-events.md) · [Python](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/custom-events.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keewano.com/sdks/custom-events-codegen.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
