Integrate mPaaS mobile analytics into your Android app to record and report event logs.
To integrate mobile analytics into your Android client:
1. Integrate the mobile analytics component
Follow the Android integration guide to add the mobile analytics component.
2. Record event logs
The following example records an event log with custom properties.
Sample code
This example records an event with the business ID, event ID, payment time, user ID, and payment method.
import com.mpaas.mas.adapter.api.MPLogger;
import java.util.HashMap;
import java.util.Map;
// Business ID
String bizType = "Pay";
// Event ID
String logId = "PayResults";
// Add properties
Map<String, String> params = new HashMap<>(4);
// Property: Payment time. The key is the property ID. The value is the property value.
params.put("pay_time", String.valueOf(System.currentTimeMillis()));
// Property: User ID
params.put("user_id", "the-userId");
// Property: Payment method
params.put("payment_method", "alipay");
// Log the event
MPLogger.event(logId, bizType, params);
Parameter descriptions
|
Parameter |
Description |
|---|---|
|
bizType |
The business ID (also called business code or business type). Uniquely identifies a business. Set to The |
|
logId |
Uniquely identifies an event. Tutorial scenarios. |
|
params |
Stores event properties in
|
3. Report logs
Local logs are automatically reported when the cache reaches a threshold or the app runs in the background for a set period. To immediately report logs during development and testing, call:
import com.mpaas.mas.adapter.api.MPLogger;
MPLogger.uploadAll();