This page describes how to use the AMPLIFY Appcelerator Services Analytics for native Android applications, built with Java and the Android APIs.
Appcelerator Analytics collects real-time data about your application's usage which can then be viewed in the Analytics dashboard. By default, the Analytics dashboard provides information about app installs, number of sessions, and average app session length (organized by app name, platform, and geography). Your app can also utilize custom analytic events and event funnels.
For platform-specific details about how analytics captured, see Analytics Architecture.
For information about viewing analytics data, see Managing Client Applications.
Analytics refers to data about how your application has been used, as well as information about how users interact with your application. Analytics data is transmitted in the form of events.
Events are operational milestones in the application. Some events are generated automatically, such as those that mark an installation, or the beginning and end of a session. Others may be custom events, which have a meaning specific to an application, such as tapping a specific button or opening a certain window.
A feature event represents an action a user could take in an application, such as 'liking an item' or launching a video'. Applications use the Titanium or APSAnalytics API to create custom events.
Event funnels let you define custom, ordered event sequences that let you track a specific user process, such as finding a product and making a purchase.
The Analytics dashboard organizes, analyzes, and presents analytics data captured for your applications. You also use the Analytics dashboard to create and view event funnels.
To integrate the Analytics service with a new or existing Android application:
- Go to the Dashboard and create a new native Android application.
- Download the Services SDK and get your Analytics application key.
- Unpack the Services SDK ZIP file.
- Copy the
libfolder of your Android project.
Modify the project's
AndroidManifest.xmlfile to include the following permissions and to add the APSAnalytics package as a service:
Add the following import statements to the main Activity of the project:
In the main Activity's
onCreate()method, enable the service by calling the APSServiceManager's
enablemethod. Pass the method the application context as the first argument and the APS application key as the second argument.
The Android application can now make additional method calls using the
APSAnalytics class. Before making API calls to the APSAnalytics class, you need to retrieve a shared instance using the
method. Make APSAnalytics API calls using the shared instance.
For the Android platform, you need to set up the application to send user session events.
Advanced initialization options
By default, after the application has been backgrounded for 30000 milliseconds (30 seconds), the Analytics service ends the current user session and starts a new one when the application enters the foreground again. To adjust the timeout, use the APSAnalytics's
Setup user session events
On the Android platform, user session events are not automatically sent, unlike the iOS and Titanium platforms. You need to add three
APSAnalyitcs method calls in the main Activity of your application in order to capture user session data.
- Call the sendAppEnrollEvent() method right after the application calls the
onCreate()method. The enroll event indicates application installs or upgrades.
- Call the
sendAppForegroundEvent()method inside the main Activity's
onResume()method. The foreground event indicates when the application is being used.
- Call the
sendAppBackgroundEvent()method inside the main Activity's
onPause()method. The background event indicates when the application has been dismissed.
Creating custom events
You use the APSAnalytics'
method to generate a feature event that captures a specific application or user activity. A feature event should represent an action, such as launching a video, or 'new item', 'launch video', and so forth. The name you assign to a feature event should incorporate the application state into the event name, rather than long descriptive names. The following naming convention is suggested, where group.event refers to the parent event:
Feature event names should be as generic as possible. For instance, if you want to track when users select a certain menu option, use a name like "user.menu.selection", not "joeuser.menu.selection". The first option is better because it groups all the same types of events into a single metric that's easy to view on Dashboard. The person analyzing the data only has to look at a single number to get an overview of how many users have selected that menu option. The second might be fine for very small user bases, but if you have more than 100 users it means that the person analyzing the data would have to look through 100 different event names to be able to generate any useful data.
For example, to track a user's menu selection you might use the following code, where the 10 digit number uniquely identifies the selection in your code:
You should avoid using long, descriptive event names, as shown below:
In the following example, the application uses a default location provider to get location information from the device. The application sends the location data to the Analytics service.