---
title: "Togo for Android"
description: "Every method and option of the Android SDK, the Kotlin and Java library for phone and tablet apps."
canonical: "https://www.togohq.ai/docs/reference/sdk-android"
applies_to: "sdk-android 1.x"
updated: "2026-11-26T00:00:00Z"
---

# Togo for Android

Every method and option of the Android SDK, the Kotlin and Java library for phone and tablet apps.

```kotlin
// settings.gradle.kts, beside google() and mavenCentral()
maven("https://maven.togohq.ai")

// your app module's build.gradle.kts
implementation("ai.togohq:sdk-android:1.0.0")
```

Android 5.0 (API 21) or later; its one dependency is the Kotlin standard library, and the release
build needs no ProGuard or R8 rules for it. Every method is a static method on `Togo`, the same from
Kotlin and Java, can be called from any thread, and never waits on the network. Calls run in the
order you made them. No method throws, and every argument may be `null` from Java: a refused call
logs one `[togo] …` line saying why and reaches [`onError`](#onerror). A guide to using it:
[Send events from an Android app](/docs/android).

## `Togo.setup(context, config)`

```kotlin
class MyApp : Application() {
  override fun onCreate() {
    super.onCreate()
    val key = if (BuildConfig.DEBUG) "togo_pkt_…" else "togo_pkl_…"
    Togo.setup(this, TogoConfig.Builder(key).build())
  }
}
```

Call it once, in `Application.onCreate()`. A second call is ignored; a call made before `setup` is
dropped, with one log line. Use the test key in debug builds, so `verify_tracking` sees your
emulator's events.

`setup` sends the launch's `$app_installed` or `$app_updated`. It starts no session, because
`onCreate()` also runs for a broadcast, a job or a push message: an activity coming to the
foreground does, with `$app_opened`. In any process but the app's main one, `setup` logs one line
and every call does nothing.

## Options

Build the configuration with `TogoConfig.Builder(writeKey)`, one setter per option, then `build()`.
`NOT_REQUIRED` is a `TogoConsent` and `DROP` a `TogoOnDenied`.

| Option                   | Default                | What it does                                                                                     |
| ------------------------ | ---------------------- | ------------------------------------------------------------------------------------------------ |
| `writeKey`               | —                      | Required, the builder's argument. `togo_pkt_…` (test) or `togo_pkl_…` (live)                     |
| `endpoint`               | `https://in.togohq.ai` | Where events are sent                                                                            |
| `sessionTimeoutSeconds`  | `1800` (30 min)        | Seconds of inactivity that end a session. `0` or less turns sessions off: no `sessionId` is sent |
| `consent`                | `NOT_REQUIRED`         | The starting consent state. `PENDING` holds events in memory until `setConsent(GRANTED)`         |
| `onDenied`               | `DROP`                 | What happens once consent is denied: held events are dropped                                     |
| `consentBufferMaxEvents` | `100`                  | Events held while consent is `PENDING`; past it, the oldest are dropped and reported             |
| `defaultProperties`      | none                   | Properties on every `track()` event, such as `mapOf("source" to "android_app")`                  |
| `appVersion`             | `versionName`          | Your release number, read as `$app_version`. Set it when `versionName` is not it                 |
| `appBuild`               | `versionCode`          | Your build number, read as `$app_build`. Set it when `versionCode` is not it                     |
| `onError`                | —                      | Called for every event, or part of one, that will not be recorded. See [`onError`](#onerror)     |

A setter given `null` keeps the default; a `null` write key is refused at `setup` as an invalid one.
A session also ends after 24 hours, whatever the timeout. A batch is 50 events or 5 seconds,
whichever comes first, fixed on a device; to send at once, call `Togo.flush()`.

`defaultProperties` is fixed at `setup`. An event's own value for the same key wins, and the
collision is logged once.

## `Togo.track(eventName, properties)`

```kotlin
Togo.track("plan_selected", mapOf("plan_id" to "pro", "seats" to 5))
```

From Java, pass a `Map<String, Object>`, or the name alone. A property value is a `String`, a
number, a `Boolean` or `null`. Any other value — a map, a list, an object — is left out of the event
and reported as `property_value_invalid`, and the rest is sent. The name is stored exactly as you
send it, and is 1 to 255 characters. A name starting with `$` is Togo's: with a live key the event
is dropped and reported; with a test key it is sent, so `verify_tracking` reports it with its fix. A
property name starting with `$` is reserved
([Reserved properties](/docs/reference/reserved-properties)), and a name longer than 255 characters,
or holding a control character or an email address, is one Togo cannot use: with a live key the SDK
drops the property and sends the rest; with a test key it sends it as well, so `verify_tracking`
reports it with its fix.

A string value longer than 1,024 characters is cut to its first 1,024, and past 256 properties the
first 256 in sort order by name are kept. The event is still sent, and both are reported through
[`onError`](#onerror); with a test key the value or the properties are sent whole, so
`verify_tracking` shows what Togo keeps. Never put an email address, a name or text a person typed
in an event property: they belong in `setPersonProperties`.

## `Togo.identify(userId)`

```kotlin
Togo.identify(account.id)
```

Call it at sign-in with your own account id — the same one your website and server use, never an
email address. A different id first does what `reset()` does. An empty or `null` id, or one over
128 characters, is refused as `user_id_invalid`. [Identify people](/docs/guides/identify) explains
how one person is followed across platforms.

## `Togo.setPersonProperties(set, email, name)`

```kotlin
Togo.setPersonProperties(
  email = account.email,
  name = account.name,
  set = mapOf("plan" to "pro"),
)
```

`email` and `name` set the reserved person properties `$email` and `$name`; `set` takes your own
keys, as in [Set person properties](/docs/guides/person-properties). A `null` argument changes
nothing. Set the email and name there, never as an `email` or `name` key in `set`.

For `setOnce`, `unset`, or removing the email or name, pass a `TogoPersonProperties` — the form Java
uses:

```java
Togo.setPersonProperties(
    new TogoPersonProperties.Builder()
        .email(account.email)
        .setOnce(Collections.singletonMap("first_plan", "pro"))
        .build());
```

Its builder has `email()`, `removeEmail()`, `name()`, `removeName()`, `set()`, `setOnce()` and
`unset()`.

## `Togo.reset()`

Call it at logout. The device gets a new anonymous visitor and a new session; the device id stays.

## `Togo.setConsent(consent)` and `Togo.getConsent()`

```kotlin
Togo.setConsent(TogoConsent.GRANTED) // or TogoConsent.DENIED
```

Four states: `NOT_REQUIRED`, `PENDING`, `GRANTED` and `DENIED`. `setConsent` can be called at any
time and as often as you like. `GRANTED` after `PENDING` sends what was held; `DENIED` drops it and
deletes everything the SDK stored on the device. `getConsent()` returns the current state.
[Connect a consent banner](/docs/guides/consent) explains the four states.

## `Togo.getAnonymousId()`, `Togo.getDeviceId()`, `Togo.getSessionId()`

Each returns the current id, or `null` before the first event consent permits; `getSessionId()` is
also `null` while there is no session. They never create an id. Pass `getDeviceId()` to
`verify_tracking` as `filter.deviceId` to check the events your emulator sent.

## `Togo.flush(callback)`

```kotlin
Togo.flush { Log.i("app", "sent") }
```

Sends what is queued now. The `FlushCallback` runs after the attempt, on the SDK's callback thread,
so it may call any `Togo` method. An event that could not be sent stays queued and is retried.

## `onError`

```kotlin
TogoConfig.Builder(key)
  .onError { error -> Sentry.captureMessage(error.message) }
  .build()
```

Pass it to the error tracker your app already uses. It is called once for every event that will not
be recorded, or value dropped or cut from one, and once when the client stops sending — in
production as well as in debug builds. Never for consent `DENIED`. It runs on the SDK's callback
thread, after the call that caused it has returned. It receives a `TogoError`: `code`, `message`
(what the log shows, without `[togo] `), `eventIds`, `eventName` and `property` (the property's name
when the report is about one, never its value). The codes are the
[browser SDK's](/docs/reference/sdk-browser#onerror), as constants on `TogoErrorCode`, plus the ones
below. Treat a code you do not recognise as a lost event.

Four codes mean something specific on a device:

| `code`                   | What was lost                                                                                                  |
| ------------------------ | -------------------------------------------------------------------------------------------------------------- |
| `user_id_invalid`        | Nothing: `identify()` was given an empty id or one over 128 characters, and the user is unchanged              |
| `property_value_invalid` | One property: its value was not a string, number, boolean or `null`. The rest of the event is sent             |
| `write_key_rejected`     | Nothing yet: Togo refused the key, so the SDK stops sending until the app restarts and keeps the queued events |
| `endpoint_invalid`       | Nothing yet: `endpoint` is not a URL, or is cleartext HTTP Android blocks. The SDK stops and keeps the queue   |

## `TogoWrapper`

`ai.togohq.wrapper.TogoWrapper` is for the Solar2D plugin, `plugin.togohq`, which
runs this SDK underneath; an app never calls it. It makes every event name the plugin
(`sdk-solar2d`) instead of `sdk-android`, so a breakdown by SDK counts the plugin a game installed.
Any other name, or a version that is empty, holds a space or is over 32 characters, is ignored with
one log line, and events name `sdk-android`.

## Delivery

Events wait on the device while it is offline and are sent when it reconnects, even after Android
ends the app; each keeps the time it happened and the same event id across attempts. How many wait,
and for how long: [Limits](/docs/reference/limits).
