Android

Add the Tugboat SDK to your native Android app.

Add Tugboat to a native Android app built with Android views. Jetpack Compose content is recorded but masked whole, and can't be tagged yet. You'll need your Android app's SDK key. See SDK overview.

Requirements

  • Android 7.0 (API 24) or later. Screenshots need Android 8.0 (API 26) or later.
  • compileSdk 36
  • OkHttp 3.14.9 or later, if you capture network calls with OkHttp

Install

Add the SDK from Maven Central:

// settings.gradle.kts
dependencyResolutionManagement {
    repositories { mavenCentral() }
}

// app/build.gradle.kts
dependencies {
    implementation("com.gettugboat.sdk:tugboat-android:0.1.2")
    implementation("com.gettugboat.sdk:tugboat-okhttp:0.1.1") // optional, for OkHttp
}

Start the SDK

Start Tugboat once, in your Application.onCreate:

import android.app.Application
import com.tugboat.android.AppInfo
import com.tugboat.android.CollectorConfig
import com.tugboat.android.Tugboat
import com.tugboat.android.TugboatConfig

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Tugboat.start(
            this,
            TugboatConfig(
                collector = CollectorConfig(
                    baseUrl = "https://collector.gettugboat.com",
                    apiKey = BuildConfig.TUGBOAT_SDK_KEY,
                ),
                app = AppInfo(
                    name = "My App",
                    version = BuildConfig.VERSION_NAME,
                    buildNumber = BuildConfig.VERSION_CODE.toString(),
                    appId = BuildConfig.APPLICATION_ID,
                ),
                enabled = true,
            ),
        )
    }
}

Register MyApplication in your AndroidManifest.xml, and to use BuildConfig values as above, turn on buildFeatures { buildConfig = true } and add a buildConfigField for your SDK key. All AppInfo fields and both collector fields are required. If one is blank, the SDK doesn't start and logs which field is missing.

Turn capture on

Capture is off by default. Either:

  • set enabled = true, as above, to record from launch, or
  • leave it off and call Tugboat.activate(activationRequestId = "...") when you want to start recording, and Tugboat.deactivate() to stop.

Name your screens

Activities and AndroidX fragments are tracked automatically. If you use Jetpack Navigation, track your NavController after starting the SDK:

Tugboat.trackNavigation(navController)

To give an important control a stable name, set its tag:

import com.tugboat.android.tugboatTag

checkoutButton.tugboatTag = "checkout"

Without a tag, a view's android:id name is used. Don't put personal data in tags.

Identify users

Tugboat.setUserId("user-123")
Tugboat.setTraits(mapOf("plan" to "pro"))

Pass null to setUserId to clear it, for example when someone signs out.

Capture network calls

With OkHttp: add the interceptor first, as an application interceptor:

import com.tugboat.android.okhttp.TugboatOkHttpInterceptor

val client = OkHttpClient.Builder()
    .addInterceptor(TugboatOkHttpInterceptor { request -> routeFor(request) }) // e.g. "/orders/{id}"
    .addInterceptor(authInterceptor)
    .build()

The route resolver turns each request into the path Tugboat records. Return a pattern such as /orders/{id} so IDs stay out of it, or null to skip the request. Don't use addNetworkInterceptor; nothing is recorded there.

By hand:

val call = Tugboat.beginNetworkCall("POST", "/projects")
call.complete(201)

Send events

import com.tugboat.android.ParameterPolicy

val events = Tugboat.eventHook(
    source = "analytics",
    parameterPolicy = ParameterPolicy.allowList(setOf("method")),
)
events.record("USER_LOGIN", mapOf("method" to "email"))

The parameter policy decides which parameters are sent: allowAll (the default), namesOnly, allowList or transform. Use the narrowest one that works, because allowAll can send search terms, IDs or other user content.

Mark sensitive content

All text, images and video are masked by default, and web views are masked whole. To always mask a view and everything inside it:

import com.tugboat.android.tugboatSensitive

accountNumberView.tugboatSensitive()

From Java, use TugboatViews.tugboatSensitive(view). See Privacy and masking.

Verify your setup

  1. Run your app with capture turned on and use it for a minute.
  2. Check Logcat for the Tugboat tag. Problems such as missing fields are logged there.
  3. Check Tugboat.lifecycleState; it's ACTIVE while recording.
  4. Open Findings › Sessions › All sessions in Tugboat and find your session.

Pause or stop capture

  • Tugboat.deactivate() stops recording and keeps your settings, so you can activate again.
  • Tugboat.stop() ends the session and forgets your settings.
  • Tugboat.clearPendingData() deletes recordings that haven't been sent yet.

Troubleshooting

Nothing is recorded

Check Logcat for Tugboat not started. Make sure every AppInfo field is filled in, the collector address is an absolute https:// URL, and capture is on (enabled = true or a call to activate).

No screenshots on some devices

Screenshots need Android 8.0 (API 26) or later. On older devices, sessions are recorded without screenshots.

Network calls are missing

Add TugboatOkHttpInterceptor first, with addInterceptor, and make sure the route resolver returns a path for the request.

Configuration options

OptionDefaultDescription
enabledfalseStart recording when the SDK starts.
captureFocusChangesfalseRecord when a text field gains focus (never what's typed).
captureSystemInputfalseRecord presses of back and hardware buttons.
durableOutboxfalseKeep unsent recordings on disk and send them later, even after the app restarts.
outboxMaxBytes20 MBDisk limit for unsent recordings.
outboxMaxAgeMs72 hoursUnsent recordings older than this are deleted.

More resources


Did this page help you?