Android integration

This guide covers the complete Android integration of Amply SDK.

Basic Setup

1

Add Dependency

In your app's build.gradle.kts:

dependencies {
    implementation("tools.amply:sdk-android:0.1.7")
}
2

Initialize SDK

Initialize the SDK in your Application class:

import android.app.Application
import tools.amply.sdk.Amply
import tools.amply.sdk.config.amplyConfig

class MyApplication : Application() {

    lateinit var amply: Amply
        private set

    override fun onCreate() {
        super.onCreate()

        val config = amplyConfig {
            api {
                appId = "your.app.id"
                apiKeyPublic = "your_public_key"
                apiKeySecret = "your_secret_key"
            }
        }

        amply = Amply(config, this)
    }

    companion object {
        fun getAmply(context: Context): Amply {
            return (context.applicationContext as MyApplication).amply
        }
    }
}
3

Register Application Class

In your AndroidManifest.xml:

<application
    android:name=".MyApplication"
    ... >
</application>

Configuration Options

Full Configuration

val config = amplyConfig {
    api {
        appId = "your.app.id"
        apiKeyPublic = "your_public_key"
        apiKeySecret = "your_secret_key"
    }

    // Optional: Default campaign configuration (JSON string)
    defaultConfig = """{"campaigns": []}"""

    // Optional: Override endpoints for development
    network {
        configBaseUrl = "https://config.amply.tools"
        backendBaseUrl = "https://api.amply.tools"
    }
}

Tracking Events

Basic Events

From Activities/Fragments

From Compose

Register Listener

Handle in Activity

System Events

Listen for SDK system events:

Rate & Review

The SDK supports triggering app store reviews via campaigns. On Android:

  • Release builds (Play Store): Uses Google Play In-App Review API

  • Debug builds: Shows a simulated dialog for testing

No additional code is needed - rate review actions are handled automatically when campaigns trigger them.

Retrieving Data

Get Dataset Snapshots

Get Recent Events

Permissions

Advertising ID (Optional)

To collect Google Advertising ID, add to your build.gradle.kts:

The SDK will automatically collect the advertising ID when available.

Best Practices

  • Initialize early — Initialize in Application.onCreate() for accurate session tracking

  • Use a singleton — Keep one SDK instance throughout app lifecycle

  • Track meaningfully — Focus on events that drive insights

  • Test campaigns — Use debug builds to verify campaign behavior

  • Handle deep links — Always provide fallback behavior

Troubleshooting

chevron-rightSDK Not Initializinghashtag
  • Verify API keys are correct

  • Check network connectivity

  • Review logcat for error messages

chevron-rightEvents Not Sendinghashtag
  • Ensure SDK is initialized before tracking

  • Check if app has network permission

  • Verify backend URL is accessible

chevron-rightCampaigns Not Triggeringhashtag
  • Use getDataSetSnapshot() to verify data

  • Check targeting and triggering rules

  • Ensure system events listener is registered

Last updated