AppAmbit Analytics Android
Submit Analytics Events
Use this class to send analytics events from your Android application. To get started, make sure you've added the module to your app. For setup instructions, refer to the Getting Started guide.
AppAmbit Analytics gives you insight into user behavior and engagement, helping you improve your application experience. The SDK automatically collects session data and device details such as model and OS version. You can also define custom events to track interactions that matter to you. All collected data is accessible through the AppAmbit portal for analysis.
Session and Device Information
After integrating AppAmbit Analytics and starting the SDK, it will begin tracking user sessions and device information (e.g., OS version, device model) automatically—no extra code required, unless Analytics.enableManualSession() is called.
Manual Management for Session
Info
Manual mode is disabled by default, if you need more control over sessions, events and logs you can do so by following the steps below.
In case you want to handle your session manually you must call enableManualSession, before you start using AppAmbit
Java
import com.appambit.sdk.Analytics;
import com.appambit.sdk.AppAmbit;
@Override
protected void onCreate(Bundle savedInstanceState) {
Analytics.enableManualSession();
AppAmbit.start(getApplicationContext(), "<YOUR-APPKEY>");
...
}
Kotlin
import com.appambit.sdk.Analytics;
import com.appambit.sdk.AppAmbit;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Analytics.enableManualSession();
AppAmbit.start(this, "<YOUR-APPKEY>");
...
}
Warning
If this option is enabled no event, log or crash will be sent or saved locally until a session is started manually using Analytics.startSession();
anywhere in your code where you need it.
Start Session
If you already called enableManualSession, you can now start a session manually, calling StartSession:
Java
Analytics.startSession();
Kotlin
Analytics.startSession()
If the method is called again before ending the session the call will be ignored.
End Session
If you already called EnableManualSession, and you already started a session, you can now end the session session manually, calling EndSession:
Java
Analytics.endSession();
Kotlin
Analytics.endSession()
If the method is called again before ending the session the call will be ignored.
Generate a Test Event
AppAmbit Analytics includes an API to trigger a test event, useful for verifying SDK integration.
Java
Analytics.generateTestEvent();
Kotlin
Analytics.generateTestEvent()
Custom Events
Track custom events to capture meaningful user interactions. Once the SDK is initialized, use the trackEvent()
method to track your events with properties. You can send up to 150 distinct event names. Also, there's a maximum limit of 120 characters per event name and 80 characters per event property name and event property value.
Java
Map<String, String> properties = new HashMap<>();
properties.put("Count", "41");
Analytics.trackEvent("ButtonClicked", properties);
Kotlin
val properties: Map<String, String> = mapOf(
"Count" to "41",
)
Analytics.trackEvent("ButtonClicked", properties)
Properties are optional. The following code is for send a simple event without additional data:
Java
Analytics.trackEvent("Music clicked", null);
Kotlin
Analytics.trackEvent("Music clicked", null)