Mobile Analytics relies on a client SDK for event tracking. The SDK collects data, such as user behavior and app performance, generates logs, and reports them to the server. The server then parses these logs based on a predefined data format, so you can monitor and analyze key metrics from your client application.
This topic describes how to integrate the MAS component into an Android client. The MAS component supports two integration methods: the native AAR-based approach and the component-based approach. Choose the approach that matches your project setup, then follow the six steps below.
Prerequisites
Before you begin, ensure that you have completed the required onboarding process for your integration method:
If you use the native AAR-based approach, complete Add mPaaS to Your Project before you begin.
If you use the native AAR-based approach, complete Add mPaaS to Project before you begin.
If you use the component-based approach, complete the Onboarding Process before you begin.
If you use the component-based approach, complete the Component-based Onboarding Process before you begin.
Add SDK
Native AAR approach
Use Component Management (AAR) to install the LOGGING component in your project. For more information, see Manage Component Dependencies (Native AAR)AAR Component Management.
Component-based approach
In your Portal and Bundle projects, use Component Management to install the LOGGING component. For more information, see Onboarding ProcessAdd Component Dependencies.
Initialize mPaaS
Native AAR approach
Call MP.init() in your Application class to initialize mPaaS before any component is used.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize mPaaS
MP.init(this);
}
}
For more information, see Initialize mPaaS.
Component-based approach
The mPaaS framework initializes automatically. No action is required.
Add configuration
The following configuration options are available. Upload logs and log diagnosis are required; the remaining options are optional.
Upload logs
Uploading logs requires network access. Add the following permissions to AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Log diagnosis
To use the Log diagnosis feature, add the following permission to AndroidManifest.xml and dynamically request it at runtime on Android 6.0 and later:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Diagnostic logs are saved to the device's SD card and cannot be retrieved without this permission.
Set channel ID (optional)
Set a channel ID to distinguish data from APKs distributed through different channels in the console.
Create a channel.config file in the assets directory and set the channel_id value:
# Specifies the current distribution channel
channel_id=alipay
If you omit the channel.config file, the channel ID defaults to mpaas_default.
Get IMEI/IMSI (optional)
On Android 9 and earlier, the SDK retrieves the device's International Mobile Equipment Identity (IMEI) and International Mobile Subscriber Identity (IMSI) by default when the required permissions are granted. To disable this behavior, add the following to AndroidManifest.xml:
<meta-data
android:name="imei.switch"
android:value="off" />
This configuration requires baseline 10.2.3.6 or later. After adding this configuration, Mobile Analytics, Message Push, and Data Sync will no longer retrieve the device's IMEI and IMSI.
Enable auto-start detection (optional)
On some devices, TianyanLoggingService may restart automatically after you force-stop the app. To prevent this, add the following to AndroidManifest.xml:
<meta-data
android:name="open_service_self_start_detection"
android:value="true" />
This configuration requires baseline 10.2.3.77 or later.
Add logs
After the SDK is integrated, add the following log types to your app:
View local logs
See View Local Logs for instructions on viewing logs stored on the device.
Report logs
To synchronize client logs with the server, follow the instructions in Report Logs.