Use the Android SDK in a phone or tablet app written in Kotlin or Java. Android 5.0 (API 21) or later; its one dependency is the Kotlin standard library. For what happens on your server — a payment confirmed, a subscription renewed — also use the server SDK.
Add the library
Add Togo’s Maven repository beside the ones you already use, in settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://maven.togohq.ai")
}
}
Then add the library to your app module’s build.gradle.kts:
dependencies {
implementation("ai.togohq:sdk-android:1.0.0")
}
In Groovy build files, the same two lines are:
maven { url 'https://maven.togohq.ai' }
implementation 'ai.togohq:sdk-android:1.0.0'
Set it up in Application.onCreate(), with the test key in debug builds
Call Togo.setup() once, in your Application class. Use the test key (togo_pkt_…) in debug
builds, so verify_tracking sees the events from your emulator, and the live key
(togo_pkl_…) in release builds:
import ai.togohq.Togo
import ai.togohq.TogoConfig
import android.app.Application
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())
}
}
Register the class in AndroidManifest.xml with android:name=".MyApp" on <application>. If
BuildConfig is not generated, turn on buildConfig under buildFeatures in the module’s
build.gradle.kts. From Java the calls are the same static methods:
String key = BuildConfig.DEBUG ? "togo_pkt_…" : "togo_pkl_…";
Togo.setup(this, new TogoConfig.Builder(key).build());
Every call can be made from any thread and never waits on the network. No call throws: a refused
call logs one [togo] line saying why, and TogoConfig.Builder.onError receives it too. The release
build needs no ProGuard or R8 rules for the SDK.
Track events and name the person
Togo.track("plan_selected", mapOf("plan_id" to "pro", "seats" to 5))
// After sign-in: your own account id, the same one your website and server use.
Togo.identify(account.id)
Togo.setPersonProperties(email = account.email, name = account.name)
// At logout: a new anonymous visitor on this device.
Togo.reset()
In Java, Togo.track() takes a Map<String, Object>, and Togo.setPersonProperties() takes a
TogoPersonProperties made with its Builder. A property value
is a string, a number, a boolean or null; anything else is left out of the event and reported to
onError.
Pass the same id to identify() that your website and server use, so one person is one person
on every platform. Never put an email address or a name in an event property; they belong in
setPersonProperties. Identify people and
Set person properties explain both calls.
What the SDK sends on its own
| Event | When | Properties |
|---|---|---|
$app_installed |
The first launch of a new install | — |
$app_updated |
The first launch after the app’s version or build changed | previous_app_version, previous_app_build |
$app_opened |
The app comes to the foreground: opened by the user, or brought back | from_background |
$session_started |
The first event of a session: after 30 minutes idle, or once a day has passed | — |
A rotation, moving between your activities, or one split-screen window closing is not leaving the app. A process Android starts for a broadcast, a job, a push message or a content provider shows no activity, so it opens nothing and starts no session.
Every event carries the app’s versionName and versionCode, read as $app_version and
$app_build, so any chart can split by release, along with the device’s OS, OS version, model and
manufacturer ($manufacturer). Set appVersion and appBuild on TogoConfig.Builder when those
are not your release numbers.
Events wait on the device while it is offline and are sent when it reconnects, even after Android
kills the app; each keeps the time it happened. Up to 5,000 events, or 8 MiB, wait; past that the
oldest are dropped, and an event still unsent after seven days is dropped, with an error for each in
your logs and in onError.
Installs count from the first release with Togo
The first version of your app that adds the SDK does not count your existing users as new installs.
$app_installed is sent when the app was installed in the last seven days; an older install sends
neither $app_installed nor $app_updated on its first launch with Togo, and its next update sends
$app_updated. An install first opened more than seven days after it was installed is counted the
same way, as an existing user.
A person who clears the app’s data, or withdraws consent and later grants it, is a new device: both delete everything the SDK stored on the phone.
Set it up in the main process
The SDK runs in your app’s main process. In a process you declare with android:process, Togo.setup()
logs one line and every call does nothing, because two processes writing the same files would corrupt
them. Call Togo.setup() and every other Togo method from code that runs in the main process.
Ask for consent where you need it
import ai.togohq.TogoConsent
Togo.setup(this, TogoConfig.Builder(key).consent(TogoConsent.PENDING).build())
// When your consent screen resolves:
Togo.setConsent(TogoConsent.GRANTED) // or TogoConsent.DENIED
Under PENDING the SDK holds up to 100 events in memory and stores and sends nothing. GRANTED
sends them; DENIED drops them and deletes what the SDK stored on the device.
Connect a consent banner explains the four states; whether your app needs
consent is your determination.
Answer Google Play’s Data safety form
Your Data safety answers are your declaration about your whole app; for the data the SDK collects, they are these:
- Device or other IDs (the device id the SDK generates), App interactions (the events you
track and the app lifecycle events), and User IDs if you call
identify(). - Each is collected, not shared, processed for Analytics, and encrypted in transit: the SDK sends over HTTPS.
- No advertising ID. The SDK never reads it, and its manifest declares only the
INTERNETpermission — The Android advertising ID says what to do instead.
Your app’s own answers also cover any personal data you send, such as the email address and name in
setPersonProperties.
Check it works
Run a debug build on an emulator with the test key and confirm the events arrived: Check that events arrive.
Every method and option: Togo for Android reference.