API tracking for Android apps
API Tracking is a part of Apptics' Analytics SDK which allows you to track the success rate and response time for the REST APIs configured in the Apptics web console. Refer to the User Guide to configure APIs in the web console.
- Before you begin, make sure that Apptics is integrated into your project by following the Integration Guide.
Copieddependencies {
// ...
// Apptics BoM, latest version is mentioned in the integration guide.
implementation platform('com.zoho.apptics:apptics-bom:[latest-version]')
// Since BoM version is specified, no need to explicitly specify the dependency version.
implementation 'com.zoho.apptics:apptics-analytics'
}
- If you do not use Apptics BoM, you can directly declare the analytics dependency with its version.
Copieddependencies {
// Have to explicitly mention the version, if you are not using BoM.
// latest version is mentioned in the integration guide.
implementation 'apptics_android_sdk.milestones:analytics:[latest-version]'
}
Note: It is recommend to use Apptics BoM to avoid unnecessary compatibility issues.
- Initialize analytics in application onCreate() method.
CopiedApptics.init(this)
Tracking APIs
You can track APIs only after configuring them in the Apptics web console. You will be provided with an ID for each API that is configured in the console.
For retrofit users
- Add AppticsAnalyticsApiTrackingInterceptor to your Okhttp client builder used to make API calls.
CopiedOkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new AppticsApiTrackingInterceptor())
.build();
- Add TrackApiWith annotation to the API interface method, with the corresponding API ID provided in the web console.
Copiedinterface Service {
@TrackApiWith(API_ID)
@Post(url) or @Get(url)
fun makeApiCall()
}
For users using other networking libraries
- Use startTrackApi method with the API ID and the request method (GET, POST, PUT, etc.) before making network call.
Copiedval trackId = AppticsApiTracker.startTrackApi(API ID, requestMethod)
- startTrackApi will return a tracking id. Use that id along with the API response code (200, 400, etc.) in the endTrackApimethod. Call endTrackApi method once the API has returned the response.
CopiedAppticsApiTracker.endTrackApi(trackId, responseCode)