The first part of analytics lets us know how users interact with our applications and helps us make decisions such as:
- Find out what parts of your app are most popular with users and focus on developing parts
- Understand which parts of your app are less used to redesign or clear these parts
- Find potential guidance questions, get more information, and more.
So, integrating an analytics system into your application can make your application more powerful.
1. Download the Google Analytics Library
First, we need to download from the Google developer site the classes that need to be added to the project.
2. Add the Google Analytics library to our Android project
Unzip the downloaded file, add the jar file to the Libs folder, and import the files in the build path.
3. Update manifest file
If your app does not yet allow the following permissions, add the following:
4. Update Activity Code
All activity must reload the OnStart and OnStop methods to enable or disable the analytics feature. A good practice is to create a basic activity and have all other activity inherit it. Now we need to modify this basic activity.
| 1234567891011 |
@Overrideprotected void onStart() { super.onStart(); EasyTracker.getInstance(this).activityStart(this);}@Overrideprotected void onStop() { super.onStop(); EasyTracker.getInstance(this).activityStop(this);} |
5. Add analytics settings under the Values folder
Create a new file, Analytics.xml. The following parameters are sufficient to configure Google Analytics.
| 123456789101112 |
<?xml version="1.0" encoding="utf-8" ?><resources> <!--Replace placeholder ID with your tracking ID--> <string name="ga_trackingId">UA-XXXX-Y</string> <!--Enable automatic activity tracking--> <bool name="ga_autoActivityTracking">true</bool> <!--Enable automatic exception tracking--> <bool name="ga_reportUncaughtExceptions">true</bool></resources> |
This document provides more setup methods.
6. Create a Google Analytics account
Obviously, the first configuration parameter requires a Tracking ID, which requires you to have a Google Analytics account.
Create a new account and set the type to apply. Then enter a few simple details and you'll get the Tracking ID and add it to the configuration file.
7. Link to Google Analytics account with Google Play developer console
Recently released new features allow us to connect these two accounts to make these two services complementary. We only need to enable the link Google play app in Administraion/setup.
Next, we'll be able to get more information about what our users are using.
Summarize
The configuration described in this article will give us an overview of the amount of traffic (new users and current visits), location, and some other major information about activity.
For more help, the next section describes how to use events in an attempt (view) and access records (for example, in fragment), which will make Google Analytics play a bigger role.
Part II
The previous section describes how to integrate Google Analytics into your Android app. Next I'm going to show you how to maximize the role of Google Analytics by registering the amount of traffic for any view and event .
How to register a view
The initialization configuration only captures access to the activity. But most applications are now split into many fragment, so it makes sense to know which fragment are loaded. The following code is required:
| 123 |
EasyTracker tracker = EasyTracker.getInstance(context);tracker.set(Fields.SCREEN_NAME, name);tracker.send(MapBuilder.createAppView().build()); |
On the second line, use the class name, or a more friendly name for the person viewing the statistics to set the screen name.
How to capture and trigger events
Event functionality is inherited from web page analysis. event, which represents any action that the user makes when using the app, requires up to 4 parameters:
- Category: Depending on the requirements, our applications are differentiated into different categories. I tend to use a separate category for each part of my app.
- action: type of event: Press, search, play, stop ...
- label (optional): the tag element is included in the action. It may represent certain UI components, such as a push button, or other dynamic snapping, such as a search, in which case the tag may be a specific search made by the user.
- value (optional): This parameter is a long that is used to provide a value for the action. For example, when a user plays a media file.
Use the following code to register the event:
| 12345 |
EasyTracker tracker = EasyTracker.getInstance(context);tracker.send(MapBuilder .createEvent(category, action, label, value) .build() ); |
Set parameters in event based on requirements and how to use record information.
Conclusion
Google Analytics is a powerful tool that lets us understand how users use our apps . This information greatly helps us solve the problems users encounter, improve the most commonly used parts, or enable advertising campaigns. Let Google Analytics lead your app to success!
How to integrate Google Analytics for your app